Skip to content

Intern types for canonical identity#29570

Open
IGI-111 wants to merge 3 commits into
masterfrom
IGI-111/generics-alt
Open

Intern types for canonical identity#29570
IGI-111 wants to merge 3 commits into
masterfrom
IGI-111/generics-alt

Conversation

@IGI-111

@IGI-111 IGI-111 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

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
IGI-111 requested a review from mohammadfawaz July 2, 2026 15:54
@IGI-111 IGI-111 self-assigned this Jul 2, 2026
@IGI-111
IGI-111 force-pushed the IGI-111/generics-alt branch 6 times, most recently from 8874555 to 08bc3d7 Compare July 2, 2026 16:26
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
IGI-111 force-pushed the IGI-111/generics-alt branch from 08bc3d7 to 23220b0 Compare July 2, 2026 17:08
@IGI-111
IGI-111 force-pushed the IGI-111/generics-alt branch from 761a206 to 681ee78 Compare July 20, 2026 08:10
@IGI-111
IGI-111 force-pushed the IGI-111/generics-alt branch from 34e9c95 to 2e6ae40 Compare July 21, 2026 10:02
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