Check Array(T, N: Comptime(Int)) and Map(K, V) generic instantiation #71

Closed
opened 2026-09-18 14:35:42 +00:00 by jacksonopp · 0 comments
Owner

Follow-up to #69, split out once #69 was scoped down to just List(T) for its first pass.

#69 resolves a generic container instantiation (TypeExpr::Generic) to a concrete Ty by comptime-evaluating the callee's body under substituted generic-param bindings — but only for List(T), since List's definition (struct { items: *T, len: Int }) only needs type-parameter substitution.

Array/Map need more:

  • Array(T: type, N: Comptime(Int)) and Map(K: type, V: type) (per syntax-notes.md) both carry a Comptime(_)-kinded param (Array's N) or otherwise weren't exercised by #69's List-only pass.
  • Comptime(_) params are compile-time values, not types — nothing in Scope/TyKind today has a slot for a plain value (only Symbol -> Ty), so binding N during evaluation needs a new mechanism, not just another Scope frame entry.
  • Array(Int, 3) and Array(Int, 5) must come out as genuinely different Tys. Evaluating Array's struct-shaped body under #69's substitution scheme won't naturally distinguish them, since nothing in the resulting fields' types mentions N (see #67's array-size discussion) — the comptime value has to be carried into the resulting Ty's identity some other way.
  • Once the value-slot mechanism exists, extend the prelude (crates/twill-check/src/prelude.tw, added by #69) with real Array/Map definitions and wire them through the same comptime-evaluation path List uses.

This is the issue #67 should point to for its 'blocked on generic-instantiation resolution' dependency, not #69 directly.

Follow-up to #69, split out once #69 was scoped down to just `List(T)` for its first pass. #69 resolves a generic container instantiation (`TypeExpr::Generic`) to a concrete `Ty` by comptime-evaluating the callee's body under substituted generic-param bindings — but only for `List(T)`, since `List`'s definition (`struct { items: *T, len: Int }`) only needs type-parameter substitution. `Array`/`Map` need more: - `Array(T: type, N: Comptime(Int))` and `Map(K: type, V: type)` (per `syntax-notes.md`) both carry a `Comptime(_)`-kinded param (`Array`'s `N`) or otherwise weren't exercised by #69's `List`-only pass. - `Comptime(_)` params are compile-time *values*, not types — nothing in `Scope`/`TyKind` today has a slot for a plain value (only `Symbol -> Ty`), so binding `N` during evaluation needs a new mechanism, not just another `Scope` frame entry. - `Array(Int, 3)` and `Array(Int, 5)` must come out as genuinely different `Ty`s. Evaluating `Array`'s struct-shaped body under #69's substitution scheme won't naturally distinguish them, since nothing in the resulting fields' *types* mentions `N` (see #67's array-size discussion) — the comptime value has to be carried into the resulting `Ty`'s identity some other way. - Once the value-slot mechanism exists, extend the prelude (`crates/twill-check/src/prelude.tw`, added by #69) with real `Array`/`Map` definitions and wire them through the same comptime-evaluation path `List` uses. This is the issue #67 should point to for its 'blocked on generic-instantiation resolution' dependency, not #69 directly.
jacksonopp added this to the twill project 2026-09-18 15:39:03 +00:00
jacksonopp removed this from the twill project 2026-10-04 02:28:22 +00:00
Sign in to join this conversation.
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#71
No description provided.