resolve List(T) generic-call instantiation #73

Merged
jacksonopp merged 4 commits from us69/list-generic-instantiation into main 2026-09-18 22:18:09 +00:00
Owner

Closes #69.

Comptime-evaluates a generic type-function call (List(Int)-shaped) into a real Ty, rather than leaving TypeExpr::Generic permanently unresolved. A new fn_decl salsa query looks up a callee's declaration by name within a given SourceFile; evaluate_generic_call binds each T: type param to its resolved argument in a fresh scope frame and checks the body under that substitution — reusing check_struct/check_expr rather than adding dedicated container TyKind variants, so List(Int)/List(Bool) fall out as genuinely different, correctly-shaped Struct types for free.

Also landed as prerequisites/along the way:

  • Pointer-type resolution (TypeExpr::Pointer -> new TyKind::Pointer), needed since List's own body (items: *T) uses one.
  • A -> type-declared function's return type is now satisfied by any concrete Ty its body produces, rather than requiring exact equality with the abstract Type marker (check_fn's return-type check) — needed for List itself to type-check as a declaration at all.
  • name_hint now threads through Block/Fn bodies so a function whose body is { struct { ... } } gets its struct correctly named, instead of hitting NamelessStruct.
  • check_array_literal/check_map_literal's bare and typed cases now resolve to real List(T)/Map(K, V) shapes instead of their old placeholder result types.

Split off along the way, not included here:

  • #71 — Array's Comptime(Int) size and general Comptime(_)-value-param support (Map's params are both plain type-kinded, so it needed no Comptime support and already works here).
  • #72 — a builtin/prelude mechanism so List/Array/Map don't need declaring inline in every checked file (every test here declares them inline, since fn_decl only searches the given file).

Test plan

[x] cargo test -p twill-check (215 passing)
[x] cargo clippy --workspace --tests (clean)

Closes #69. Comptime-evaluates a generic type-function call (`List(Int)`-shaped) into a real `Ty`, rather than leaving `TypeExpr::Generic` permanently unresolved. A new `fn_decl` salsa query looks up a callee's declaration by name within a given `SourceFile`; `evaluate_generic_call` binds each `T: type` param to its resolved argument in a fresh scope frame and checks the body under that substitution — reusing `check_struct`/`check_expr` rather than adding dedicated container `TyKind` variants, so `List(Int)`/`List(Bool)` fall out as genuinely different, correctly-shaped `Struct` types for free. Also landed as prerequisites/along the way: - Pointer-type resolution (`TypeExpr::Pointer` -> new `TyKind::Pointer`), needed since `List`'s own body (`items: *T`) uses one. - A `-> type`-declared function's return type is now satisfied by any concrete `Ty` its body produces, rather than requiring exact equality with the abstract `Type` marker (`check_fn`'s return-type check) — needed for `List` itself to type-check as a declaration at all. - `name_hint` now threads through `Block`/`Fn` bodies so a function whose body is `{ struct { ... } }` gets its struct correctly named, instead of hitting `NamelessStruct`. - `check_array_literal`/`check_map_literal`'s bare and typed cases now resolve to real `List(T)`/`Map(K, V)` shapes instead of their old placeholder result types. Split off along the way, not included here: - #71 — `Array`'s `Comptime(Int)` size and general `Comptime(_)`-value-param support (`Map`'s params are both plain `type`-kinded, so it needed no `Comptime` support and already works here). - #72 — a builtin/prelude mechanism so `List`/`Array`/`Map` don't need declaring inline in every checked file (every test here declares them inline, since `fn_decl` only searches the given file). ## Test plan [x] cargo test -p twill-check (215 passing) [x] cargo clippy --workspace --tests (clean)
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jacksonopp/twill!73
No description provided.