feat(t27b): integer shifts with an untyped literal on the left - #6289
Merged
Merged
Conversation
t27b pins an untyped literal shifted by a non-literal amount to the type t27c's Zig backend gives it (the declared integer type of the local, else u32, else u64), as compiler.rs shift_runtime_rhs does. A constant amount out of range is refused by name, never masked; a runtime one traps ShiftRange like Zig's @intcast. A literal-only amount whose folded and pinned readings differ is refused, since t27c's optimizer folds it only in some positions. Encoder rows for LSLV/LSRV/ASRV and the immediates; shift_ differential tests. Corpus: pass 191 -> 223, 0 mismatches. Closes #6288 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 #6288
Refs #6063
What
<</>>. A runtime amount uses LSLV, ASRV or LSRV and trapsShiftRangeoutside 0..bits, the way Zig's@intCastpanics. A constant amount uses the lsl/asr/lsr immediates.>>is ASR on signed types and LSR on unsigned ones.1 << n). It was the first rejection in 36 corpus files.cli/t27b/src/lower.rsnow mirrors compiler.rsshift_runtime_rhs. The literal is pinned to the declared integer type of the local it initializes, else to u32, else to u64.<<does.0xFF << (20 + 8)returning u64 gives 0xFF0000000 in the reference. Pinning blindly would give 0xF0000000.<<=/>>=: the t27c parser rejects them ("Unexpected token in expression: Equals"), so the front-end never produces them.Tests
tests/encoder.rs: 6 new rows checked against clang words. They coverlsl x3, x4, x5,lsr w7, w8, w9,asr x10, x11, x12,lsl w17, w16, w8,lsr x0, x16, #63andlsl w0, w16, #31. The case count is now 157.tests/differential.rs:shift_source_programs_run_in_both_enginescovers a literal pinned toi32/u64/u32,u64for a literal past u32, i8 wrap, signed vs unsigned>>, a module const amount, compoundy = y << n, and folded literal-only amounts.t27c test-report:shift_basicspasses, andshift_amount_too_wide,shift_negative_amountandshift_literal_pinned_to_u32trap (reference: 1 pass, 3 FAIL).shift_refusals_name_the_construct.cargo test -p t27b: all green, nothing ignored.Corpus (
t27b corpus specs)/tmp/t27shared/release/t27c test-reportwith the same test count as t27b:specs/ternary/gft_*files.Top 5 blockers after (
t27b corpus specs --blockers, greedy order, 502 files pass already):🤖 Generated with Claude Code