Skip to content

Add structured, interned HIR type foundation#32

Merged
NripeshN merged 1 commit into
mainfrom
hir/structured-type-foundation
Jun 20, 2026
Merged

Add structured, interned HIR type foundation#32
NripeshN merged 1 commit into
mainfrom
hir/structured-type-foundation

Conversation

@NripeshN

Copy link
Copy Markdown
Member

Summary

First step (issue #31) of replacing the string-based HIRType with a structured, interned type system. HIRType currently overloads a single name string (qualifier prefix + base + atomic<> generic + * pointer suffix) plus a ][-joined arraySize, decoded by re-parsing strings at ~300 sites across ~38 files. This PR lays the foundation without changing any behavior.

Changes

  • include/crossgl/HIR/Type.h — structured Type (TypeKind, ScalarClass, TypeQualifier, vector width, matrix shape, pointer depth, array dimensions, and the preserved core spelling).
  • src/HIR/Type.cpp:
    • internType(const HIRType&) — the single canonical decoder of the name/arraySize grammar, reusing the existing TypeSemantics predicates for classification.
    • toLegacyHIRType(const Type&) — exact inverse; preserves the core spelling and array tokens so re-serialization is byte-identical.
  • tests/unit/TypeRoundTripTests.cpp (new crossgl_type_roundtrip_tests ctest) — exhaustive round-trip over all 57 builtin spellings × {none/buffer/uniform/shared} × {0,1,2 pointers} × {none, [], [4], [4][8]}, plus atomic<> and struct names, with structural classification spot-checks.

Safety

No production code consumes Type yet, and toLegacyHIRType(internType(t)) == t for every type, so the existing golden suite cannot move. crossgl_compiler, cglc, and crossgl_unit_tests build and link unchanged; the new round-trip test passes locally.

Next (issue #31)

  1. Reimplement the TypeSemantics predicates on top of Type (same signatures); delete the divergent duplicate predicates.
  2. Migrate HIRType storage to an interned Type handle.
  3. Convert the four backend type mappers + typeToIR to switch on TypeKind.

Part of #31

Introduce a structured Type model (Type/TypeKind/ScalarClass/TypeQualifier) with a
single canonical decoder internType() and its exact inverse toLegacyHIRType().
internType reuses the existing TypeSemantics predicates to classify the overloaded
HIRType name grammar (qualifier prefix, atomic<> generic, pointer suffix, ][ array
dimensions); the exact core spelling and array tokens are preserved so
re-serialization round-trips byte for byte.

No production code consumes Type yet, so behavior is unchanged. A new
crossgl_type_roundtrip_tests executable exhaustively verifies the round trip over
all builtin spellings x qualifiers x pointer depths x array forms (plus atomics and
struct names) and spot-checks structural classification.

First step of the structured-type-system migration (issue #31); later steps move
the TypeSemantics predicates and the backends onto Type.
@NripeshN NripeshN merged commit 30d20af into main Jun 20, 2026
7 checks passed
@NripeshN NripeshN deleted the hir/structured-type-foundation branch June 20, 2026 23:09
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