Skip to content

refactor: decompose synth/check into helpers in typeinfer.py#425

Open
alcides wants to merge 1 commit into
masterfrom
refactor/decompose-typeinfer-synth
Open

refactor: decompose synth/check into helpers in typeinfer.py#425
alcides wants to merge 1 commit into
masterfrom
refactor/decompose-typeinfer-synth

Conversation

@alcides

@alcides alcides commented Jun 24, 2026

Copy link
Copy Markdown
Owner

What

Behavior-preserving decomposition of the two large match statements in aeon/typechecking/typeinfer.py.

synth dispatch table

The 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-level synth match now reads as a dispatch table; each helper takes the context plus the destructured term fields and returns exactly what the arm returned.

Shared Rec logic

The Rec handling was duplicated almost verbatim between synth and check. It is now factored into one helper:

_rec_constraints(ctx, t, self_type, comp_types, body_handler) -> (Constraint, Type | None)

The two call sites differ only in:

  • the type bound for the recursive occurrence / siblings (declared type in synth, a freshened copy in check), passed as self_type / comp_types;
  • how the body is processed (synth returns the body type; check discards it and returns None), passed as body_handler.

The Form B existential wrap of the body type stays at the synth call site, since only synth propagates 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 — both Rec call sites produce the same constraints they did when the logic was inline. No public API changed: synth, check, check_type, and check_type_errors keep their signatures.

Validation

  • uv run pytest -q: 1686 passed, 14 skipped, 73 warnings — no failures, no errors.
  • Pre-commit (mypy + ruff legacy + ruff format) passes.

🤖 Generated with Claude Code

@alcides

alcides commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

@claude can you fix this PR?

@cursor cursor Bot force-pushed the refactor/decompose-typeinfer-synth branch from c65e9cb to ff41796 Compare June 30, 2026 03:05
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>
@cursor cursor Bot force-pushed the refactor/decompose-typeinfer-synth branch from ff41796 to 7138ed5 Compare July 5, 2026 03:02
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