fix(0124): large stack arrays lower to in-place access, not first-class values
Two lowering sites materialized a local array as a whole LLVM value;
the legalizer scalarizes each such op into one SelectionDAG node per
element, and at ~64K elements the DAG combiner segfaults
(DAGCombiner::visitMERGE_VALUES → ReplaceAllUsesWith).
- lowerVarDecl: an array-typed `---` initializer emits NO store — the
slot stays uninitialized instead of receiving a whole-array undef
store. The tuple zero-init carve-out stays; non-array `---` keeps
the undef store. The interp is unchanged either way (slots start
.undef).
- lowerIndexExpr: element reads on an array with addressable storage
GEP the storage and load one element — the general-expression
sibling of 0110's lowerFor fix — without value-lowering the object
(a dead whole-array load would still reach the DAG). Storage-less
arrays keep the index_get fallback.
Sibling shape filed as 0125: any_to_string's per-array-type arms still
pass the array by value, so a 64K+ array type + any {} print crashes.
Regression: examples/0055-basic-large-stack-array.sx (sx build
segfaulted pre-fix). 22 .ir snapshots re-pinned: removed undef stores
and ig.tmp spills, in-place gep+load (instruction-shape-only churn,
reviewed).
This commit is contained in:
45
examples/0055-basic-large-stack-array.sx
Normal file
45
examples/0055-basic-large-stack-array.sx
Normal file
@@ -0,0 +1,45 @@
|
||||
// Large (64KB+) stack arrays compile and are accessed in place: `---`
|
||||
// emits no initializer store, and element reads GEP the array's storage
|
||||
// instead of loading the whole array as a value.
|
||||
//
|
||||
// Regression (issue 0124): both whole-aggregate shapes — the undef
|
||||
// store from `---` and `index_get` on the loaded array value —
|
||||
// scalarized into one SelectionDAG node per element and segfaulted
|
||||
// `sx build` at [65536]u8.
|
||||
//
|
||||
// Results print via out/int_to_string: `{}` formatting would pull the
|
||||
// any_to_string dispatcher, whose array arms materialize every interned
|
||||
// array type BY VALUE — the separate issue 0125.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
checksum :: () -> s64 {
|
||||
buf : [65536]u8 = ---;
|
||||
i := 0;
|
||||
while i < 65536 {
|
||||
buf[i] = xx (i % 251);
|
||||
i += 1;
|
||||
}
|
||||
sum := 0;
|
||||
i = 0;
|
||||
while i < 65536 {
|
||||
sum += xx buf[i];
|
||||
i += 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
big :: () -> s64 {
|
||||
buf : [131072]s64 = ---;
|
||||
buf[0] = 11;
|
||||
buf[131071] = 31;
|
||||
return buf[0] + buf[131071];
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
out(int_to_string(checksum()));
|
||||
out("\n");
|
||||
out(int_to_string(big()));
|
||||
out("\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user