Skip to content

Commit 727e350

Browse files
raskyldtgross35
authored andcommitted
fix(int): avoid infinite recursion on left shift
Please, see this discussion for the full context: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.5Bwasm32.5D.20Infinite.20recursion.20.60compiler-builtins.60.20.60__multi3.60 Signed-off-by: Enzo "raskyld" Nocera <[email protected]> We determined that some recursion problems on SPARC and WASM were due to infinite recusion. This was introduced at 9c6fcb5 ("Split Int into Int and MinInt") when moving the implementation of `widen_hi` from something on each `impl` block to a default on the trait. The reasoning is not fully understood, but undoing this portion of the change seems to resolve the issue. [ add the above context - Trevor ] Signed-off-by: Trevor Gross <[email protected]>
1 parent 96851fd commit 727e350

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: src/int/big.rs

+8
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ impl HInt for u128 {
222222
fn widen_mul(self, rhs: Self) -> Self::D {
223223
self.zero_widen_mul(rhs)
224224
}
225+
226+
fn widen_hi(self) -> Self::D {
227+
self.widen() << <Self as MinInt>::BITS
228+
}
225229
}
226230

227231
impl HInt for i128 {
@@ -247,6 +251,10 @@ impl HInt for i128 {
247251
fn widen_mul(self, rhs: Self) -> Self::D {
248252
unimplemented!("signed i128 widening multiply is not used")
249253
}
254+
255+
fn widen_hi(self) -> Self::D {
256+
self.widen() << <Self as MinInt>::BITS
257+
}
250258
}
251259

252260
impl DInt for u256 {

Diff for: src/int/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ pub(crate) trait HInt: Int {
319319
/// around problems with associated type bounds (such as `Int<Othersign: DInt>`) being unstable
320320
fn zero_widen(self) -> Self::D;
321321
/// Widens the integer to have double bit width and shifts the integer into the higher bits
322-
fn widen_hi(self) -> Self::D {
323-
self.widen() << <Self as MinInt>::BITS
324-
}
322+
fn widen_hi(self) -> Self::D;
325323
/// Widening multiplication with zero widening. This cannot overflow.
326324
fn zero_widen_mul(self, rhs: Self) -> Self::D;
327325
/// Widening multiplication. This cannot overflow.
@@ -364,6 +362,9 @@ macro_rules! impl_h_int {
364362
fn widen_mul(self, rhs: Self) -> Self::D {
365363
self.widen().wrapping_mul(rhs.widen())
366364
}
365+
fn widen_hi(self) -> Self::D {
366+
(self as $X) << <Self as MinInt>::BITS
367+
}
367368
}
368369
)*
369370
};

0 commit comments

Comments
 (0)