refactor: decompose synth/check into helpers in typeinfer.py#425
Open
alcides wants to merge 1 commit into
Open
refactor: decompose synth/check into helpers in typeinfer.py#425alcides wants to merge 1 commit into
alcides wants to merge 1 commit into
Conversation
Owner
Author
|
@claude can you fix this PR? |
c65e9cb to
ff41796
Compare
Extract the heavy arms of the `synth` `match` into module-level helpers (`_synth_application`, `_synth_let`, `_synth_rec`, `_synth_if`) so the top-level dispatch reads as a table, and factor the `Rec` constraint construction that was duplicated almost verbatim between `synth` and `check` into a single shared `_rec_constraints(ctx, t, self_type, comp_types, body_handler)`. The two `Rec` call sites differ only in the self/companion types they bind (declared vs freshened) and in how the body is handled (synth returns a type, check discards it); both are threaded through `_rec_constraints` so the emitted constraints, context-extension order, fresh-name generation, and existential handling are identical to before. Pure code motion — no behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ff41796 to
7138ed5
Compare
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
Behavior-preserving decomposition of the two large
matchstatements inaeon/typechecking/typeinfer.py.synthdispatch tableThe heavy arms —
Application,Let,Rec,If— each carried 30–60 lines of binder/existential bookkeeping inline. They are extracted into module-level helpers_synth_application,_synth_let,_synth_rec, and_synth_if. The top-levelsynthmatchnow reads as a dispatch table; each helper takes the context plus the destructured term fields and returns exactly what the arm returned.Shared
ReclogicThe
Rechandling was duplicated almost verbatim betweensynthandcheck. It is now factored into one helper:The two call sites differ only in:
synth, a freshened copy incheck), passed asself_type/comp_types;synthreturns the body type;checkdiscards it and returnsNone), passed asbody_handler.The Form B existential wrap of the body type stays at the
synthcall site, since onlysynthpropagates a type outward.Behavior preservation
This is pure code motion. The emitted constraints, the order of context extension, fresh-name generation (
fresh_counter), and existential/binder handling are all identical to before — bothReccall sites produce the same constraints they did when the logic was inline. No public API changed:synth,check,check_type, andcheck_type_errorskeep their signatures.Validation
uv run pytest -q: 1686 passed, 14 skipped, 73 warnings — no failures, no errors.🤖 Generated with Claude Code