You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Comptime-fold all-literal ++ chains in runtime code #556
A ++ chain whose parts are all string literals (e.g. the UAT probe builders in build/release_uat.w, #552) is still assembled at runtime via with_str_concat_n, even though the result is a compile-time constant.
ComptimeEval.w:4706 already knows how to fold OP_CONCAT over CV_STR values — it just isn't applied to constant-foldable expressions in ordinary runtime code paths.
Proposed fix
During lowering (e.g. in lower_str_concat_chain, src/MirLower.w:2557), when every collected part is a string literal, emit a single folded literal instead of an RK_STR_CONCAT_N. Zero runtime cost, smaller MIR, and functions like ruat_zlib_program() become a single constant return.
Determinism note: folding must be a pure function of the literal parts (it is), so fixpoint is unaffected.
Mission relevance
"If With can infer it... the programmer should not have to spell it out" — a constant the compiler can compute should never be assembled at runtime.
Fixed in 7d9bd22. ++ chains whose parts are all plain string literals now fold at lowering into a single CK_STR constant (try_fold_literal_str_concat, src/MirLower.w). Raw payload concatenation is exact since escape sequences never span literal boundaries; mixed raw-marked/unmarked chains keep the runtime path. Verified at machine-code level: a literal-chain program's main contains no with_str_concat calls (the only remaining ones are in the runtime's panic_render). Behavior test: test/behavior/behav_str_literal_concat_fold.w.
Implementing this exposed and was blocked by #557 (string constants >4095 bytes silently corrupted at LLVM emission) — fixed first in 1a42dbf.
Activity
Fold all-literal ++ chains into single constants
ehartford commentedon Jun 12, 2026
Fixed in 7d9bd22.
++chains whose parts are all plain string literals now fold at lowering into a single CK_STR constant (try_fold_literal_str_concat, src/MirLower.w). Raw payload concatenation is exact since escape sequences never span literal boundaries; mixed raw-marked/unmarked chains keep the runtime path. Verified at machine-code level: a literal-chain program's main contains nowith_str_concatcalls (the only remaining ones are in the runtime's panic_render). Behavior test:test/behavior/behav_str_literal_concat_fold.w.Implementing this exposed and was blocked by #557 (string constants >4095 bytes silently corrupted at LLVM emission) — fixed first in 1a42dbf.