fix(sequence): fall back to canonical cast when params can't fit target#7630
Closed
changjoon-park wants to merge 1 commit into
Closed
fix(sequence): fall back to canonical cast when params can't fit target#7630changjoon-park wants to merge 1 commit into
changjoon-park wants to merge 1 commit into
Conversation
Enables casting a Sequence to a narrower type when values fit but the stored base/multiplier don't (e.g. negative multiplier to unsigned). Closes vortex-data#5102. Signed-off-by: changjoon-park <[email protected]>
Contributor
|
The fix here should be to have two ptypes not fallback to canonical as the issue describes. |
Author
make sense. the two-ptype approach is a larger redesign than I' d scoped thanks for the review ! |
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.
Summary
Closes #5102.
SequenceArrayrepresents arithmetic sequences as(base, multiplier, len). When cast to a narrower or differently-signed target type, the current implementation tries to cast the storedbaseandmultiplierto the target type directly. This fails when either parameter cannot be represented in the target type even if every produced value is representable.Concrete failing case (matches the test file's
TODO(DK)comment):Fix
Return
Ok(None)fromCastReduce::castwhen castingbaseormultiplierfails. This delegates to the canonical cast path, which decodes the sequence into individual values and casts them one by one — correctly succeeding whenever all produced values fit the target type.This matches the existing behavior for float targets, which already returns
Ok(None)in the same file.CastReduce'sOk(None)contract is for "rule doesn't apply, use another approach" situations.What this PR does not do
The issue suggests a more invasive fix: separate
PTypes for calculation vs. return value. That would preserve Sequence's compact representation through the cast and avoid the canonical decode. This PR takes the narrower approach of using the existing canonical fallback to make the operation correct; a parameter-type redesign would be a separate PR with its own design discussion.Testing
#[case::negative_step(...)]and confirmedtest_cast_sequence_conformance::case_3_negative_stepfailed withCannot cast -10i32 to u8.cargo test -p vortex-sequence— 57/57 pass.cargo test -p vortex --lib— 5/5 pass.cargo +nightly fmt --all -- --check— clean.cargo clippy -p vortex-sequence --all-targets --all-features— no warnings.No public API changes other than extending the set of casts that succeed.