Repository navigation
skc: fold constant StringConcat and ArrayUnsafeGet on constant arrays - #1689
Merged
Merged
Conversation
mbouaziz
force-pushed
the
peephole-const-folds
branch
from
November 17, 2026 13:08
3b05188 to
152ca67
Compare
mbouaziz
enabled auto-merge
November 17, 2026 13:44
mbouaziz
force-pushed
the
peephole-const-folds
branch
2 times, most recently
from
November 17, 2026 14:10
3fe6736 to
5fb2492
Compare
A StringConcat whose arguments are all constant strings now folds to a single constant string; previously only 0/1-argument concats folded. This also catches constants produced by other folds, e.g. a folded Float.toString concatenated with a literal. The parts are collected into a vector and the fold bails out as soon as one argument is not a constant string, so non-constant concats are left alone. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-Authored-By: Claude Opus 5.5 (Anthropic, via Mistral Vibe; thinking: high) <noreply@anthropic.com>
ArrayUnsafeGet on a ConstantArray with a constant index now folds to the element constant, so literal arrays with constant indices (e.g. Array[10, 20, 30] read at 0, or tuple elements via tupleIndex) resolve at compile time. The fold only fires when provably in bounds (index >= 0, tupleIndex within the slot, computed slot < values.size()); out-of-bounds or non-constant arrays/indices keep the original instruction (unsafe get is UB out of bounds, so those must not fold). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-Authored-By: Claude Opus 5.5 (Anthropic, via Mistral Vibe; thinking: high) <noreply@anthropic.com>
Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> Co-Authored-By: Claude Opus 5.5 (Anthropic, via Mistral Vibe; thinking: high) <noreply@anthropic.com>
mbouaziz
force-pushed
the
peephole-const-folds
branch
from
November 17, 2026 14:47
5fb2492 to
b21f58f
Compare
mbouaziz
disabled auto-merge
November 17, 2026 14:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two more constant folds in the peephole pass, one commit each. Both are pure
data operations whose result cannot depend on which prelude the compiler was
built with (so they are safe regardless of bootstrap vintage, unlike
Float.toString):skc: fold StringConcat of constant strings— aStringConcatwhosearguments are all constant strings folds to a single constant string;
previously only 0/1-argument concats folded. This also catches constants
produced by other folds (e.g.
(0.1).toString() + "!"). The parts arecollected into a vector and the fold bails out (
return peep) as soon asone argument is not a constant string.
skc: fold ArrayUnsafeGet on constant arrays—ArrayUnsafeGeton aConstantArraywith a constant index folds to the element constant(
values[i * valsPerSlot + tupleIndex]), so literal arrays with constantindices resolve at compile time, including tuple elements (tupleIndex).
The fold only fires when provably in bounds (
i >= 0,tupleIndex < valsPerSlot,slot < values.size()); out-of-bounds ornon-constant arrays/indices keep the original instruction, since unsafe
get is UB out of bounds and must not fold.
skc: bump to 0.4.3.Tests
Runtime/StringConcatConst: literal+literal concat, folded-float concat,empty-string concats, and a concat with a non-constant argument
(
"a" + 123.toString() + "b", not folded, still correct at runtime).Runtime/ArrayUnsafeGetConst: scalar array at first/middle/last in-boundsindices; tuple array exercising tupleIndex 0 and 1; a non-constant index
(
"ab".length() - 1, not folded); a non-constant array (.clone(), notfolded). The out-of-bounds guard itself can't be runtime-tested (unsafe
get is UB there), so it is covered by the bounds checks in code.
Validation
make clean && make stage1 && make test): 1769/1769pass, including both new tests and
Native/CompilerVersionCheck.Notes
trailers); validation performed in-session as described above.