From cd37638c14b276ed02f9b753a2633c68da1f188f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 10 Feb 2022 00:00:00 +0000 Subject: [PATCH 1/4] Inline UnifyKey::index and UnifyKey::from_index --- compiler/rustc_infer/src/infer/type_variable.rs | 1 + compiler/rustc_middle/src/infer/unify_key.rs | 4 ++++ compiler/rustc_mir_transform/src/dest_prop.rs | 2 ++ compiler/rustc_type_ir/src/lib.rs | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/compiler/rustc_infer/src/infer/type_variable.rs b/compiler/rustc_infer/src/infer/type_variable.rs index d320728a43f95..0864edf44510a 100644 --- a/compiler/rustc_infer/src/infer/type_variable.rs +++ b/compiler/rustc_infer/src/infer/type_variable.rs @@ -416,6 +416,7 @@ impl<'tcx> ut::UnifyKey for TyVidEqKey<'tcx> { fn index(&self) -> u32 { self.vid.as_u32() } + #[inline] fn from_index(i: u32) -> Self { TyVidEqKey::from(ty::TyVid::from_u32(i)) } diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs index 7a6d08fcc349b..dd303aaada900 100644 --- a/compiler/rustc_middle/src/infer/unify_key.rs +++ b/compiler/rustc_middle/src/infer/unify_key.rs @@ -32,9 +32,11 @@ impl<'tcx> From for RegionVidKey<'tcx> { impl<'tcx> UnifyKey for RegionVidKey<'tcx> { type Value = UnifiedRegion<'tcx>; + #[inline] fn index(&self) -> u32 { self.vid.as_u32() } + #[inline] fn from_index(i: u32) -> Self { RegionVidKey::from(ty::RegionVid::from_u32(i)) } @@ -118,9 +120,11 @@ pub struct ConstVarValue<'tcx> { impl<'tcx> UnifyKey for ty::ConstVid<'tcx> { type Value = ConstVarValue<'tcx>; + #[inline] fn index(&self) -> u32 { self.index } + #[inline] fn from_index(i: u32) -> Self { ty::ConstVid { index: i, phantom: PhantomData } } diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index d469be7464144..237ead591a585 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -222,9 +222,11 @@ impl From for UnifyLocal { impl UnifyKey for UnifyLocal { type Value = (); + #[inline] fn index(&self) -> u32 { self.0.as_u32() } + #[inline] fn from_index(u: u32) -> Self { Self(Local::from_u32(u)) } diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index ec6fb622d32aa..e26f0033156bc 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -400,9 +400,11 @@ pub enum InferTy { /// they carry no values. impl UnifyKey for TyVid { type Value = (); + #[inline] fn index(&self) -> u32 { self.as_u32() } + #[inline] fn from_index(i: u32) -> TyVid { TyVid::from_u32(i) } @@ -419,6 +421,7 @@ impl UnifyKey for IntVid { fn index(&self) -> u32 { self.index } + #[inline] fn from_index(i: u32) -> IntVid { IntVid { index: i } } @@ -431,9 +434,11 @@ impl EqUnifyValue for FloatVarValue {} impl UnifyKey for FloatVid { type Value = Option; + #[inline] fn index(&self) -> u32 { self.index } + #[inline] fn from_index(i: u32) -> FloatVid { FloatVid { index: i } } From d04677750bc990ba1c04a54419e19527818f17a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 10 Feb 2022 00:00:00 +0000 Subject: [PATCH 2/4] Inline GenericArg conversion functions --- compiler/rustc_middle/src/ty/subst.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 151dbcea6b524..7dccef5e3ef0f 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -48,6 +48,7 @@ pub enum GenericArgKind<'tcx> { } impl<'tcx> GenericArgKind<'tcx> { + #[inline] fn pack(self) -> GenericArg<'tcx> { let (tag, ptr) = match self { GenericArgKind::Lifetime(lt) => { @@ -94,18 +95,21 @@ impl<'tcx> PartialOrd for GenericArg<'tcx> { } impl<'tcx> From> for GenericArg<'tcx> { + #[inline] fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> { GenericArgKind::Lifetime(r).pack() } } impl<'tcx> From> for GenericArg<'tcx> { + #[inline] fn from(ty: Ty<'tcx>) -> GenericArg<'tcx> { GenericArgKind::Type(ty).pack() } } impl<'tcx> From> for GenericArg<'tcx> { + #[inline] fn from(c: ty::Const<'tcx>) -> GenericArg<'tcx> { GenericArgKind::Const(c).pack() } From 81f12eb7ef78f0889f8ff089b3ca79d9a62a7d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sat, 12 Feb 2022 00:00:00 +0000 Subject: [PATCH 3/4] Inline Target::deref --- compiler/rustc_target/src/spec/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index d735f3d41fdb0..bfafe2d83d7c9 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1541,11 +1541,13 @@ impl Default for TargetOptions { impl Deref for Target { type Target = TargetOptions; + #[inline] fn deref(&self) -> &Self::Target { &self.options } } impl DerefMut for Target { + #[inline] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.options } From ea7142076194517f84a5b867bd49e62a814a8622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 15 Feb 2022 00:00:00 +0000 Subject: [PATCH 4/4] Inline LocalExpnId::from_raw and LocalExpnId::as_raw --- compiler/rustc_span/src/hygiene.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index e0d6bd8cb7bba..8265eb23c3db4 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -172,10 +172,12 @@ impl LocalExpnId { /// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST. pub const ROOT: LocalExpnId = LocalExpnId::from_u32(0); + #[inline] pub fn from_raw(idx: ExpnIndex) -> LocalExpnId { LocalExpnId::from_u32(idx.as_u32()) } + #[inline] pub fn as_raw(self) -> ExpnIndex { ExpnIndex::from_u32(self.as_u32()) }