Inline and remove intern_method!.

It's only used in two places, and the code is shorter and more readable
with it gone.
This commit is contained in:
Nicholas Nethercote 2019-10-01 16:03:25 +10:00
parent 3724e37b5a
commit 475e131b3e

View file

@ -2154,23 +2154,6 @@ impl<'tcx> Borrow<[Goal<'tcx>]> for Interned<'tcx, List<Goal<'tcx>>> {
} }
} }
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 { macro_rules! direct_interners {
($lt_tcx:tt, $($name:ident: $method:ident($ty:ty)),+) => { ($lt_tcx:tt, $($name:ident: $method:ident($ty:ty)),+) => {
$(impl<$lt_tcx> PartialEq for Interned<$lt_tcx, $ty> { $(impl<$lt_tcx> PartialEq for Interned<$lt_tcx, $ty> {
@ -2187,11 +2170,13 @@ macro_rules! direct_interners {
} }
} }
intern_method!( impl<$lt_tcx> TyCtxt<$lt_tcx> {
$lt_tcx, pub fn $method(self, v: $ty) -> &$lt_tcx $ty {
$name: $method($ty, self.interners.$name.intern_ref(&v, || {
|a: &$lt_tcx SyncDroplessArena, v| -> &$lt_tcx $ty { a.alloc(v) }, Interned(self.interners.arena.alloc(v))
|x| x) -> $ty);)+ }).0
}
})+
} }
} }
@ -2207,10 +2192,13 @@ direct_interners!('tcx,
macro_rules! slice_interners { macro_rules! slice_interners {
($($field:ident: $method:ident($ty:ty)),+) => ( ($($field:ident: $method:ident($ty:ty)),+) => (
$(intern_method!( 'tcx, $field: $method( $(impl<'tcx> TyCtxt<'tcx> {
&[$ty], pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> {
|a, v| List::from_arena(a, v), self.interners.$field.intern_ref(v, || {
Deref::deref) -> List<$ty>);)+ Interned(List::from_arena(&self.interners.arena, v))
}).0
}
})+
); );
} }