P3: prove TypeCompat (level 3) as a real operand-type-compatibility guarantee#36
Merged
Merged
Conversation
…uarantee
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
2bd28a2 to
8dd9681
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continues deepening the flagship semantic-proof coverage of the TypedQLiser ABI. After
InjectionFree(level 5, #33) andSchemaBound(level 2, #35), this makesTypeCompat(level 3 — "operand types compatible") a genuine, sound + complete decidable property over the existing query AST, to the same quality bar.Builds on #35 (merged) — the diff here is the new
TypeCompatmodule only.Changes
src/interface/abi/Typedqliser/ABI/TypeCompat.idr:SqlType = TInt | TText | TBool) and a typed column environment (ColEnv) with a totallookupTyperesolver, reusing the existingQuery/Pred/ValueAST fromSemantics.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 isTInt; a raw splice isTText). There is no constructor for a type clash, so a mismatched comparison is uninhabited.decQueryTypeCompat : (env : ColEnv) -> (q : Query) -> Dec (QueryTypeCompat env q)— sound + complete, so aProvenTypeCompat certificate is backed by a constructive witness and a type clash can never be certified.certifyTypeCompat+certifyTypeCompatSound(aProvenverdict provably entails the property), andtypeCompatIsLevelThree : levelNat TypeCompat = 3.Proven) and negative control (name : Textcompared to an integer literal provably cannot be certified).src/interface/abi/typedqliser-abi.ipkg.RSR Quality Checklist
Required
just testor equivalent) — ABI package builds clean (see Testing); change is ABI-onlyjust fmtor equivalent)idris2 --buildemits zero warningsunsafeblocks without// SAFETY:comments — none presentbelieve_me,unsafeCoerce,Obj.magic,Admitted,sorry) — proofs are genuine (replace/trans/sym/localjustInjonly).envfiles includedAs Applicable
src/interface/abi/andsrc/interface/ffi/stay consistentTesting
Verified with Idris2 0.7.0:
Adversarial verification — three deliberately-false proofs were checked in a throwaway module (not committed) and the type checker rejected all three (exit 1):
levelNat TypeCompat = 4(it is 3) — rejected.ValueCompat TText (Lit 42) = LitInt(aTIntliteral against aTTextcolumn) — rejected (Mismatch between: TInt and TText).QueryTypeCompat exampleEnv badQuerywitness for the type-clash query — rejected.The generated
build/directory was removed and is not committed.🤖 Generated with Claude Code
https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Generated by Claude Code