Intern types for canonical identity#29570
Open
IGI-111 wants to merge 3 commits into
Open
Conversation
IGI-111
force-pushed
the
IGI-111/generics-alt
branch
6 times, most recently
from
July 2, 2026 16:26
8874555 to
08bc3d7
Compare
Introduce a two-tier type model separating canonical identity from source-level type annotations: - `Type` is a `Copy` `u32` handle into a session-scoped `TypeInterner`. Equality, hashing, and ordering are O(1). - `TypeKind` is the enum that was previously called `Type`, carrying the source shape (nested `TypeNode` children, integer variants, composites, and so on). - `TypeNode` is the AST-level wrapper: a `TypeKind`, its `Span`, and a cached `Type` handle. `TypeNode::new(interner, kind, span)` is the sole constructor that populates the handle; `PartialEq` and `Hash` delegate to it. Future generics work needs canonical identity for types so monomorphization can key on `Type` directly, and every pass benefits from O(1) equality replacing recursive structural comparison. Keeping `TypeNode` distinct from `Type` preserves per-occurrence spans that diagnostics rely on, which a pure interner handle would drop.
IGI-111
force-pushed
the
IGI-111/generics-alt
branch
from
July 2, 2026 17:08
08bc3d7 to
23220b0
Compare
IGI-111
force-pushed
the
IGI-111/generics-alt
branch
from
July 20, 2026 08:10
761a206 to
681ee78
Compare
IGI-111
force-pushed
the
IGI-111/generics-alt
branch
from
July 21, 2026 10:02
34e9c95 to
2e6ae40
Compare
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.
Introduce a two-tier type model separating canonical identity from source-level type annotations:
Typeis aCopyu32handle into a session-scopedTypeInterner. Equality, hashing, and ordering are O(1).TypeKindis the enum that was previously calledType, carrying the source shape (nestedTypeNodechildren, integer variants, composites, and so on).TypeNodeis the AST-level wrapper: aTypeKind, itsSpan, and a cachedTypehandle.TypeNode::new(interner, kind, span)is the sole constructor that populates the handle;PartialEqandHashdelegate to it.Future generics work needs canonical identity for types so monomorphization can key on
Typedirectly, and every pass benefits from O(1) equality replacing recursive structural comparison. KeepingTypeNodedistinct fromTypepreserves per-occurrence spans that diagnostics rely on, which a pure interner handle would drop.