infer: exclude aliasCache scratch bits from TypeDecl hash#2853
Merged
Conversation
PR #2849 added aliasCacheValid / aliasCacheHasAlias bits to the TypeDecl::flags union for the lazy findAlias subtree cache. They are runtime scratch state set on first findAlias call, not part of the type's semantic identity. They were leaking into getLookupHash, getSemanticHash, and getOwnSemanticHash via hashmix(flags) / hb.update(flags). Within a single compile this is deterministic (same input -> same cache lifecycle -> same bit state). Across two semantically equivalent TypeDecls whose findAlias-call lifecycles differ (one cached, one not), the hashes diverge -- risky for type interning and AOT semantic hashing across module boundaries. Add flagsWithoutAliasCache(td) -- save the two bits via const_cast, clear them, read flags, restore. Use it at the 3 hash sites. No ABI change. dastest 9341 pass. AOT test_aot 8685 pass. JIT smoke clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents TypeDecl hash values from including lazy findAlias cache state, keeping lookup and semantic hashes tied to type identity rather than runtime scratch bits.
Changes:
- Adds
flagsWithoutAliasCacheto temporarily excludealiasCacheValidandaliasCacheHasAlias. - Uses the filtered flags in lookup, semantic, and own semantic hash generation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
PR #2849 added
aliasCacheValid/aliasCacheHasAliasbits to theTypeDecl::flagsunion for the lazyfindAliassubtree cache. They are runtime scratch state — set on the firstfindAliascall, retained for later calls — not part of the type's semantic identity. They were leaking intogetLookupHash,getSemanticHash, andgetOwnSemanticHashviahashmix(hash, flags)/hb.update(flags).Within a single compile this is deterministic (same input ⇒ same cache lifecycle ⇒ same bit state). Across two semantically equivalent TypeDecls whose
findAlias-call lifecycles differ (one cached, one not), the hashes diverge — risky for type interning and AOT semantic hashing across module boundaries.This adds
flagsWithoutAliasCache(td)— save the two bits viaconst_cast, clear them, readflags, restore — and uses it at the 3 hash sites instead of rawflags.No ABI change (bits stay in the
flagsunion; the helper only touches them transiently during hash compute).Test plan
daslang.exe dastest/dastest.das -- --test tests/— 9341 passed, 0 faileddaslang.exe -jit tests/jit_tests/array.das+tests/decs/test_bulk_create.das— no verifier errorstest_aot.exe -use-aot dastest/dastest.das -- --use-aot --test tests— 8685 passed, 0 failed.dasfiles changed (lint/format/detect-dupe not applicable)🤖 Generated with Claude Code