A namespaced import's const (`m :: #import "lib.sx"; … m.CAP`) only ever resolved as a runtime value — the const folders in program_index.zig had no namespace-member arm, so a qualified const was rejected as an array dimension / Vector lane / generic value-param and could not seed another const, while the flat-import form worked everywhere. Add a `lookupQualifiedConst` (+ float / float-typed twins) ctx hook: resolve the alias via `namespaceAliasVerdictFrom` to its target module, then fold the member from that module's per-source const cache (`foldQualifiedConstInt` in lower/comptime.zig), pinned to the target source so nested const RHSs fold there. Wire it into evalConstIntExpr / evalConstFloatExpr / isFloatValuedExpr — both the expression-position field_access arm (`[m.CAP]T`) and the type-argument dotted-name arm (`Vector(m.LANES, …)`, generic value-params). Implemented on the source-aware ctxs (Lowering / SourceConstCtx); the namespace-blind ModuleConstCtx / StatelessInner return null, so a qualified-const dim reached only via the stateless type-alias path stays a clean unresolved-dim diagnostic, never a fabricated length. Resolves correctly for array dims, arithmetic, integral-float dims, Vector lanes, generic value-params, inline-for bounds, and struct fields. Regression: examples/modules/0842-modules-qualified-import-const-comptime.sx.
28 lines
1.4 KiB
Plaintext
28 lines
1.4 KiB
Plaintext
// A qualified-import-member const (`m.CAP`) folds as a compile-time constant in
|
|
// every comptime position the bare-import form already supported: array
|
|
// dimensions, const arithmetic, an integral-float dimension, a Vector lane
|
|
// count, and a generic value-param argument.
|
|
//
|
|
// Regression (issue 0192): a namespaced import's const reached the const
|
|
// folders only as a runtime value — `evalConstIntExpr`'s field_access arm had
|
|
// no namespace-member arm, and a qualified ref in type-argument position
|
|
// (`Vector(m.LANES, …)`) arrives as a single dotted name. Both now resolve
|
|
// through the namespace alias to the target module's per-source const.
|
|
#import "modules/std.sx";
|
|
m :: #import "0842-modules-qualified-import-const-comptime/layout.sx";
|
|
|
|
Box :: struct($N: i64) { data: [N]u8; }
|
|
|
|
main :: () -> i64 {
|
|
a : [m.CAP]u8 = ---; // array dimension → 8
|
|
b : [m.CAP * 2 + 1]u8 = ---; // arithmetic over a qualified const → 17
|
|
c : [m.FOURF]u8 = ---; // integral float const dim → 4
|
|
v : Vector(m.LANES, f32) = ---; // Vector lane count → 4 lanes
|
|
bx : Box(m.CAP) = ---; // generic value-param arg → 8
|
|
iter := 0;
|
|
inline for 0..m.CAP (i) { iter += 1; } // inline-for bound → 8
|
|
|
|
print("a={} b={} c={} box={} lanes-iter={}\n", a.len, b.len, c.len, bx.data.len, iter);
|
|
return a.len + b.len + c.len + bx.data.len + iter; // 8+17+4+8+8 = 45
|
|
}
|