resolve Array/Map generic instantiation with Comptime(_) params #74

Merged
jacksonopp merged 4 commits from us71/generic-res-for-array-map-comptime-value-params into main 2026-09-23 14:15:08 +00:00
Owner

Closes #71.

Summary

  • Add InstantiationArg<'db> { Type(Ty), Value(Literal) } and TyKind::Instantiated { name, args, body }, so a generic call's resolved args (types and comptime values alike) become part of the resulting Ty's identity - Array(Int, 3) and Array(Int, 5) now intern as distinct Tys even though their evaluated struct bodies are identical.
  • evaluate_generic_call now recognizes Comptime(_)-kinded params (peeking the param's declared type shape directly, since it can't be resolved via resolve_type_expr) and binds them against InstantiationArg::Value, reporting a new GenericArgKindMismatch diagnostic when a param/arg kind pair doesn't match.
  • Fixed check_array_literal's [N]T[...] branch, which was passing the size expression's type (Ty::int) into generic-call resolution instead of its actual literal value - the root cause of Array(Int, 3)/Array(Int, 5) previously being indistinguishable.
  • resolve_type_expr's TypeExpr::Generic branch now threads GenericArg::Value through instead of discarding it, so annotation-position generics (let x: Array(Int, 3) = ...) resolve through the same path as literal-position ones.
  • Pulled repeated magic strings ("List", "Array", "Map", "Comptime", "type", "self", primitive type names) into a new constants module.

Test plan

  • cargo check / cargo clippy clean
  • New unit tests: annotation-position Array(Int, 3) resolution, both GenericArgKindMismatch directions, Map resolving via a real declaration
  • User confirmed cargo test -p twill-check passes locally
Closes #71. ## Summary - Add `InstantiationArg<'db> { Type(Ty), Value(Literal) }` and `TyKind::Instantiated { name, args, body }`, so a generic call's resolved args (types and comptime values alike) become part of the resulting `Ty`'s identity - `Array(Int, 3)` and `Array(Int, 5)` now intern as distinct `Ty`s even though their evaluated struct bodies are identical. - `evaluate_generic_call` now recognizes `Comptime(_)`-kinded params (peeking the param's declared type shape directly, since it can't be resolved via `resolve_type_expr`) and binds them against `InstantiationArg::Value`, reporting a new `GenericArgKindMismatch` diagnostic when a param/arg kind pair doesn't match. - Fixed `check_array_literal`'s `[N]T[...]` branch, which was passing the size expression's *type* (`Ty::int`) into generic-call resolution instead of its actual literal *value* - the root cause of `Array(Int, 3)`/`Array(Int, 5)` previously being indistinguishable. - `resolve_type_expr`'s `TypeExpr::Generic` branch now threads `GenericArg::Value` through instead of discarding it, so annotation-position generics (`let x: Array(Int, 3) = ...`) resolve through the same path as literal-position ones. - Pulled repeated magic strings (`"List"`, `"Array"`, `"Map"`, `"Comptime"`, `"type"`, `"self"`, primitive type names) into a new `constants` module. ## Test plan - [x] `cargo check` / `cargo clippy` clean - [x] New unit tests: annotation-position `Array(Int, 3)` resolution, both `GenericArgKindMismatch` directions, `Map` resolving via a real declaration - [x] User confirmed `cargo test -p twill-check` passes locally
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!74
No description provided.