ir: generalize type-alias resolution via TypeTable.aliases borrow

Previously, type aliases (`ShaderHandle :: u32`, `Vec4 ::
Vector(4, f32)`) were resolved at three explicit call sites:
- `resolveTypeWithBindings` fallthrough (lower.zig: was 10481-83)
- Protocol method param resolution (was 11154-61)
- Protocol method return resolution (was 11169-76)

Every other `type_bridge.resolveAstType` caller silently fell into
`resolveTypeName`'s "create empty struct stub" path at the bottom,
materialising the alias name as a fresh `{Name=}` struct instead of
its target type. Symptom: the IR call signature got `{}` parameters
where the user meant `u32` etc.

This pushes the alias check inside `resolveTypeName` itself. A new
`TypeTable.aliases: ?*const std.StringHashMap(TypeId)` borrow is
loaned at `lowerRoot` from the owning Lowering. `resolveTypeName`
consults it before falling through to the stub default. Every
caller of `resolveAstType` (and its recursive helpers — `*Alias`,
`[]Alias`, `?Alias`, etc.) now picks up the same resolution.

The three pre-check sites in lower.zig collapse:
- `resolveTypeWithBindings`: the trailing alias pre-check is gone;
  the comment now points at the new path.
- Protocol method param: the `Self → *void` short-circuit stays;
  the alias arm is gone — the fallthrough handles it.
- Protocol method return: same shape.

Tests:
- `type_bridge.test.zig` gains `resolveAstType: TypeTable.aliases
  resolves named alias` pinning the new behaviour. Demonstrates:
  (1) no alias set → unknown name becomes empty struct stub (the
  silent-fail shape we're fixing); (2) alias set → resolves to the
  alias target; (3) compound forms (`*Alias`) recurse into
  `resolveTypeName` for the inner name and pick up the alias.

224/224 example tests pass; zig build test green.
This commit is contained in:
agra
2026-05-28 15:12:53 +03:00
parent 6d258ad82b
commit 29bd182f3f
4 changed files with 83 additions and 24 deletions

View File

@@ -247,6 +247,14 @@ pub const TypeTable = struct {
alloc: Allocator,
/// Target pointer size in bytes (4 for wasm32, 8 for 64-bit targets).
pointer_size: u8 = 8,
/// Borrowed pointer to Lowering's `type_alias_map`. When set,
/// `resolveTypeName` consults it before falling through to
/// the empty-struct-stub default — so a name like `ShaderHandle`
/// (defined `ShaderHandle :: u32`) resolves to `u32` rather than
/// being interned as a fresh empty struct. Pointer lifetime is
/// the owning Lowering's; consumers must clear it before the
/// Lowering is torn down.
aliases: ?*const std.StringHashMap(TypeId) = null,
pub fn init(alloc: Allocator) TypeTable {
var table = TypeTable{