Skip to content

Port full corpus to Lean 4.31 + fix Option-cases default arm#6

Merged
emeryberger merged 1 commit into
roundtrip-faithfulnessfrom
port-corpus-4.31
Jul 4, 2026
Merged

Port full corpus to Lean 4.31 + fix Option-cases default arm#6
emeryberger merged 1 commit into
roundtrip-faithfulnessfrom
port-corpus-4.31

Conversation

@emeryberger

Copy link
Copy Markdown
Owner

Stacked on #5 (base = roundtrip-faithfulness) — merge that first.

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-defined Option.bind/Either.bind/… defs are untouched)
  • Array.swap! -> Array.swapIfInBounds
  • Array.mkArray -> Array.replicate
  • List.get? i -> xs[i]?
  • List.enum -> List.zipIdx — the tuple order flips (i,v) -> (v,i), so the destructuring binders are swapped to preserve semantics
  • String.drop now returns String.Slice -> .toString (Parsers)
  • compare _ _ == .lt -> == Ordering.lt (the dotted-ident type is no longer inferable through ==)
  • Matrix: def -> abbrev so m[i]? can synthesize GetElem? through the alias

Also adds Advanced and Production to the Corpus root so lake build covers the whole corpus, and regenerates extracted/lcnf_corpus.py from 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 named Option.none/Option.some arms and dropped a default arm, producing an empty if:/else: block (IndentationError) for Option matches Lean compiled with a default — the same class of bug as the earlier emitListCases fix (PR #5). Now handles default on both branches with a pass safety net.

Verification

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.

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.
@emeryberger emeryberger merged commit 42b8496 into roundtrip-faithfulness Jul 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant