ty::context: move interning Allocation
s and Layout
s to direct_interners!
.
This commit is contained in:
parent
7f2f927eb8
commit
0c02e3f550
1 changed files with 26 additions and 55 deletions
|
@ -118,8 +118,8 @@ pub struct CtxtInterners<'tcx> {
|
|||
/// The arena that types, regions, etc. are allocated from.
|
||||
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
||||
|
||||
/// Specifically use a speedy hash algorithm for these hash sets, since
|
||||
/// they're accessed quite often.
|
||||
// Specifically use a speedy hash algorithm for these hash sets, since
|
||||
// they're accessed quite often.
|
||||
type_: InternedSet<'tcx, TyS<'tcx>>,
|
||||
type_list: InternedSet<'tcx, List<Ty<'tcx>>>,
|
||||
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
|
||||
|
@ -132,9 +132,9 @@ pub struct CtxtInterners<'tcx> {
|
|||
projs: InternedSet<'tcx, List<ProjectionKind>>,
|
||||
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
|
||||
const_: InternedSet<'tcx, Const<'tcx>>,
|
||||
/// Const allocations.
|
||||
allocation: InternedSet<'tcx, Allocation>,
|
||||
const_allocation: InternedSet<'tcx, Allocation>,
|
||||
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
|
||||
layout: InternedSet<'tcx, Layout>,
|
||||
}
|
||||
|
||||
impl<'tcx> CtxtInterners<'tcx> {
|
||||
|
@ -152,8 +152,9 @@ impl<'tcx> CtxtInterners<'tcx> {
|
|||
projs: Default::default(),
|
||||
place_elems: Default::default(),
|
||||
const_: Default::default(),
|
||||
allocation: Default::default(),
|
||||
const_allocation: Default::default(),
|
||||
bound_variable_kinds: Default::default(),
|
||||
layout: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1062,10 +1063,9 @@ pub struct GlobalCtxt<'tcx> {
|
|||
/// Stores memory for globals (statics/consts).
|
||||
pub(crate) alloc_map: Lock<interpret::AllocMap<'tcx>>,
|
||||
|
||||
layout_interner: ShardedHashMap<&'tcx Layout, ()>,
|
||||
|
||||
output_filenames: Arc<OutputFilenames>,
|
||||
|
||||
// FIXME(eddyb) this doesn't belong here and should be using a query.
|
||||
pub(super) vtables_cache:
|
||||
Lock<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), AllocId>>,
|
||||
}
|
||||
|
@ -1107,13 +1107,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.arena.alloc(ty::AdtDef::new(self, did, kind, variants, repr))
|
||||
}
|
||||
|
||||
pub fn intern_const_alloc(self, alloc: Allocation) -> &'tcx Allocation {
|
||||
self.interners
|
||||
.allocation
|
||||
.intern(alloc, |alloc| Interned(self.interners.arena.alloc(alloc)))
|
||||
.0
|
||||
}
|
||||
|
||||
/// Allocates a read-only byte or string literal for `mir::interpret`.
|
||||
pub fn allocate_bytes(self, bytes: &[u8]) -> interpret::AllocId {
|
||||
// Create an allocation that just contains these bytes.
|
||||
|
@ -1122,20 +1115,19 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.create_memory_alloc(alloc)
|
||||
}
|
||||
|
||||
// FIXME(eddyb) move to `direct_interners!`.
|
||||
pub fn intern_stability(self, stab: attr::Stability) -> &'tcx attr::Stability {
|
||||
self.stability_interner.intern(stab, |stab| self.arena.alloc(stab))
|
||||
}
|
||||
|
||||
// FIXME(eddyb) move to `direct_interners!`.
|
||||
pub fn intern_const_stability(self, stab: attr::ConstStability) -> &'tcx attr::ConstStability {
|
||||
self.const_stability_interner.intern(stab, |stab| self.arena.alloc(stab))
|
||||
}
|
||||
|
||||
pub fn intern_layout(self, layout: Layout) -> &'tcx Layout {
|
||||
self.layout_interner.intern(layout, |layout| self.arena.alloc(layout))
|
||||
}
|
||||
|
||||
/// Returns a range of the start/end indices specified with the
|
||||
/// `rustc_layout_scalar_valid_range` attribute.
|
||||
// FIXME(eddyb) this is an awkward spot for this method, maybe move it?
|
||||
pub fn layout_scalar_valid_range(self, def_id: DefId) -> (Bound<u128>, Bound<u128>) {
|
||||
let attrs = self.get_attrs(def_id);
|
||||
let get = |name| {
|
||||
|
@ -1210,7 +1202,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
evaluation_cache: Default::default(),
|
||||
crate_name: Symbol::intern(crate_name),
|
||||
data_layout,
|
||||
layout_interner: Default::default(),
|
||||
stability_interner: Default::default(),
|
||||
const_stability_interner: Default::default(),
|
||||
alloc_map: Lock::new(interpret::AllocMap::new()),
|
||||
|
@ -1670,7 +1661,7 @@ macro_rules! nop_list_lift {
|
|||
nop_lift! {type_; Ty<'a> => Ty<'tcx>}
|
||||
nop_lift! {region; Region<'a> => Region<'tcx>}
|
||||
nop_lift! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
|
||||
nop_lift! {allocation; &'a Allocation => &'tcx Allocation}
|
||||
nop_lift! {const_allocation; &'a Allocation => &'tcx Allocation}
|
||||
nop_lift! {predicate; &'a PredicateInner<'a> => &'tcx PredicateInner<'tcx>}
|
||||
|
||||
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
|
||||
|
@ -1962,8 +1953,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
"Const Stability interner: #{}",
|
||||
self.0.const_stability_interner.len()
|
||||
)?;
|
||||
writeln!(fmt, "Allocation interner: #{}", self.0.interners.allocation.len())?;
|
||||
writeln!(fmt, "Layout interner: #{}", self.0.layout_interner.len())?;
|
||||
writeln!(
|
||||
fmt,
|
||||
"Const Allocation interner: #{}",
|
||||
self.0.interners.const_allocation.len()
|
||||
)?;
|
||||
writeln!(fmt, "Layout interner: #{}", self.0.interners.layout.len())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -2051,38 +2046,6 @@ impl<'tcx, T> Borrow<[T]> for Interned<'tcx, List<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Borrow<RegionKind> for Interned<'tcx, RegionKind> {
|
||||
fn borrow(&self) -> &RegionKind {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Borrow<Const<'tcx>> for Interned<'tcx, Const<'tcx>> {
|
||||
fn borrow<'a>(&'a self) -> &'a Const<'tcx> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Borrow<Allocation> for Interned<'tcx, Allocation> {
|
||||
fn borrow<'a>(&'a self) -> &'a Allocation {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PartialEq for Interned<'tcx, Allocation> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Eq for Interned<'tcx, Allocation> {}
|
||||
|
||||
impl<'tcx> Hash for Interned<'tcx, Allocation> {
|
||||
fn hash<H: Hasher>(&self, s: &mut H) {
|
||||
self.0.hash(s)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! direct_interners {
|
||||
($($name:ident: $method:ident($ty:ty),)+) => {
|
||||
$(impl<'tcx> PartialEq for Interned<'tcx, $ty> {
|
||||
|
@ -2099,9 +2062,15 @@ macro_rules! direct_interners {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Borrow<$ty> for Interned<'tcx, $ty> {
|
||||
fn borrow<'a>(&'a self) -> &'a $ty {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn $method(self, v: $ty) -> &'tcx $ty {
|
||||
self.interners.$name.intern_ref(&v, || {
|
||||
self.interners.$name.intern(v, |v| {
|
||||
Interned(self.interners.arena.alloc(v))
|
||||
}).0
|
||||
}
|
||||
|
@ -2112,6 +2081,8 @@ macro_rules! direct_interners {
|
|||
direct_interners! {
|
||||
region: mk_region(RegionKind),
|
||||
const_: mk_const(Const<'tcx>),
|
||||
const_allocation: intern_const_alloc(Allocation),
|
||||
layout: intern_layout(Layout),
|
||||
}
|
||||
|
||||
macro_rules! slice_interners {
|
||||
|
|
Loading…
Add table
Reference in a new issue