Skip to content

Commit

Permalink
rustc: Remove the unnecessary ast_ty_to_ty_cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed May 11, 2016
1 parent 2065216 commit 3a30136
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 39 deletions.
3 changes: 1 addition & 2 deletions src/librustc/hir/def.rs
Expand Up @@ -17,8 +17,7 @@ use hir;
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Def {
Fn(DefId),
SelfTy(Option<DefId>, // trait id
Option<(ast::NodeId, ast::NodeId)>), // (impl id, self type id)
SelfTy(Option<DefId> /* trait */, Option<ast::NodeId> /* impl */),
Mod(DefId),
ForeignMod(DefId),
Static(DefId, bool /* is_mutbl */),
Expand Down
6 changes: 0 additions & 6 deletions src/librustc/ty/context.rs
Expand Up @@ -356,11 +356,6 @@ pub struct GlobalCtxt<'tcx> {
// Cache for the type-contents routine. FIXME -- track deps?
pub tc_cache: RefCell<FnvHashMap<Ty<'tcx>, ty::contents::TypeContents>>,

// Cache for various types within a method body and so forth.
//
// FIXME this should be made local to typeck, but it is currently used by one lint
pub ast_ty_to_ty_cache: RefCell<NodeMap<Ty<'tcx>>>,

// FIXME no dep tracking, but we should be able to remove this
pub ty_param_defs: RefCell<NodeMap<ty::TypeParameterDef<'tcx>>>,

Expand Down Expand Up @@ -664,7 +659,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
tcache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
rcache: RefCell::new(FnvHashMap()),
tc_cache: RefCell::new(FnvHashMap()),
ast_ty_to_ty_cache: RefCell::new(NodeMap()),
impl_or_trait_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
trait_item_def_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
trait_items_cache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/ty/sty.rs
Expand Up @@ -93,10 +93,8 @@ pub enum TypeVariants<'tcx> {
/// Substs here, possibly against intuition, *may* contain `TyParam`s.
/// That is, even after substitution it is possible that there are type
/// variables. This happens when the `TyEnum` corresponds to an enum
/// definition and not a concrete use of it. To get the correct `TyEnum`
/// from the tcx, use the `NodeId` from the `ast::Ty` and look it up in
/// the `ast_ty_to_ty_cache`. This is probably true for `TyStruct` as
/// well.
/// definition and not a concrete use of it. This is true for `TyStruct`
/// as well.
TyEnum(AdtDef<'tcx>, &'tcx Substs<'tcx>),

/// A structure type, defined with `struct`.
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_metadata/astencode.rs
Expand Up @@ -362,11 +362,8 @@ impl tr for Def {
match *self {
Def::Fn(did) => Def::Fn(did.tr(dcx)),
Def::Method(did) => Def::Method(did.tr(dcx)),
Def::SelfTy(opt_did, impl_ids) => { Def::SelfTy(opt_did.map(|did| did.tr(dcx)),
impl_ids.map(|(nid1, nid2)| {
(dcx.tr_id(nid1),
dcx.tr_id(nid2))
})) }
Def::SelfTy(opt_did, impl_id) => { Def::SelfTy(opt_did.map(|did| did.tr(dcx)),
impl_id.map(|id| dcx.tr_id(id))) }
Def::Mod(did) => { Def::Mod(did.tr(dcx)) }
Def::ForeignMod(did) => { Def::ForeignMod(did.tr(dcx)) }
Def::Static(did, m) => { Def::Static(did.tr(dcx), m) }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -1938,7 +1938,7 @@ impl<'a> Resolver<'a> {
// Resolve the self type.
this.visit_ty(self_type);

this.with_self_rib(Def::SelfTy(trait_id, Some((item_id, self_type.id))), |this| {
this.with_self_rib(Def::SelfTy(trait_id, Some(item_id)), |this| {
this.with_current_self_type(self_type, |this| {
for impl_item in impl_items {
this.resolve_visibility(&impl_item.vis);
Expand Down
28 changes: 8 additions & 20 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -1272,7 +1272,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,
// Find the type of the associated item, and the trait where the associated
// item is declared.
let bound = match (&ty.sty, ty_path_def) {
(_, Def::SelfTy(Some(trait_did), Some((impl_id, _)))) => {
(_, Def::SelfTy(Some(trait_did), Some(impl_id))) => {
// `Self` in an impl of a trait - we have a concrete self type and a
// trait reference.
let trait_ref = tcx.impl_trait_ref(tcx.map.local_def_id(impl_id)).unwrap();
Expand Down Expand Up @@ -1479,17 +1479,14 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,
tcx.prohibit_type_params(base_segments);
tcx.mk_param(space, index, name)
}
Def::SelfTy(_, Some((_, self_ty_id))) => {
Def::SelfTy(_, Some(impl_id)) => {
// Self in impl (we know the concrete type).
tcx.prohibit_type_params(base_segments);
if let Some(&ty) = tcx.ast_ty_to_ty_cache.borrow().get(&self_ty_id) {
if let Some(free_substs) = this.get_free_substs() {
ty.subst(tcx, free_substs)
} else {
ty
}
let ty = tcx.node_id_to_type(impl_id);
if let Some(free_substs) = this.get_free_substs() {
ty.subst(tcx, free_substs)
} else {
span_bug!(span, "self type has not been fully resolved")
ty
}
}
Def::SelfTy(Some(_), None) => {
Expand Down Expand Up @@ -1585,12 +1582,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,

let tcx = this.tcx();

if let Some(&ty) = tcx.ast_ty_to_ty_cache.borrow().get(&ast_ty.id) {
debug!("ast_ty_to_ty: id={:?} ty={:?} (cached)", ast_ty.id, ty);
return ty;
}

let typ = match ast_ty.node {
match ast_ty.node {
hir::TyVec(ref ty) => {
tcx.mk_slice(ast_ty_to_ty(this, rscope, &ty))
}
Expand Down Expand Up @@ -1714,11 +1706,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,
// handled specially and will not descend into this routine.
this.ty_infer(None, None, None, ast_ty.span)
}
};

debug!("ast_ty_to_ty: id={:?} ty={:?}", ast_ty.id, typ);
tcx.ast_ty_to_ty_cache.borrow_mut().insert(ast_ty.id, typ);
return typ;
}
}

pub fn ty_of_arg<'tcx>(this: &AstConv<'tcx, 'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -2696,7 +2696,7 @@ fn register_def(cx: &DocContext, def: Def) -> DefId {
Def::Static(i, _) => (i, TypeStatic),
Def::Variant(i, _) => (i, TypeEnum),
Def::SelfTy(Some(def_id), _) => (def_id, TypeTrait),
Def::SelfTy(_, Some((impl_id, _))) => return cx.map.local_def_id(impl_id),
Def::SelfTy(_, Some(impl_id)) => return cx.map.local_def_id(impl_id),
_ => return def.def_id()
};
if did.is_local() { return did }
Expand Down

0 comments on commit 3a30136

Please sign in to comment.