Skip to content

Render switch discriminant once per group; drop dead inner scope#253

Open
AaronWebster wants to merge 1 commit into
masterfrom
emboss/render-dedup
Open

Render switch discriminant once per group; drop dead inner scope#253
AaronWebster wants to merge 1 commit into
masterfrom
emboss/render-dedup

Conversation

@AaronWebster
Copy link
Copy Markdown
Collaborator

@AaronWebster AaronWebster commented May 20, 2026

The optimized Ok() switch-block code in _generate_optimized_ok_method_body was rendering each switch group's discriminant twice — once unscoped at grouping time to build the SWITCH key, and again with the active ExpressionScope at emit time. Render it once with the scope and reuse the result. Because ExpressionScope.add dedupes by inner rendered form, the result is stable for equivalent discriminants and still works as a grouping key.

The ok_method_switch_block template's ${inner_scope_definitions} placeholder was unused — the inner ExpressionScope it referenced had nothing added to it. Removed both, which also drops the blank line each switch block was carrying in the goldens.

Pure compile-time cleanup; no behavioral change.

Size impact

Target Metric Master PR Delta
ARM Thumb-2 TU .text 18962 18962 0 (0.0%)
MicroBlaze TU .text 43640 43640 0 (0.0%)
Host x86-64 TU .text 29166 29166 0 (0.0%)

Foundation for #254 / #256 / #257 / #258 / #259 (see those for the wins this enables).

The optimized Ok() switch-block code in _generate_optimized_ok_method_body
was rendering each switch group's discriminant twice: once unscoped at
grouping time to build the SWITCH: key, and again with the active
ExpressionScope at emit time. Render it once with the scope and reuse
the result. The result is stable for equivalent discriminants because
ExpressionScope.add dedupes by inner rendered form, so it still works
as a grouping key.

The ok_method_switch_block template's \${inner_scope_definitions}
placeholder was unused — the inner ExpressionScope it referenced had
nothing added to it. Removed both, which also drops the blank line
each switch block carried in the goldens.

No behavioral change; purely compile-time cleanup. Golden churn
limited to the blank-line removal in four files (one line per existing
switch block).
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.

2 participants