From e9d54e1860d1d246382ef222386f3b58e6e10e56 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 1 Oct 2019 15:48:25 +1000 Subject: [PATCH 1/4] Reorder the slice interners. So the order matches the order in `CtxtInterners`. --- src/librustc/ty/context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 6c5d9a6dfdf22..ee6930551e5e6 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2215,10 +2215,10 @@ macro_rules! slice_interners { } slice_interners!( - existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>), - predicates: _intern_predicates(Predicate<'tcx>), type_list: _intern_type_list(Ty<'tcx>), substs: _intern_substs(GenericArg<'tcx>), + existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>), + predicates: _intern_predicates(Predicate<'tcx>), clauses: _intern_clauses(Clause<'tcx>), goal_list: _intern_goals(Goal<'tcx>), projs: _intern_projs(ProjectionKind) From 3724e37b5a21c497a295129af0fe67072c6b89d1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 1 Oct 2019 15:49:37 +1000 Subject: [PATCH 2/4] Remove special treatment for `_intern_canonical_var_infos`. This is a leftover from when there were global and thread-local arenas. --- src/librustc/ty/context.rs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index ee6930551e5e6..7012d34479d59 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2217,6 +2217,7 @@ macro_rules! slice_interners { slice_interners!( type_list: _intern_type_list(Ty<'tcx>), substs: _intern_substs(GenericArg<'tcx>), + canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo), existential_predicates: _intern_existential_predicates(ExistentialPredicate<'tcx>), predicates: _intern_predicates(Predicate<'tcx>), clauses: _intern_clauses(Clause<'tcx>), @@ -2224,20 +2225,6 @@ slice_interners!( projs: _intern_projs(ProjectionKind) ); -// This isn't a perfect fit: `CanonicalVarInfo` slices are always -// allocated in the global arena, so this `intern_method!` macro is -// overly general. However, we just return `false` for the code that checks -// whether they belong in the thread-local arena, so no harm done, and -// seems better than open-coding the rest. -intern_method! { - 'tcx, - canonical_var_infos: _intern_canonical_var_infos( - &[CanonicalVarInfo], - |a, v| List::from_arena(a, v), - Deref::deref - ) -> List -} - impl<'tcx> TyCtxt<'tcx> { /// Given a `fn` type, returns an equivalent `unsafe fn` type; /// that is, a `fn` type that is equivalent in every way for being From 475e131b3e877d3926b5869cde5b548825f0ceb1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 1 Oct 2019 16:03:25 +1000 Subject: [PATCH 3/4] Inline and remove `intern_method!`. It's only used in two places, and the code is shorter and more readable with it gone. --- src/librustc/ty/context.rs | 40 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 7012d34479d59..b520e66fc4922 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2154,23 +2154,6 @@ impl<'tcx> Borrow<[Goal<'tcx>]> for Interned<'tcx, List>> { } } -macro_rules! intern_method { - ($lt_tcx:tt, $name:ident: $method:ident($alloc:ty, - $alloc_method:expr, - $alloc_to_key:expr) -> $ty:ty) => { - impl<$lt_tcx> TyCtxt<$lt_tcx> { - pub fn $method(self, v: $alloc) -> &$lt_tcx $ty { - let key = ($alloc_to_key)(&v); - - self.interners.$name.intern_ref(key, || { - Interned($alloc_method(&self.interners.arena, v)) - - }).0 - } - } - } -} - macro_rules! direct_interners { ($lt_tcx:tt, $($name:ident: $method:ident($ty:ty)),+) => { $(impl<$lt_tcx> PartialEq for Interned<$lt_tcx, $ty> { @@ -2187,11 +2170,13 @@ macro_rules! direct_interners { } } - intern_method!( - $lt_tcx, - $name: $method($ty, - |a: &$lt_tcx SyncDroplessArena, v| -> &$lt_tcx $ty { a.alloc(v) }, - |x| x) -> $ty);)+ + impl<$lt_tcx> TyCtxt<$lt_tcx> { + pub fn $method(self, v: $ty) -> &$lt_tcx $ty { + self.interners.$name.intern_ref(&v, || { + Interned(self.interners.arena.alloc(v)) + }).0 + } + })+ } } @@ -2207,10 +2192,13 @@ direct_interners!('tcx, macro_rules! slice_interners { ($($field:ident: $method:ident($ty:ty)),+) => ( - $(intern_method!( 'tcx, $field: $method( - &[$ty], - |a, v| List::from_arena(a, v), - Deref::deref) -> List<$ty>);)+ + $(impl<'tcx> TyCtxt<'tcx> { + pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> { + self.interners.$field.intern_ref(v, || { + Interned(List::from_arena(&self.interners.arena, v)) + }).0 + } + })+ ); } From b2ae3f2a6b4d6e8c6a02173aa7db9a6370c3bc9c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 1 Oct 2019 16:07:57 +1000 Subject: [PATCH 4/4] Remove the `$lt_tcx` parameter from `direct_interners!`. It's not necessary. --- src/librustc/ty/context.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index b520e66fc4922..740e916dd5cc1 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2155,23 +2155,23 @@ impl<'tcx> Borrow<[Goal<'tcx>]> for Interned<'tcx, List>> { } macro_rules! direct_interners { - ($lt_tcx:tt, $($name:ident: $method:ident($ty:ty)),+) => { - $(impl<$lt_tcx> PartialEq for Interned<$lt_tcx, $ty> { + ($($name:ident: $method:ident($ty:ty)),+) => { + $(impl<'tcx> PartialEq for Interned<'tcx, $ty> { fn eq(&self, other: &Self) -> bool { self.0 == other.0 } } - impl<$lt_tcx> Eq for Interned<$lt_tcx, $ty> {} + impl<'tcx> Eq for Interned<'tcx, $ty> {} - impl<$lt_tcx> Hash for Interned<$lt_tcx, $ty> { + impl<'tcx> Hash for Interned<'tcx, $ty> { fn hash(&self, s: &mut H) { self.0.hash(s) } } - impl<$lt_tcx> TyCtxt<$lt_tcx> { - pub fn $method(self, v: $ty) -> &$lt_tcx $ty { + impl<'tcx> TyCtxt<'tcx> { + pub fn $method(self, v: $ty) -> &'tcx $ty { self.interners.$name.intern_ref(&v, || { Interned(self.interners.arena.alloc(v)) }).0 @@ -2184,7 +2184,7 @@ pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool { x.has_type_flags(ty::TypeFlags::KEEP_IN_LOCAL_TCX) } -direct_interners!('tcx, +direct_interners!( region: mk_region(RegionKind), goal: mk_goal(GoalKind<'tcx>), const_: mk_const(Const<'tcx>)