Skip to content

bugc: preserve function loc/sourceId through optimizer#223

Merged
gnidan merged 1 commit into
transform-contextfrom
compiler-preserve-fn-loc-optimizer
Jul 2, 2026
Merged

bugc: preserve function loc/sourceId through optimizer#223
gnidan merged 1 commit into
transform-contextfrom
compiler-preserve-fn-loc-optimizer

Conversation

@gnidan

@gnidan gnidan commented Jul 2, 2026

Copy link
Copy Markdown
Member

The optimizer's cloneFunction dropped the optional Ir.Function.loc and sourceId fields, returning only { name, parameters, entry, blocks }. Because the first optimization pass clones the module, every function lost its declaration source info from optimization level 1 upward.

evmgen gates declaration emission on func.loc && func.sourceId, so all invoke/return contexts lost their declaration source ranges at optimized levels.

Evidence (widget path: bytecode.runtimeInstructions)

Before:

L0 invoke 3/3 declared; return 2/2 declared
L1 invoke 0/3 declared; return 0/2 declared
L2 invoke 0/3 declared; return 0/2 declared

After:

L0..L3 invoke 3/3 declared; return 2/2 declared

Fix

Copy loc/sourceId in cloneFunction's return so declarations survive optimization. This restores declaration source ranges on invoke/return (including the tailcall back-edge) at every optimized level — the levels where the docs demo runs.

Changes

  • optimizer/optimizer.tscloneFunction preserves loc/sourceId.
  • evmgen/optimizer-contexts.test.ts — regression test asserting invoke/return contexts still carry declaration at levels 1, 2, 3 (with a level-0 baseline).

Verification

  • yarn build + full bugc suite green (410 passed, 22 pre-existing skips).
  • Drove the widget-path compile of a recursive program at levels 0-3: all now report full declaration coverage.

cloneFunction dropped the optional Ir.Function.loc and sourceId
fields, returning only { name, parameters, entry, blocks }. Since
the first optimization pass clones the module, every function lost
its declaration source info from optimization level 1 upward.

evmgen gates declaration emission on func.loc && func.sourceId, so
all invoke/return contexts lost their declaration source ranges at
optimized levels — measurably 3/3 declared at level 0, 0/3 at
levels 1-3 on the widget's runtimeInstructions path.

Copy loc/sourceId in cloneFunction's return so declarations survive
optimization. Adds a regression test asserting invoke/return
contexts still carry declaration at levels 1, 2, and 3 (with a
level-0 baseline).
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-02 04:20 UTC

@gnidan gnidan merged commit 13a5843 into transform-context Jul 2, 2026
4 checks passed
@gnidan gnidan deleted the compiler-preserve-fn-loc-optimizer branch July 2, 2026 04:16
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