Skip to content

Pretty-printer: emit body for opaque define (Refs #931) - #956

Merged
jsiek merged 1 commit into
mainfrom
claude/silly-yalow-343b7f
Jun 12, 2026
Merged

Pretty-printer: emit body for opaque define (Refs #931)#956
jsiek merged 1 commit into
mainfrom
claude/silly-yalow-343b7f

Conversation

@jsiek

@jsiek jsiek commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Define.pretty_print short-circuited to self.str_header() whenever self.visibility == 'opaque', emitting only the head (opaque define name : type) and dropping the required = body. The parser requires every define to be followed by = and a body, so the freshly-pretty-printed source for opaque define id_one_two : fn OneTwo -> OneTwo = fun b { b } reparsed with a ParseError: expected "=" after name in "define" on the next top-level token.
  • The opaque-elides-body branch was a leftover from when pretty_print was also used by .thm printing to hide opaque bodies. #935 already removed the same branch from Union / RecFun / GenRecFun (Import semantics are unaffected because opacity is enforced by the checker, not by the surface form). Define was missed in that pass — fixed now.
  • Define.str_header() was only used by the dropped opaque branch, and the now-trivial pretty_print (return str(self)) just shadowed the base Statement.pretty_print, so both are deleted.
  • PARSER_ROUND_TRIP_FILES gains test/should-validate/ImportTests.pf, the existing fixture that exercises the opaque define name : T = fun ... shape (alongside private union, private recursive, and a downstream expand id_one_two proof). After this patch all four RD/LALR × RD/LALR round-trip combinations pass for that file.

Refs #931. Five of the original 8 bug categories plus the recent follow-ups already landed; this is one of the remaining parse-fail items called out in the most recent triage comment.

Test plan

  • python3.13 test-deduce.py --equiv (parser equivalence + round-trip sweep, including the new ImportTests.pf entry)
  • python3.13 test-deduce.py --passable (every test/should-validate/*.pf still checks under both parsers)
  • make static (ruff + mypy)
  • CI green

Claude session — fallback UUID: 41852f93-8a03-47e4-9c79-35651aa28d9a

🤖 Generated with Claude Code

`Define.pretty_print` short-circuited to `self.str_header()` whenever
`self.visibility == 'opaque'`, emitting just `opaque define name : type`
without the required `= body`. The parser requires `=` and a body
after every `define`, so the freshly-pretty-printed source for
`opaque define id_one_two : fn OneTwo -> OneTwo = fun b { b }` became
the partial `opaque define id_one_two : (fn OneTwo -> OneTwo)` and the
next top-level `theorem` token failed with
`ParseError: expected "=" after name in "define"`.

That `opaque ⇒ header-only` branch was a leftover from when
`pretty_print` was also used by `.thm` printing to elide opaque bodies.
`GenRecFun`, with the explicit note that `.thm` files now include the
body for opaque declarations and `Import` semantics are unaffected
because opacity is enforced by the checker, not the surface form.
`Define` was simply missed in that pass.

`Define.str_header()` was only used by the dropped opaque branch, and
the now-trivial `pretty_print` (`return str(self)`) just shadowed the
base `Statement.pretty_print`, so both are deleted.

`PARSER_ROUND_TRIP_FILES` gains `ImportTests.pf`, which exercises the
`opaque define id_one_two : fn OneTwo -> OneTwo = fun b { b }`
shape that surfaced this bug.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jsiek
jsiek force-pushed the claude/silly-yalow-343b7f branch from e43f3f4 to eecec0f Compare June 12, 2026 21:19
@jsiek
jsiek merged commit bd69c69 into main Jun 12, 2026
9 checks passed
@jsiek
jsiek deleted the claude/silly-yalow-343b7f branch June 12, 2026 21:26
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