feat(t27b): lower for over a range and for x in xs (Closes #6349) - #6350
Merged
Merged
Conversation
for (a..b) |i| and for i in a..b lower to a counted loop with Zig's semantics: usize bounds evaluated once, length b - a checked before the first iteration, capture a usize constant. for x in xs no longer reads the loop variable as a label. Multi-object loops are refused as StmtFor(multi-object). t27b corpus specs --reference: counted 615 -> 623 / 720, checked 338 -> 346, mismatch 0. Closes #6349 Refs #6063 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
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.
Closes #6349
Refs #6063
What
cli/t27b/src/lower.rslowers theforshapes the reference-backed blocker list ranked next (StmtFor+4,StmtFor(range)+3, plusStmtForRange):for (a..b) |i|,for i in a..b,for (i in a..=b),for _ in a..b: Zig's semantics -- both bounds coerced to usize and evaluated once (afirst), the lengthb - acomputed with a checked subtraction before the first iteration (Zig panics with integer overflow whenb < a; checked againstzig test), the capture a usize constant per iteration.continueruns the step.for x in xs: t27c's parser copies the loop variable into the node name, which t27b read as a labelled loop (that was theprovider-error-classifier.t27"labelled loop"). The parser builds no labelled loops; a name equal to the sole capture is now the collection loop, any other name stays refused.StmtFor(multi-object)(for (xs, ys) |x, y|), a comptime-reversed range (range 3..1 runs backwards), a signed bound (type mismatch), a negative literal bound (literal out of range) -- the last three are compile errors undert27c test-report.Test
for_over_a_rangeincli/t27b/tests/source.rs(interpreter + JIT):rangesPASS,nested_rangesPASS,reversed_range_trapsFAIL (integer overflow at the loop line) -- the same verdictst27c test-reportgives the same source.bench_unlowerable_body_names_its_constructnow uses a multi-object loop as its unlowerable construct (its oldfor (0..10)body lowers now and is refused as a type mismatch instead, as Zig refuses@as(u32, usize)).Measure
t27b corpus specs --blockers --reference <t27c> --reference-cache <own cache>, t27c built from origin/master e0e806a, fixed copies of the t27b binary before and after, load average 25-170 during the runs.Reference: pass 720, blocked 509, fail 26, timeout 2 (same in both runs, cached).
Newly passing (all reference-pass, every test run):
provider-error-classifier.t27(18 tests),gen_w379.t27(7),gen_caesar.t27(2),gen_mock.t27(5),gen_neuron.t27(4),gen_rle.t27(5),gen_test_runner.t27(4),trios-doctor/src/main.t27(3).No file anywhere in
specs/is blocked byStmtFor(range)orStmtForRangeany more. What is left of the family:StmtFor(multi-object)in 4 files (2 reference-passing,gen_cross_entropyandgen_linear_regression, both also blocked by other constructs) andStmtFor"more than one iterable or capture" in 3 reference-blocked files.Reference-backed greedy top 5 after:
StmtExpr+4,ExprLiteral(negative literal)+4,ExprUnary(try) statement+3,ExprSwitch+4,type f32+3.docs/reports/t27b_expectations.jsonis untouched.🤖 Generated with Claude Code