Port full corpus to Lean 4.31 + fix Option-cases default arm#6
Merged
Conversation
The example corpus still used APIs removed/renamed in 4.31, so the four
modules that used them (plus Advanced) failed to build and the full
extraction could not run. Ported every site to its 4.31 spelling:
- List.bind -> List.flatMap (call sites only; user .bind defs kept)
- Array.swap! -> Array.swapIfInBounds
- Array.mkArray -> Array.replicate
- List.get? i -> xs[i]?
- List.enum -> List.zipIdx (tuple order flips (i,v)->(v,i); binders
swapped to preserve semantics)
- String.drop now returns String.Slice -> add .toString (Parsers)
- compare _ _ == .lt -> == Ordering.lt (dotted-ident type no longer
inferable through ==)
- Matrix: def -> abbrev so `m[i]?` can synthesize GetElem? through the
alias
Also add Advanced and Production to the Corpus root so `lake build`
covers the whole corpus, and regenerate extracted/lcnf_corpus.py from the
ported sources (554 transpiled defs, valid Python).
Extracting the full corpus surfaced one more transpiler bug (in
LeanToPython.lean): emitOptionCases handled only the named
Option.none/Option.some arms and dropped a `default` arm, producing an
empty `if:`/`else:` block (IndentationError) for matches Lean compiled
with a default -- the same class of bug as the earlier emitListCases
fix. Now handles default on both branches with a `pass` safety net.
Verified: whole corpus builds; full extraction is valid Python;
Comprehensions/TailCalls/RegressionFixes suites, evaluate_correctness.py
(0 wrong), and the round-trip harness (112/112 + 3807/3807) all pass.
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.
The example corpus still used APIs removed/renamed in 4.31, so several modules failed to build and the full extraction (
Corpus/CorpusTestCombined.lean) could not run. This ports every site to its 4.31 spelling and gets the whole corpus building + extracting cleanly again.Corpus API ports
List.bind->List.flatMap(call sites only; the user-definedOption.bind/Either.bind/… defs are untouched)Array.swap!->Array.swapIfInBoundsArray.mkArray->Array.replicateList.get? i->xs[i]?List.enum->List.zipIdx— the tuple order flips(i,v)->(v,i), so the destructuring binders are swapped to preserve semanticsString.dropnow returnsString.Slice->.toString(Parsers)compare _ _ == .lt->== Ordering.lt(the dotted-ident type is no longer inferable through==)Matrix:def->abbrevsom[i]?can synthesizeGetElem?through the aliasAlso adds
AdvancedandProductionto theCorpusroot solake buildcovers the whole corpus, and regeneratesextracted/lcnf_corpus.pyfrom the ported sources (554 transpiled defs, valid Python).One more transpiler bug
Extracting the full corpus surfaced a bug in
emitOptionCases(LeanToPython.lean): it handled only the namedOption.none/Option.somearms and dropped adefaultarm, producing an emptyif:/else:block (IndentationError) forOptionmatches Lean compiled with a default — the same class of bug as the earlieremitListCasesfix (PR #5). Now handlesdefaulton both branches with apasssafety net.Verification
Whole corpus builds; full extraction is valid Python;
Comprehensions/TailCalls/RegressionFixessuites,evaluate_correctness.py(0 wrong), and the round-trip harness (112/112 + 3807/3807) all pass.