Commit 5bda716
feat(sql): resolve table aliases across L2/L3/L4 safety checks (#41)
* P3: prove TypeCompat (level 3) as a real operand-type-compatibility guarantee
Continues the flagship semantic-proof coverage (InjectionFree level 5,
SchemaBound level 2) with TypeCompat (level 3: "operand types compatible").
Adds `Typedqliser.ABI.TypeCompat`, to the same quality bar:
* a small SQL type universe (`SqlType`) and a typed column environment
(`ColEnv`) with a total `lookupType` resolver, reusing the existing
`Query`/`Pred`/`Value` AST;
* `ValueCompat`/`PredTypeCompat`/`QueryTypeCompat` — the proposition that
every WHERE comparison compares a column against a value of a matching
type (a bound parameter adopts the column's type; a literal is TInt; a
raw splice is TText). There is no constructor for a type clash, so a
mismatched comparison is uninhabited;
* `decQueryTypeCompat` — a sound + complete `Dec`, so a "Proven" TypeCompat
certificate is backed by a constructive witness and a type clash can
never be certified;
* `certifyTypeCompatSound` (a `Proven` verdict provably entails the
property); `typeCompatIsLevelThree : levelNat TypeCompat = 3`;
* positive control (a well-typed query, with the certifier computing to
`Proven`) and negative control (`name : Text` compared to an integer
literal provably cannot be certified).
Verified with idris2 0.7.0: `idris2 --build typedqliser-abi.ipkg` exits 0 with
zero warnings (all 7 modules). Adversarially checked — three deliberately-false
proofs (wrong level ordinal, a TInt literal certified against a TText column,
and a type-compatible witness for the clash query) are all rejected by the
type checker.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
* abi: add Layer-3 NullSafe (level 4) theorem with guard discovery
Adds Typedqliser.ABI.Invariants, a second, deeper, distinct machine-checked
property over the existing Semantics query model (Query/Pred/Value reused
verbatim). Where the Layer-2 flagship (Semantics.InjectionFree, level 5) is a
purely structural property, NullSafe (level 4) is context-sensitive: a projected
nullable column is safe only if the WHERE predicate guards it, with guards
discovered by union under And and intersection under Or (disjunctive weakening).
Includes a sound + complete decision procedure (decQueryNullSafe : Dec ...),
a certifier proven sound (certifyNullSafeSound), the level-ordinal identity
plus a proof it differs from InjectionFree, three positive controls and three
non-vacuity controls (unguarded projection, And/union, Or/intersection). Builds
clean with zero warnings; the deliberately-false adversarial proof is rejected.
No believe_me/postulate/assert_total/%hint; %default total throughout.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
* Add Layer-4 ABI<->FFI seam proof (Typedqliser.ABI.FfiSeam)
Prove the FFI result-code encoding is SOUND: the C integer the Zig FFI
returns faithfully round-trips back to the ABI value, and distinct ABI
outcomes never collide on the wire.
- intToResult / intToStatus: total decoders (if x == n over boolean
Bits32 ==, which reduces on concrete literals).
- resultRoundTrip / statusRoundTrip: lossless encoding, proved by Refl.
- resultToIntInjective / statusToIntInjective: injectivity DERIVED from
the round-trip via a local justInj + cong.
- Positive controls (decodeOk/decodeNullPointer/decodeUnknown/decodeProven)
and machine-checked non-vacuity controls (okNotError, schemaNotNull,
provenNotRefuted) refuting collisions of distinct codes.
Genuine total proof: no believe_me / postulate / assert_total / sorry.
Builds clean with zero warnings; a false seam claim is rejected by --check.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
* abi(capstone): Layer-5 end-to-end ABI soundness certificate
Assemble the existing per-layer proofs into one inhabited record
`ABISound` and a single value `abiContractDischarged` built from the
already-exported witnesses:
- Layer-2 flagship: safeQueryInjectionFree (InjectionFree, level 5)
- Layer-2 companions: boundQuerySchemaBound (SchemaBound, level 2),
goodQueryTypeCompat (TypeCompat, level 3)
- Layer-3 invariant: guardedQueryNullSafe (NullSafe, level 4)
- Layer-4 FFI seam: resultToIntInjective
The capstone proves no new domain theorem; its content is that the
whole chain holds simultaneously — if any prior layer were unsound the
value would not typecheck. Adversarial control: a false certificate
(deriving Ok = Error through the seam) is rejected by the typechecker.
%default total, SPDX MPL-2.0, zero warnings.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
* ci: make CI green — bump rust-ci to standards@8dc2bf0 (toolchain: stable fix); port ABI-FFI gate Python->Bash (Python is estate-banned)
Resolves the standing baseline CI reds (rust-ci toolchain error, governance
Language/anti-pattern, governance workflow-lint) without altering the proven
ABI. The Bash gate reproduces the former Python gate's verdict verbatim
(validated across all -iser repos) and catches the same drift classes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
* ci: adopt canonical Julia ABI-FFI gate (estate standard, matches verisimiser) in place of the interim Bash port
* style: cargo fmt + clippy --fix to satisfy rust-ci (fmt --check + clippy -D warnings)
* style: cargo fmt + clippy --fix under stable 1.96 (CI toolchain) — fmt --check + clippy -D warnings clean
* feat(sql): resolve table aliases in L2/L3/L4 checks
Aliased column references like `u.id` in `FROM users u` were not resolved
to their real table, so the schema-binding (L2), type-compatibility (L3),
and null-safety (L4) checks mishandled them: L2 raised false positives on
valid aliased queries, while L3/L4 silently skipped aliased columns (false
negatives). Build a qualifier->table map from the FROM/JOIN clauses and
resolve qualifiers through it across all three levels, including
alias-qualified projections in the null check.
Strengthens the previously no-op l2_valid_multi_table_join test and adds
L2/L3/L4 alias-resolution tests.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 280dcb5 commit 5bda716
2 files changed
Lines changed: 158 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
106 | 162 | | |
107 | 163 | | |
108 | 164 | | |
| |||
172 | 228 | | |
173 | 229 | | |
174 | 230 | | |
| 231 | + | |
175 | 232 | | |
176 | 233 | | |
177 | 234 | | |
178 | 235 | | |
179 | | - | |
180 | | - | |
| 236 | + | |
| 237 | + | |
181 | 238 | | |
182 | 239 | | |
183 | 240 | | |
| |||
225 | 282 | | |
226 | 283 | | |
227 | 284 | | |
228 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
229 | 291 | | |
230 | 292 | | |
231 | 293 | | |
| |||
240 | 302 | | |
241 | 303 | | |
242 | 304 | | |
243 | | - | |
| 305 | + | |
244 | 306 | | |
245 | 307 | | |
246 | 308 | | |
| |||
323 | 385 | | |
324 | 386 | | |
325 | 387 | | |
| 388 | + | |
326 | 389 | | |
327 | 390 | | |
328 | 391 | | |
| |||
334 | 397 | | |
335 | 398 | | |
336 | 399 | | |
337 | | - | |
338 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
339 | 404 | | |
340 | | - | |
| 405 | + | |
341 | 406 | | |
342 | 407 | | |
343 | 408 | | |
| |||
378 | 443 | | |
379 | 444 | | |
380 | 445 | | |
| 446 | + | |
381 | 447 | | |
382 | 448 | | |
383 | 449 | | |
384 | 450 | | |
385 | 451 | | |
386 | 452 | | |
387 | | - | |
| 453 | + | |
388 | 454 | | |
389 | 455 | | |
390 | 456 | | |
| |||
398 | 464 | | |
399 | 465 | | |
400 | 466 | | |
| 467 | + | |
401 | 468 | | |
402 | 469 | | |
403 | 470 | | |
| |||
428 | 495 | | |
429 | 496 | | |
430 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
431 | 521 | | |
432 | 522 | | |
433 | 523 | | |
| |||
444 | 534 | | |
445 | 535 | | |
446 | 536 | | |
| 537 | + | |
447 | 538 | | |
448 | 539 | | |
449 | 540 | | |
450 | 541 | | |
451 | | - | |
| 542 | + | |
| 543 | + | |
452 | 544 | | |
453 | | - | |
454 | | - | |
| 545 | + | |
| 546 | + | |
455 | 547 | | |
456 | | - | |
| 548 | + | |
457 | 549 | | |
458 | 550 | | |
459 | 551 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
307 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
308 | 359 | | |
309 | 360 | | |
310 | 361 | | |
| |||
0 commit comments