From 167555f36a3b3e7f4a0a685c63d928bbd32f1157 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 17 Jan 2024 16:22:11 -0800 Subject: [PATCH] Pack the u128 in SwitchTargets --- compiler/rustc_middle/src/mir/mod.rs | 12 +++--------- compiler/rustc_middle/src/mir/syntax.rs | 3 ++- compiler/rustc_middle/src/mir/terminator.rs | 12 +++++++----- 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, 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, BasicBlock>>, + inner: iter::Zip, 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.inner.next().map(|(val, bb)| (*val, *bb)) + self.inner.next().map(|(val, bb)| (val.get(), *bb)) } #[inline]