about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2024-01-17 16:22:11 -0800
committerJosh Stone <jistone@redhat.com>2024-01-19 20:10:39 -0800
commit167555f36a3b3e7f4a0a685c63d928bbd32f1157 (patch)
treec0be2628705bf1028127f992e5a65c9ef7bfc8b5
parentcb7d863e742ae3782174db2acf57310cd1b27561 (diff)
downloadrust-167555f36a3b3e7f4a0a685c63d928bbd32f1157.tar.gz
rust-167555f36a3b3e7f4a0a685c63d928bbd32f1157.zip
Pack the u128 in SwitchTargets
-rw-r--r--compiler/rustc_middle/src/mir/mod.rs12
-rw-r--r--compiler/rustc_middle/src/mir/syntax.rs3
-rw-r--r--compiler/rustc_middle/src/mir/terminator.rs12
3 files changed, 12 insertions, 15 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index 624ae8c22f9..36f5ba161d5 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -1672,19 +1672,13 @@ mod size_asserts {
     use super::*;
     use rustc_data_structures::static_assert_size;
     // tidy-alphabetical-start
-    // This can be removed after i128:128 is in the bootstrap compiler's target.
-    #[cfg(not(bootstrap))]
-    static_assert_size!(BasicBlockData<'_>, 144);
+    static_assert_size!(BasicBlockData<'_>, 136);
     static_assert_size!(LocalDecl<'_>, 40);
     static_assert_size!(SourceScopeData<'_>, 72);
     static_assert_size!(Statement<'_>, 32);
     static_assert_size!(StatementKind<'_>, 16);
-    // This can be removed after i128:128 is in the bootstrap compiler's target.
-    #[cfg(not(bootstrap))]
-    static_assert_size!(Terminator<'_>, 112);
-    // This can be removed after i128:128 is in the bootstrap compiler's target.
-    #[cfg(not(bootstrap))]
-    static_assert_size!(TerminatorKind<'_>, 96);
+    static_assert_size!(Terminator<'_>, 104);
+    static_assert_size!(TerminatorKind<'_>, 88);
     static_assert_size!(VarDebugInfo<'_>, 88);
     // tidy-alphabetical-end
 }
diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs
index 6ebe57e29da..a5c229879a7 100644
--- a/compiler/rustc_middle/src/mir/syntax.rs
+++ b/compiler/rustc_middle/src/mir/syntax.rs
@@ -13,6 +13,7 @@ use crate::ty::{self, List, Ty};
 use crate::ty::{Region, UserTypeAnnotationIndex};
 
 use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
+use rustc_data_structures::packed::Pu128;
 use rustc_hir::def_id::DefId;
 use rustc_hir::{self, CoroutineKind};
 use rustc_index::IndexVec;
@@ -829,7 +830,7 @@ impl TerminatorKind<'_> {
 pub struct SwitchTargets {
     /// Possible values. The locations to branch to in each case
     /// are found in the corresponding indices from the `targets` vector.
-    pub(super) values: SmallVec<[u128; 1]>,
+    pub(super) values: SmallVec<[Pu128; 1]>,
 
     /// Possible branch sites. The last element of this vector is used
     /// for the otherwise branch, so targets.len() == values.len() + 1
diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs
index 385237b357b..fdbbf468ece 100644
--- a/compiler/rustc_middle/src/mir/terminator.rs
+++ b/compiler/rustc_middle/src/mir/terminator.rs
@@ -3,6 +3,7 @@ use rustc_hir::LangItem;
 use smallvec::SmallVec;
 
 use super::TerminatorKind;
+use rustc_data_structures::packed::Pu128;
 use rustc_macros::HashStable;
 use std::slice;
 
@@ -14,7 +15,8 @@ impl SwitchTargets {
     /// The iterator may be empty, in which case the `SwitchInt` instruction is equivalent to
     /// `goto otherwise;`.
     pub fn new(targets: impl Iterator<Item = (u128, BasicBlock)>, otherwise: BasicBlock) -> Self {
-        let (values, mut targets): (SmallVec<_>, SmallVec<_>) = targets.unzip();
+        let (values, mut targets): (SmallVec<_>, SmallVec<_>) =
+            targets.map(|(v, t)| (Pu128(v), t)).unzip();
         targets.push(otherwise);
         Self { values, targets }
     }
@@ -22,7 +24,7 @@ impl SwitchTargets {
     /// Builds a switch targets definition that jumps to `then` if the tested value equals `value`,
     /// and to `else_` if not.
     pub fn static_if(value: u128, then: BasicBlock, else_: BasicBlock) -> Self {
-        Self { values: smallvec![value], targets: smallvec![then, else_] }
+        Self { values: smallvec![Pu128(value)], targets: smallvec![then, else_] }
     }
 
     /// Inverse of `SwitchTargets::static_if`.
@@ -31,7 +33,7 @@ impl SwitchTargets {
         if let &[value] = &self.values[..]
             && let &[then, else_] = &self.targets[..]
         {
-            Some((value, then, else_))
+            Some((value.get(), then, else_))
         } else {
             None
         }
@@ -75,7 +77,7 @@ impl SwitchTargets {
 }
 
 pub struct SwitchTargetsIter<'a> {
-    inner: iter::Zip<slice::Iter<'a, u128>, slice::Iter<'a, BasicBlock>>,
+    inner: iter::Zip<slice::Iter<'a, Pu128>, slice::Iter<'a, BasicBlock>>,
 }
 
 impl<'a> Iterator for SwitchTargetsIter<'a> {
@@ -83,7 +85,7 @@ impl<'a> Iterator for SwitchTargetsIter<'a> {
 
     #[inline]
     fn next(&mut self) -> Option<Self::Item> {
-        self.inner.next().map(|(val, bb)| (*val, *bb))
+        self.inner.next().map(|(val, bb)| (val.get(), *bb))
     }
 
     #[inline]