lang: array-typed '::' consts as immutable globals (PLAN-CONST-AGG step 1)
K : [4]s64 : .[...] and the untyped A :: .[1, 2, 3] register as is_const globals: one storage, reads GEP it, dead-global elimination drops unused ones, source-aware reads come free via selectGlobalAuthor. - registerConstArrayGlobal (scanDecls pass 2): typed via the annotation (array-ness + dimension/count checked), untyped via element-type unification — all ints s64; ANY float promotes the element type to f64 with ints converting exactly; bool/string homogeneous; a non-numeric mix or non-inferable element asks for an annotation. - constExprValue converts int elements into float destinations exactly (the int+float promotion rule, element-wise). - emitGlobals marks is_const globals LLVMSetGlobalConstant — also flips the comptime-backed #run globals and __sx_default_context to 'constant' (37 pinned IR snapshots regenerated; runtime unchanged). - Element shapes: nested arrays, struct elements, strings, bools. Non-constant elements / dim mismatch / mixed types diagnose loudly. Examples: 0177 (feature matrix incl. @K reads through *[4]s64 — needs the 0117 fix), 1159/1160/1161 (diagnostics), 0837 repointed to values.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
// An ARRAY-typed `::` const (`K : [4]s64 : .[...]`) is not a supported
|
||||
// module-const shape — its own module's read diagnoses cleanly as
|
||||
// unresolved. The own author OWNS the name: the read must never borrow
|
||||
// another module's same-named scalar const (which used to type `K[2]`
|
||||
// against the scalar and panic at LLVM emission).
|
||||
// An ARRAY-typed `::` const is an immutable global owned by its module.
|
||||
// Cross-module: the main file's scalar `K : s64 : 4` and h.sx's array
|
||||
// `K : [4]s64 : .[...]` coexist — each module's bare `K` binds its OWN
|
||||
// author (h's use_k reads ITS array, main's K stays the scalar 4).
|
||||
//
|
||||
// Regression (issue 0115). When array `::` consts land, repoint this
|
||||
// example at the new behavior.
|
||||
// Regression (issue 0115): h.sx's read used to borrow main's scalar K
|
||||
// and panic at LLVM emission; before array consts landed (PLAN-CONST-AGG
|
||||
// step 1) the shape was a clean "unresolved" diagnostic.
|
||||
|
||||
#import "modules/std.sx";
|
||||
h :: #import "0837-modules-array-const-no-cross-borrow/h.sx";
|
||||
@@ -13,5 +13,5 @@ h :: #import "0837-modules-array-const-no-cross-borrow/h.sx";
|
||||
K : s64 : 4;
|
||||
|
||||
main :: () {
|
||||
print("{}\n", h.use_k());
|
||||
print("{} {}\n", K, h.use_k());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user