Repository navigation
fix: replay kernel primitives before the rest of the solution - #98
Open
fushanbobfan wants to merge 1 commit into
Open
fushanbobfan wants to merge 1 commit into
fushanbobfan wants to merge 1 commit into
Conversation
The kernel unfolds a string literal to String.ofList [Char.ofNat ..] without any declaration mentioning those constants, so replay could add a declaration that reduces a literal before Char.ofNat or String.ofList were in the environment. Replay the dependency closure of the primitive targets first, then the remaining constants. Fixes leanprover#93
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 was wrong
The builtin kernel step rejects solutions whose proofs reduce a string literal (#93). The kernel unfolds
"live"toString.ofList [Char.ofNat .., ..], but no declaration mentionsString.ofListorChar.ofNat, andKernel.Environment.replayonly orders declarations by the constants they mention. Depending on the order, a theorem such asstrTag "live" = 1 := rflreaches the kernel before those constants exist, which fails withunknown constant 'Char.ofNat'or a declaration type mismatch.What this changes
runBuiltinKernelnow computes the dependency closure of the primitive targets inside the solution's constant map (dependencyClosureinComparator/Util.lean, built onrunForUsedConsts, so mutual blocks, constructors and recursors stay together) and replays that part first, then the remaining constants. The set of constants sent to the kernel is unchanged; only the order differs. The primitives are still compared against the challenge as before.Two test projects from the issue's reproductions are added:
string_literal_match(matchon a string literal, proved byrfl) andstring_literal_decide(("live" = "dead") = Falsebydecide).How it was tested
In a Linux container (Lean v4.35.0-rc3, lean4export from the manifest,
scripts/fake-landrun.shin place of landrun, since I could not run landrun there):unknown constant 'Char.ofNat';declaration type mismatch, 'strTag_live'), as does the issue's ownRepro.StrC/Repro.StrSlayout.lean --run runtests.leanpasses all 22 tests, includingchar_ofnat_issueandprimitive_issue.nanoda was not built in that container, so the nanoda leg was not exercised by a real
nanoda_bin.