Source location tracking and debug infrastructure - #284
Draft
micahscopes wants to merge 9 commits into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per-instruction source locations on
Function, debug tags for inlining, compilation cache API. Inliner propagates source locations when cloning instructions.