items is now a []T slice whose .len IS the live element count (cap = allocated
capacity), so a List iterates directly: `for xs.items (e) { ... }`. A
`len :: (self) -> i64 #get => items.len` accessor keeps `xs.len` reads working;
`.len` WRITES become `.items.len`. List stays 24 bytes (`[]T`=16 + cap=8).
- list.sx: append/ensure_capacity/deinit rewritten for the slice backing. deinit
guards the free on `cap > 0` (true ownership) and resets via explicit
ptr=null/len=0 (a `.{}` slice assignment yields a garbage len; `.[]` is the
empty-slice literal but can't be assigned to a generic []T — both worked around).
- Compiler coupling updated: comptime_vm makeStringList/readStringList write/read
items as a {ptr,len} fat pointer at field 0 + cap at field 1; control_flow
listView views an `items: []T` slice (keeps the legacy {[*]T,len} shape too).
- Migrated List `.len` writes to `.items.len` in sched.sx + ui/{render,pipeline,
glyph_cache} + platform/{sdl3,android,uikit}.
- Snapshots: List's type-table layout changed → ~40 .ir + memory/0800 (items now
prints as a slice) regenerated; diagnostics/1183 retargeted to a genuine
many-pointer (xs.items is a slice now). Example memory/0840 locks for-each.
24 lines
923 B
Plaintext
24 lines
923 B
Plaintext
// A many-pointer `[*]T` carries NO length, so it cannot coerce to a slice `[]T`
|
|
// implicitly — doing so would pass a bare 8-byte pointer where a 16-byte
|
|
// `{ptr,len}` fat pointer is expected, silently corrupting the callee's view of
|
|
// the data (garbage length, mis-aligned element reads). The compiler rejects it
|
|
// loudly and tells the user to supply the length via `ptr[0..len]`.
|
|
//
|
|
// Regression (issue 0141): this silent mis-coercion segfaulted the comptime VM
|
|
// and failed LLVM verification at runtime; it now produces a clean diagnostic.
|
|
#import "modules/std.sx";
|
|
|
|
sum :: (s: []i64) -> i64 {
|
|
total := 0;
|
|
for s (x) { total += x; }
|
|
return total;
|
|
}
|
|
|
|
main :: () -> i32 {
|
|
a : [4]i64 = .[10, 20, 30, 40];
|
|
mp : [*]i64 = xx @a[0]; // a genuine many-pointer (carries no length)
|
|
r := sum(mp); // [*]i64 → []i64 — rejected; needs mp[0..len]
|
|
print("{}\n", r);
|
|
return 0;
|
|
}
|