Skip to content

refactor: dedupe and flatten the sprint's checker, emitter, and parser additions - #813

Merged
kacy merged 1 commit into
mainfrom
refactor-sprint-elegance
Aug 19, 2026
Merged

refactor: dedupe and flatten the sprint's checker, emitter, and parser additions#813
kacy merged 1 commit into
mainfrom
refactor-sprint-elegance

Conversation

@kacy

@kacy kacy commented Aug 19, 2026

Copy link
Copy Markdown
Owner

A readability pass over the code #804-#812 added, provably behavior-neutral: the refactored compiler emits byte-identical IR to the pre-refactor compiler across 552 corpus files, including the compiler's own 5.4 MB closure. Net -16 source lines.

checker

  • The E263 duplicate-method block tracked (key, kind) pairs through a comma-joined string probed with substring contains, plus a cross-registry has_method_declaration read that was provably equivalent to a same-map lookup. It is now one Map[String, Bool] keyed "<key>#<kind>" and a named dup_check_applies — and the previously implicit third case (an unresolvable impl target is exempt) is stated in a comment.
  • optional_plain_comparison's two mirrored halves and the tail of argument_widens_to_optional were the same predicate written three times; extracted as optional_accepts_plain.
  • check_generic_enum_variant_construction: removed an unreachable E212 branch (the sole caller's enum_decl_has_variant guard is the gate — now said in a comment) and its now-unused enum_name parameter; replaced an inline copy of argument_expression_index with the helper.
  • New normalized_method_name retires two hand-rolled leading-dot strips.
  • propagate_empty_argument_collection_type: a condition whose both arms reached the same return now calls collection_literal_coerces for its recording effect and says so.
  • Hoisted a repeated generic_enum_construction_base call in the annotated-binding path.

emitter

  • ir_emit_return_value shed the if true: wrapper the extraction in fix: give a match on an rc-payload optional exact ownership #809 left behind (pure dedent).
  • The verbatim-duplicated release-then-retain dance for match bindings (optional subject vs enum payload) is one helper, ir_bind_owned_rc_payload, carrying the full untracked-name rationale that previously lived only on the enum copy.
  • The track-or-poison prepass policy, written out three times in ir_collect_string_bind_names, is one helper, ir_prepass_track_or_poison; the optional-match hook also gained a comment stating it sees only top-level arm patterns (unlike the pat_variant hook, which recurses).
  • The two 200+-character mirrored conditions gating the widened compare collapse to ir_plain_compare_operand_ok.
  • ir_emit_optional_optional_compare / ir_emit_optional_plain_compare shared two verbatim blocks; now ir_emit_inner_value_eq and ir_emit_guarded_eq.
  • The syntactic tuple-literal release gate names its condition (is_tuple_literal) and its comment now says explicitly that the second "tuple" is an AST node kind, not the rc kind spelled the same; the stale "therefore still leaks its box" sentence on ir_owned_arg_kind_releases is corrected to point at the caller that now handles it.
  • ir_emit_match_arm_return drops an unused pub and its trailing flag-set is annotated as belt-and-braces.

parser

  • parse_fn_decl built its child list, then rebuilt it around the where clause with an index walk and a ret_node sentinel ordering dance; it now builds the list once, after the clause. The bound-list grammar is one parse_bound_list shared by the inline and where spellings so they cannot drift, and the merge is a named merge_generic_param_bounds.
  • The merge loop's inverted-reading for g_idx, gi follows the value-then-index convention (gp_idx, gp_i), stops at the first match, and generics is declared mut (it was written through an index while immutable — E216 only covers ident targets, which is itself worth a look someday).

what was tested

  • Byte-identical IR A/B: dumped IR for all tests/cases, all examples, and self-host/ir_driver.pith with the pre- and post-refactor compilers — 552 files, zero differences; the compiler's own closure is byte-identical, so codegen provably did not change.
  • make bootstrap-verify — fixed point holds after make refresh-bootstrap-seed (the seed diff is the recompiled refactored source itself, per the A/B above).
  • make check-invalid-only (53 passed) — E262/E263/E264/E226 rejections all unchanged.
  • make run-regressions-only (370 passed).
  • fmt run on all five files (no drift); lint ok on all five.

@kacy
kacy merged commit fb28e3c into main Aug 19, 2026
2 checks passed
@kacy
kacy deleted the refactor-sprint-elegance branch August 19, 2026 14:43
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