inferred leading comptime params

This commit is contained in:
2026-07-12 17:02:12 +02:00
parent 0706188b98
commit 2dea7711f2
11 changed files with 769 additions and 84 deletions
+33 -2
View File
@@ -754,10 +754,41 @@
zero-count, zero-sized-type, and alignment handling
- `std/arraylist.ArrayList(T)` exposes `items`, `capacity`, and `allocator`, with fallible
reserve/append, roughly 1.5x growth from 8, clear-without-free, and reusable deinit
- deferred: recursive factories, reflection, inferred type arguments, type-producing
- deferred: recursive factories, reflection, type-producing
unions/enums, pop/insert/remove/shrink/clone container operations
31. threading generic/polymorphic type information everywhere (init, deinit, etc.) might be annoying and verbose. consider whether generic structs could fit nicely to avoid this.
31. generic container ergonomics (spike completed; no language change)
- type factories already provide the important half of generic structs: `ArrayList(T)` is a
cached, concrete nominal type whose layout contains `T`; no type information is carried at
runtime
- the verbosity comes from free functions repeating explicit comptime type arguments
(`deinit(i32, &values)`, `append(i32, &values, value)`), not from a missing generic data model
- do not add functions inside structs, implicit `Self`, associated lookup, or per-value runtime
type metadata for this; those features would add a second namespace/member model without
improving layout or specialization
- the smallest fitting feature is call-local inference of omitted comptime type arguments:
```
values ArrayList(i32) = arraylist.init(mem.c_allocator)
defer arraylist.deinit(&values)
try arraylist.append(&values, 42)
```
`T` comes from the expected result for `init` and from the concrete receiver argument for the
other calls
- keep functions package-scoped and keep the explicit form valid; this preserves simple name
resolution and gives ambiguous calls an escape hatch
31.5. inferred leading comptime parameters (implemented)
- a native call may omit its complete leading `$T type` / integer comptime prefix when every
value is uniquely recoverable from runtime argument types and/or the immediate expected result
- inference structurally matches direct type parameters, pointers/slices/arrays/optionals/
fallibles/functions, direct array counts, and canonical generated type-factory provenance;
forwarding/non-invertible factories keep the explicit spelling
- concrete evidence is exact; contextual numeric constants are weak evidence and are rebuilt with
the resolved parameter type before ordinary coercion
- calls are all-explicit or all-inferred (no partial prefix omission); unconstrained/conflicting
values diagnose with the explicit call as the escape hatch
- the existing specialization/HIR/LLVM ABI is unchanged; `std/mem` and `std/arraylist` now use the
inferred form where their arguments or result provide enough information
32. disallow arbitrary integer division
- take inspiration from zig