Repository navigation
feat(core): datatype functions in the factory visible to a procedure - #1502
Open
kondylidou wants to merge 5 commits into
Open
kondylidou wants to merge 5 commits into
kondylidou wants to merge 5 commits into
Conversation
Program.factoryBeforeProcedure folds with Decl.addToRuntimeFactory, so the constructors, testers and destructors of a datatype declared before a procedure are in the factory its contract triple and its entry environments are stated over. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
aqjune-aws
requested changes
Nov 19, 2026
aqjune-aws
approved these changes
Nov 19, 2026
aqjune-aws
enabled auto-merge
November 19, 2026 21:25
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 19, 2026
Main's contract lemmas take a proof that the procedure has no type parameters, by decide by default. The type-checked program does not reduce in the kernel, so the test supplies it by native_decide, as contract_by_run does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
What
Program.factoryBeforeProcedureis the factory a procedure's contract triple is statedover and the one its entry environments must have (
ProcEntryEnv). It held Core'sbuilt-ins and the functions declared before the procedure, but none of the functions
generated for a datatype. A body or a contract that mentions a constructor, a tester or
a destructor therefore did not evaluate at a procedure entry, and a triple over it said
nothing.
This PR makes
factoryBeforeProcedurefold withDecl.addToRuntimeFactory, whichalready adds the functions
Lambda.genBlockFactorygenerates for a datatype block. Theprocedure entries now see the same functions as the runtime factory of the declarations
before them (
runtimeFactoryOf Core.Factory).Changes
Program.factoryBeforeProcedure(Core/Program.lean): the fold usesDecl.addToRuntimeFactoryinstead ofDecl.addFunctionsToFactory.Program.factoryBeforeProcedure_eq_core_of_noFunctions(Core/ProgramProps.lean): itshypothesis now also excludes datatype declarations before the procedure. Its uses
decide the hypothesis on a concrete program and need no change.
Procedure.contractTripleand ofIsCoreEntryAt, which described themissing functions as follow-up work. What remains there is the base factory: procedure
entries are over Core's built-ins, not over
base.Tests
Tests/Logic/HoareDatatypes.lean: the constructors, testers and destructors of adatatype are in the factory of a procedure declared after it, none of them is a Core
built-in, and a procedure declared before the datatype still has Core's own factory.
headOfCons_meets_contractproves thecontractTripleof a procedure that setsr := IntList..hd(Cons(1, Nil()))and ensuresr == 1. It holds because every model ofthe factory agrees with the destructor's concrete evaluator
(
Core.opInterp_of_concreteEval), which needs the destructor in the factory.Tests/CoreEntriesTests.leanpinned the absence of the datatype's constructor in thefactory of a procedure entry. It now pins its presence.
lake build,lake lintandlake testpass.Not covered
tester needs the eliminator's semantics in a model. Not attempted here.
🤖 Generated with Claude Code