Skip to content

feat(core): datatype functions in the factory visible to a procedure - #1502

Open
kondylidou wants to merge 5 commits into
strata-org:mainfrom
kondylidou:feat/factory-datatype-functions
Open

kondylidou wants to merge 5 commits into
strata-org:mainfrom
kondylidou:feat/factory-datatype-functions

Conversation

@kondylidou

@kondylidou kondylidou commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Program.factoryBeforeProcedure is the factory a procedure's contract triple is stated
over and the one its entry environments must have (ProcEntryEnv). It held Core's
built-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 factoryBeforeProcedure fold with Decl.addToRuntimeFactory, which
already adds the functions Lambda.genBlockFactory generates for a datatype block. The
procedure 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 uses
    Decl.addToRuntimeFactory instead of Decl.addFunctionsToFactory.
  • Program.factoryBeforeProcedure_eq_core_of_noFunctions (Core/ProgramProps.lean): its
    hypothesis now also excludes datatype declarations before the procedure. Its uses
    decide the hypothesis on a concrete program and need no change.
  • Docstrings of Procedure.contractTriple and of IsCoreEntryAt, which described the
    missing functions as follow-up work. What remains there is the base factory: procedure
    entries are over Core's built-ins, not over base.

Tests

  • New Tests/Logic/HoareDatatypes.lean: the constructors, testers and destructors of a
    datatype 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_contract proves the contractTriple of a procedure that sets
    r := IntList..hd(Cons(1, Nil())) and ensures r == 1. It holds because every model of
    the factory agrees with the destructor's concrete evaluator
    (Core.opInterp_of_concreteEval), which needs the destructor in the factory.
  • Tests/CoreEntriesTests.lean pinned the absence of the datatype's constructor in the
    factory of a procedure entry. It now pins its presence.

lake build, lake lint and lake test pass.

Not covered

  • Testers have no concrete evaluator (their body is the eliminator), so a contract over a
    tester needs the eliminator's semantics in a model. Not attempted here.
  • The factory of a procedure entry stays over Core's built-ins, as before.

🤖 Generated with Claude Code

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
aqjune-aws enabled auto-merge November 19, 2026 21:25
@aqjune-aws
aqjune-aws added this pull request to the merge queue Nov 19, 2026
@github-merge-queue
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants