Skip to content

Fix hardcoded source ID in bugc debug info#177

Merged
gnidan merged 1 commit into
mainfrom
compiler-fix-source-id
Mar 9, 2026
Merged

Fix hardcoded source ID in bugc debug info#177
gnidan merged 1 commit into
mainfrom
compiler-fix-source-id

Conversation

@gnidan

@gnidan gnidan commented Mar 9, 2026

Copy link
Copy Markdown
Member

Summary

The compiler was hardcoding source ID as "0" in three places when generating ethdebug/format debug info:

  • irgen/generate/module.ts — variable declaration source ranges
  • irgen/generate/process.ts — code context source ranges (was using module name instead of source ID)
  • evmgen/program-builder.ts — contract definition source range

This PR threads sourcePath from the compilation input through the IR generation state (State.Module.sourceId) and into Ir.Module.sourceId, which is then used consistently across all debug info output. When no sourcePath is provided (e.g. in tests), it falls back to "0".

Changes:

  • Add sourceId field to Ir.Module and State.Module
  • IR gen pass accepts sourcePath from sequence state, defaults to "0"
  • process.ts code contexts use sourceId instead of module name
  • program-builder.ts reads sourceId from IR module
  • Update all test module constructions with sourceId field
  • Add 2 new tests verifying default and explicit sourceId behavior

The compiler was hardcoding source ID as "0" in three places
when generating ethdebug/format debug info. Now threads the
sourcePath from compilation input through the IR generation
state and into the final Format.Program output.

- Add sourceId field to Ir.Module and State.Module
- IR gen pass accepts sourcePath, defaults to "0" if absent
- process.ts code contexts use sourceId instead of module name
- program-builder.ts reads sourceId from IR module
- Update all test module constructions with sourceId field
- Add tests verifying sourceId default and sourcePath threading
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-09 20:12 UTC

@gnidan

gnidan commented Mar 9, 2026

Copy link
Copy Markdown
Member Author

Review (debugger agent): Approve.

The fix correctly threads sourcePath through the compiler pipeline:

  1. CLI passes filePath as sourcePath through the pass system
  2. generateModule() accepts optional sourcePath, defaults to "0" for backward compatibility
  3. Ir.Module.sourceId stores the actual source identifier
  4. buildProgram() uses ir.sourceId instead of hardcoded "0" for the debug info source.id
  5. Process.buildContextForNode uses sourceId from current module instead of module.name

The sourceId is also correctly propagated through optimizer cloning (BaseOptimizationStep) and all test fixtures updated with the new required field.

This matters for pointer dereferencing — when programs-react resolves variables, the source.id in Materials.SourceRange needs to match actual source identifiers for correct source mapping. LGTM.

@gnidan gnidan merged commit cd0f686 into main Mar 9, 2026
4 checks passed
@gnidan gnidan deleted the compiler-fix-source-id branch March 9, 2026 20:08
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