Skip to content

Fe trace attribution and EVM PC mapping - #301

Open
cburgdorf wants to merge 3 commits into
fe-lang:mainfrom
cburgdorf:trace-debug-rebase
Open

Fe trace attribution and EVM PC mapping#301
cburgdorf wants to merge 3 commits into
fe-lang:mainfrom
cburgdorf:trace-debug-rebase

Conversation

@cburgdorf

@cburgdorf cburgdorf commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add the minimal Sonatina substrate required by Fe's ethdebug-distill work:

  • carry opaque Fe origin keys through IR optimization,
  • expose deterministic views over optimized IR,
  • stamp post-optimization instruction provenance,
  • and join that provenance to EVM bytecode through byte-exact PC ranges.

This is intentionally scoped to Fe's trace pipeline rather than being a general-purpose debug-info framework.

Design

Each instruction can carry two independent optional attribution channels:

  • Frontend origin: attached by Fe during MIR-to-Sonatina lowering and preserved through optimization.
  • Post-optimization provenance: stamped by Fe after optimization and carried through EVM lowering into the final PC map.

Attribution strings use shared Arc<str> storage. Inlining and machine lowering therefore preserve identity without duplicating long frontend keys per instruction.

Function::propagate_inst_attribution copies both channels when a pass replaces or expands an instruction. This contract is used by the relevant optimizer passes and both inliners.

Trace views

The PR exposes deterministic, panic-free views over:

  • functions,
  • blocks,
  • instructions,
  • CFG edges,
  • and instruction kinds.

It also exposes the optimized module before backend preparation so Fe can emit post-optimization trace facts and stamp instruction provenance.

EVM observability

EVM lowering distinguishes between:

  • exact 1:1 lowering, which carries both attribution channels, and
  • synthesized glue instructions, which may inherit frontend context but must not impersonate a stamped post-optimization instruction.

The object layer emits byte-reconciled PC ranges with either:

  • frontend provenance for mapped ranges, or
  • an explicit unmapped reason.

Synthetic observability units are numbered after all real module functions, avoiding identity collisions.

Attribution correctness

The PR also fixes incorrect attribution in branch canonicalization: replacement compares now inherit attribution from the compare they replace, rather than borrowing it from the enclosing branch.

Missing attribution remains missing. Instructions created without a valid attribution anchor are deliberately left unmapped instead of borrowing nearby provenance.

Known uncovered creation sites remain in parts of aggregate/ABI transformation and GVN/LSR/CFG-edit phi construction.

Verification

Sonatina:

  • cargo test -p sonatina-ir
  • cargo test -p sonatina-codegen
  • all 819 Sonatina codegen unit tests and integration tests pass

Fe, using a temporary local Cargo patch:

  • cargo test -p fe-codegen
  • cargo test -p fe
  • Fe codegen, CLI, trace, ethdebug, E2E, and formatter-roundtrip suites pass

@cburgdorf cburgdorf changed the title Trace debug rebase Fe trace attribution and EVM PC mapping Jul 21, 2026
cburgdorf and others added 3 commits July 21, 2026 16:30
Store frontend origins and post-optimization provenance as shared per-instruction attribution. Preserve the bundle through replacement passes and both inliners, clear it with erased instructions, and leave pass-created instructions unattributed when no valid anchor exists.

Co-authored-by: Micah Scopes <micahscopes@gmail.com>
Provide deterministic function, block, instruction, CFG-edge, and instruction-kind views for Fe trace emission. Let frontend consumers inspect and stamp the optimized module before EVM backend preparation.

Co-authored-by: Micah Scopes <micahscopes@gmail.com>
Carry exact post-optimization provenance through machine lowering into byte-reconciled PC ranges. Keep synthesized glue separate, account explicitly for unmapped bytes, and allocate synthetic function identities after all real module functions.

Co-authored-by: Micah Scopes <micahscopes@gmail.com>
@cburgdorf
cburgdorf force-pushed the trace-debug-rebase branch from f2112ef to 9d9325e Compare July 21, 2026 13:33
@cburgdorf
cburgdorf marked this pull request as ready for review August 11, 2026 08:45
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 9d9325e32d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@micahscopes @sbillig These changes are needed for tracing to work post-optimization. It's based on @micahscopes 's initial work.

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