Skip to content

Commit

Permalink
Split CommonTypes into CommonTypes and CommonLifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Apr 25, 2019
1 parent bd31c39 commit 2c20c44
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ pub struct CommonTypes<'tcx> {
/// a trait object, and which gets removed in `ExistentialTraitRef`.
/// This type must not appear anywhere in other converted types.
pub trait_object_dummy_self: Ty<'tcx>,
}

pub struct CommonLifetimes<'tcx> {
pub re_empty: Region<'tcx>,
pub re_static: Region<'tcx>,
pub re_erased: Region<'tcx>,
Expand Down Expand Up @@ -933,11 +935,6 @@ EnumLiftImpl! {
impl<'tcx> CommonTypes<'tcx> {
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
let mk_region = |r| {
interners.region.borrow_mut().intern(r, |r| {
Interned(interners.arena.alloc(r))
}).0
};

CommonTypes {
unit: mk(Tuple(List::empty())),
Expand All @@ -961,10 +958,22 @@ impl<'tcx> CommonTypes<'tcx> {
f64: mk(Float(ast::FloatTy::F64)),

trait_object_dummy_self: mk(Infer(ty::FreshTy(0))),
}
}
}

re_empty: mk_region(RegionKind::ReEmpty),
re_static: mk_region(RegionKind::ReStatic),
re_erased: mk_region(RegionKind::ReErased),
impl<'tcx> CommonLifetimes<'tcx> {
fn new(interners: &CtxtInterners<'tcx>) -> CommonLifetimes<'tcx> {
let mk = |r| {
interners.region.borrow_mut().intern(r, |r| {
Interned(interners.arena.alloc(r))
}).0
};

CommonLifetimes {
re_empty: mk(RegionKind::ReEmpty),
re_static: mk(RegionKind::ReStatic),
re_erased: mk(RegionKind::ReErased),
}
}
}
Expand Down Expand Up @@ -1016,6 +1025,9 @@ pub struct GlobalCtxt<'tcx> {
/// Common types, pre-interned for your convenience.
pub types: CommonTypes<'tcx>,

/// Common lifetimes, pre-interned for your convenience.
pub lifetimes: CommonLifetimes<'tcx>,

/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
trait_map: FxHashMap<DefIndex,
Expand Down Expand Up @@ -1214,6 +1226,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
});
let interners = CtxtInterners::new(&arenas.interner);
let common_types = CommonTypes::new(&interners);
let common_lifetimes = CommonLifetimes::new(&interners);
let dep_graph = hir.dep_graph.clone();
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
Expand Down Expand Up @@ -1268,6 +1281,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
global_interners: interners,
dep_graph,
types: common_types,
lifetimes: common_lifetimes,
trait_map,
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
let exports: Vec<_> = v.into_iter().map(|e| {
Expand Down Expand Up @@ -2486,7 +2500,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

#[inline]
pub fn mk_static_str(self) -> Ty<'tcx> {
self.mk_imm_ref(self.types.re_static, self.mk_str())
self.mk_imm_ref(self.lifetimes.re_static, self.mk_str())
}

#[inline]
Expand Down

0 comments on commit 2c20c44

Please sign in to comment.