Skip to content

Commit 167555f

Browse files
committed
Pack the u128 in SwitchTargets
1 parent cb7d863 commit 167555f

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

compiler/rustc_middle/src/mir/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1672,19 +1672,13 @@ mod size_asserts {
16721672
use super::*;
16731673
use rustc_data_structures::static_assert_size;
16741674
// tidy-alphabetical-start
1675-
// This can be removed after i128:128 is in the bootstrap compiler's target.
1676-
#[cfg(not(bootstrap))]
1677-
static_assert_size!(BasicBlockData<'_>, 144);
1675+
static_assert_size!(BasicBlockData<'_>, 136);
16781676
static_assert_size!(LocalDecl<'_>, 40);
16791677
static_assert_size!(SourceScopeData<'_>, 72);
16801678
static_assert_size!(Statement<'_>, 32);
16811679
static_assert_size!(StatementKind<'_>, 16);
1682-
// This can be removed after i128:128 is in the bootstrap compiler's target.
1683-
#[cfg(not(bootstrap))]
1684-
static_assert_size!(Terminator<'_>, 112);
1685-
// This can be removed after i128:128 is in the bootstrap compiler's target.
1686-
#[cfg(not(bootstrap))]
1687-
static_assert_size!(TerminatorKind<'_>, 96);
1680+
static_assert_size!(Terminator<'_>, 104);
1681+
static_assert_size!(TerminatorKind<'_>, 88);
16881682
static_assert_size!(VarDebugInfo<'_>, 88);
16891683
// tidy-alphabetical-end
16901684
}

compiler/rustc_middle/src/mir/syntax.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::ty::{self, List, Ty};
1313
use crate::ty::{Region, UserTypeAnnotationIndex};
1414

1515
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
16+
use rustc_data_structures::packed::Pu128;
1617
use rustc_hir::def_id::DefId;
1718
use rustc_hir::{self, CoroutineKind};
1819
use rustc_index::IndexVec;
@@ -829,7 +830,7 @@ impl TerminatorKind<'_> {
829830
pub struct SwitchTargets {
830831
/// Possible values. The locations to branch to in each case
831832
/// are found in the corresponding indices from the `targets` vector.
832-
pub(super) values: SmallVec<[u128; 1]>,
833+
pub(super) values: SmallVec<[Pu128; 1]>,
833834

834835
/// Possible branch sites. The last element of this vector is used
835836
/// for the otherwise branch, so targets.len() == values.len() + 1

compiler/rustc_middle/src/mir/terminator.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_hir::LangItem;
33
use smallvec::SmallVec;
44

55
use super::TerminatorKind;
6+
use rustc_data_structures::packed::Pu128;
67
use rustc_macros::HashStable;
78
use std::slice;
89

@@ -14,15 +15,16 @@ impl SwitchTargets {
1415
/// The iterator may be empty, in which case the `SwitchInt` instruction is equivalent to
1516
/// `goto otherwise;`.
1617
pub fn new(targets: impl Iterator<Item = (u128, BasicBlock)>, otherwise: BasicBlock) -> Self {
17-
let (values, mut targets): (SmallVec<_>, SmallVec<_>) = targets.unzip();
18+
let (values, mut targets): (SmallVec<_>, SmallVec<_>) =
19+
targets.map(|(v, t)| (Pu128(v), t)).unzip();
1820
targets.push(otherwise);
1921
Self { values, targets }
2022
}
2123

2224
/// Builds a switch targets definition that jumps to `then` if the tested value equals `value`,
2325
/// and to `else_` if not.
2426
pub fn static_if(value: u128, then: BasicBlock, else_: BasicBlock) -> Self {
25-
Self { values: smallvec![value], targets: smallvec![then, else_] }
27+
Self { values: smallvec![Pu128(value)], targets: smallvec![then, else_] }
2628
}
2729

2830
/// Inverse of `SwitchTargets::static_if`.
@@ -31,7 +33,7 @@ impl SwitchTargets {
3133
if let &[value] = &self.values[..]
3234
&& let &[then, else_] = &self.targets[..]
3335
{
34-
Some((value, then, else_))
36+
Some((value.get(), then, else_))
3537
} else {
3638
None
3739
}
@@ -75,15 +77,15 @@ impl SwitchTargets {
7577
}
7678

7779
pub struct SwitchTargetsIter<'a> {
78-
inner: iter::Zip<slice::Iter<'a, u128>, slice::Iter<'a, BasicBlock>>,
80+
inner: iter::Zip<slice::Iter<'a, Pu128>, slice::Iter<'a, BasicBlock>>,
7981
}
8082

8183
impl<'a> Iterator for SwitchTargetsIter<'a> {
8284
type Item = (u128, BasicBlock);
8385

8486
#[inline]
8587
fn next(&mut self) -> Option<Self::Item> {
86-
self.inner.next().map(|(val, bb)| (*val, *bb))
88+
self.inner.next().map(|(val, bb)| (val.get(), *bb))
8789
}
8890

8991
#[inline]

0 commit comments

Comments
 (0)