Define typing relation for commands and prove soundness of typechecker#1335
Draft
joscoh wants to merge 33 commits into
Draft
Define typing relation for commands and prove soundness of typechecker#1335joscoh wants to merge 33 commits into
joscoh wants to merge 33 commits into
Conversation
…eAux All resolveAux proofs except hasType converted to use ind principle
added 5 commits
June 8, 2026 10:28
Unification too permissive: now split into rigid type variables that cannot be unified, and free type variables which can Involves changes to typechecker, spec, and proofs Added test cases for various edge cases
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.
Gives a type specification for commands (
CmdHasType'), generalized over theLExprtyping relation, and instantiates it withLExpr.hasType(CmdHasType) andLExpr.hasTypeA(CmdHasTypeA). Proves that:Cmd.typeChecksucceeds, then the original command was well-typed according toCmdHasType(theoremCmd.typeCheck_sound).Cmd.typeChecksucceeds, then the output command is well-annotated according toCmdHasTypeA(theoremCmd.typeCheck_annotated_sound).Core command typing (new files under
Strata/Languages/Core/)CmdTypeSpec.lean— the inductiveCmdHasType', parameterized over anExprTypingSpectypeclass with two instances:CmdHasType(polymorphicHasType, overLTy) andCmdHasTypeA(annotatedHasTypeA, overLMonoTy).CmdTypeSpecProps.lean— the two top-level soundness theorems,Cmd.typeCheck_soundandCmd.typeCheck_annotated_sound, showingCmd.typeCheckproduces commands satisfying the spec.CmdTypeProps.lean— supporting lemmas aboutpreprocess/inferType/
unifyTypesand context updates that feed the soundness proofs.CmdType.inferType— no longer auto-registers undeclared free variablesvia
addInOldestContext. Expressions ininit/set/assert/assume/coverthat reference variables not already in scope are now rejected by
freeVarCheck.Previously, undeclared variables were silently added, which is not longer needed
with nondeterministic init.
Rigid type variables (fixes #1345)
CmdType.checkAnnotCompat— new checker pass that rejects any unificationresult refining a rigid (skolemized) type variable.
ProcedureType.lean—setupInputEnvnow generates fresh rigid vars fortype parameters and records them in
C.rigidTypeVars; body typecheckingenforces identity on these vars via
checkAnnotCompat.CmdTypeSpec.lean— theinit_det/init_nondetconstructors useRigidAnnotCompat(AnnotCompat restricted to be identity on rigid vars).CmdTypeSpecProps.lean—Cmd.typeCheck_preserves_rigid_invproves theinvariant is preserved;
typeCheck_sounduses it.RigidTypeVarsTests.lean— test cases for polymorphic procedures withrigid type parameters, including expected-failure cases.
Lambda layer
LExprResolveProps.lean(renamed fromLExprResolveAnnotated.lean) adds theoremresolve_eqModuloAnnotations(resolution preservesexpression structure, changing only metadata and annotations).
LExprTypeSpec.lean— adds freshness /TEnvWF/ well-scoped supportinglemmas used by the resolve and command proofs. The
HasTyperelation itselfis unchanged.
LExprTypeEnv.lean— addsTContext.substandTEnvlemmas(substitution lookup,
addInNewestContext, free-variable scoping) used by thecommand proofs.
LExprWF.leanandLTyUnify.lean.Tooling
Strata/Util/Tactics.lean— now contains theelim_err/elim_errstactics fordischarging error branches when unfolding
Except-valued checker code, usedthroughout the soundness proofs.