Skip to content

Source location tracking and debug infrastructure - #284

Draft
micahscopes wants to merge 9 commits into
fe-lang:mainfrom
micahscopes:debug-info
Draft

Source location tracking and debug infrastructure#284
micahscopes wants to merge 9 commits into
fe-lang:mainfrom
micahscopes:debug-info

Conversation

@micahscopes

@micahscopes micahscopes commented May 15, 2026

Copy link
Copy Markdown
Contributor

Per-instruction source locations on Function, debug tags for inlining, compilation cache API. Inliner propagates source locations when cloning instructions.

Add source_locs: SecondaryMap<InstId, SourceLoc> to Function, where
SourceLoc is an opaque u32 assigned by the frontend. Frontends use this
to map instructions back to source positions via external lookup tables.

Source locations survive instruction replacement (same InstId slot) and
are ignored for deleted instructions. The default value (0) means no
source location.
Implement Cranelift-style DebugTags: per-instruction tag sequences that
preserve virtual call stacks through inlining. When the inliner clones
instructions from a callee, it can prepend the callsite's tags to all
inlined instructions via prepend_tags().

Tag types: SourceLoc (source position), InlineCallsite (inlined-from
location), SemanticScope (type/scope reference).
Implement Cranelift-style incremental compilation cache API:
- CacheKey: SHA-256-like hash of function IR content + source locations
- CompilationCache trait: pluggable storage backend (get/insert)
- InMemoryCache: simple HashMap-based implementation for testing
- compute_cache_key: hashes function structure for cache lookup

The cache key includes source locations so debug info changes invalidate
cached compilations, matching Cranelift's behavior.
When the full inliner clones instructions from callee to caller,
copy the callee instruction's source_loc to the new instruction
in the caller. This preserves source attribution through inlining.
Make CacheKey, CompilationCache, InMemoryCache, and compute_cache_key
accessible via sonatina_codegen::object for frontend consumption.
Replace single DefaultHasher stub with 4 independent hashers that fill
all 256 bits of the cache key. Hash block topology, instruction identity,
source locations, and argument count for comprehensive content addressing.
Implement serialize/deserialize on CachedCompilation for persistent
cache storage. Uses simple little-endian binary format without external
dependencies. Includes round-trip test.
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