Skip to content

Fixing panics in test262 when running in debug mode #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Instant {
let rounded = IncrementRounder::<i128>::from_positive_parts(self.as_i128(), increment)?
.round_as_positive(resolved_options.rounding_mode);

Ok(rounded.into())
Ok(rounded as i128)
}

// Utility for converting `Instant` to `i128`.
Expand Down
2 changes: 1 addition & 1 deletion src/components/zoneddatetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ impl ZonedDateTime {
}
TimeZoneRecord::Offset(offset_record) => {
// NOTE: ixdtf parser restricts minute/second to 0..=60
let minutes = i16::from((offset_record.hour * 60) + offset_record.minute);
let minutes = i16::from(offset_record.hour) * 60 + offset_record.minute as i16;
TimeZone::OffsetMinutes(minutes * i16::from(offset_record.sign as i8))
}
// TimeZoneRecord is non_exhaustive, but all current branches are matching.
Expand Down
2 changes: 1 addition & 1 deletion src/options/relative_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl RelativeTo {
}
TimeZoneRecord::Offset(offset_record) => {
// NOTE: ixdtf parser restricts minute/second to 0..=60
let minutes = i16::from((offset_record.hour * 60) + offset_record.minute);
let minutes = i16::from(offset_record.hour) * 60 + offset_record.minute as i16;
TimeZone::OffsetMinutes(minutes * i16::from(offset_record.sign as i8))
}
// TimeZoneRecord is non_exhaustive, but all current branches are matching.
Expand Down
32 changes: 17 additions & 15 deletions src/rounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ pub(crate) trait Roundable:
fn is_exact(dividend: Self, divisor: Self) -> bool;
fn compare_remainder(dividend: Self, divisor: Self) -> Option<Ordering>;
fn is_even_cardinal(dividend: Self, divisor: Self) -> bool;
fn result_floor(dividend: Self, divisor: Self) -> u64;
fn result_ceil(dividend: Self, divisor: Self) -> u64;
fn result_floor(dividend: Self, divisor: Self) -> u128;
fn result_ceil(dividend: Self, divisor: Self) -> u128;
fn quotient_abs(dividend: Self, divisor: Self) -> Self {
// NOTE: Sanity debugs until proper unit tests to vet the below
debug_assert!(<i128 as NumCast>::from((dividend / divisor).abs()) < Some(u64::MAX as i128));
// NOTE (nekevss): quotient_abs exceeds the range of u64, so u128 must be used.
debug_assert!(<u128 as NumCast>::from((dividend / divisor).abs()) < Some(u128::MAX));
(dividend / divisor).abs()
}
}

pub(crate) trait Round {
fn round(&self, mode: TemporalRoundingMode) -> i128;
fn round_as_positive(&self, mode: TemporalRoundingMode) -> u64;
fn round_as_positive(&self, mode: TemporalRoundingMode) -> u128;
}

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
Expand Down Expand Up @@ -85,12 +86,13 @@ impl<T: Roundable> Round for IncrementRounder<T> {
}

#[inline]
fn round_as_positive(&self, mode: TemporalRoundingMode) -> u64 {
fn round_as_positive(&self, mode: TemporalRoundingMode) -> u128 {
let unsigned_rounding_mode = mode.get_unsigned_round_mode(self.sign);
let rounded =
apply_unsigned_rounding_mode(self.dividend, self.divisor, unsigned_rounding_mode);
// TODO: Add unit tests for the below
rounded * <u64 as NumCast>::from(self.divisor).expect("increment is representable by a u64")
rounded
* <u128 as NumCast>::from(self.divisor).expect("increment is representable by a u64")
}
}

Expand All @@ -107,12 +109,12 @@ impl Roundable for i128 {
Roundable::result_floor(dividend, divisor).rem_euclid(2) == 0
}

fn result_floor(dividend: Self, divisor: Self) -> u64 {
Roundable::quotient_abs(dividend, divisor) as u64
fn result_floor(dividend: Self, divisor: Self) -> u128 {
Roundable::quotient_abs(dividend, divisor) as u128
}

fn result_ceil(dividend: Self, divisor: Self) -> u64 {
Roundable::quotient_abs(dividend, divisor) as u64 + 1
fn result_ceil(dividend: Self, divisor: Self) -> u128 {
Roundable::quotient_abs(dividend, divisor) as u128 + 1
}
}

Expand All @@ -134,12 +136,12 @@ impl Roundable for f64 {
(quotient.floor() / (quotient.ceil() - quotient.floor()) % 2.0) == 0.0
}

fn result_floor(dividend: Self, divisor: Self) -> u64 {
Roundable::quotient_abs(dividend, divisor).floor() as u64
fn result_floor(dividend: Self, divisor: Self) -> u128 {
Roundable::quotient_abs(dividend, divisor).floor() as u128
}

fn result_ceil(dividend: Self, divisor: Self) -> u64 {
Roundable::quotient_abs(dividend, divisor).ceil() as u64
fn result_ceil(dividend: Self, divisor: Self) -> u128 {
Roundable::quotient_abs(dividend, divisor).ceil() as u128
}
}

Expand All @@ -148,7 +150,7 @@ fn apply_unsigned_rounding_mode<T: Roundable>(
dividend: T,
divisor: T,
unsigned_rounding_mode: TemporalUnsignedRoundingMode,
) -> u64 {
) -> u128 {
// is_floor
// 1. If x is equal to r1, return r1.
if Roundable::is_exact(dividend, divisor) {
Expand Down
Loading