Auto merge of #105446 - erikdesjardins:vt-size, r=nikic
Add 0..=isize::MAX range metadata to size loads from vtables This is the (much belated) size counterpart to #91569. Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often. Miri detects this UB already:b7cc99142a/compiler/rustc_const_eval/src/interpret/traits.rs (L119-L121)
(In fact Miri goes further, [assuming a 48-bit address space on 64-bit platforms](9db224fc90/compiler/rustc_abi/src/lib.rs (L312-L331)
), but I don't think we can assume that in an optimization.)
This commit is contained in:
commit
2b094b1ede
5 changed files with 76 additions and 4 deletions
|
@ -774,6 +774,18 @@ impl Integer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the largest signed value that can be represented by this Integer.
|
||||
#[inline]
|
||||
pub fn signed_max(self) -> i128 {
|
||||
match self {
|
||||
I8 => i8::MAX as i128,
|
||||
I16 => i16::MAX as i128,
|
||||
I32 => i32::MAX as i128,
|
||||
I64 => i64::MAX as i128,
|
||||
I128 => i128::MAX,
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the smallest Integer type which can represent the signed value.
|
||||
#[inline]
|
||||
pub fn fit_signed(x: i128) -> Integer {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue