Skip to content

Commit 3a30136

Browse files
committed
rustc: Remove the unnecessary ast_ty_to_ty_cache.
1 parent 2065216 commit 3a30136

File tree

7 files changed

+15
-39
lines changed

7 files changed

+15
-39
lines changed

src/librustc/hir/def.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use hir;
1717
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1818
pub enum Def {
1919
Fn(DefId),
20-
SelfTy(Option<DefId>, // trait id
21-
Option<(ast::NodeId, ast::NodeId)>), // (impl id, self type id)
20+
SelfTy(Option<DefId> /* trait */, Option<ast::NodeId> /* impl */),
2221
Mod(DefId),
2322
ForeignMod(DefId),
2423
Static(DefId, bool /* is_mutbl */),

src/librustc/ty/context.rs

-6
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,6 @@ pub struct GlobalCtxt<'tcx> {
356356
// Cache for the type-contents routine. FIXME -- track deps?
357357
pub tc_cache: RefCell<FnvHashMap<Ty<'tcx>, ty::contents::TypeContents>>,
358358

359-
// Cache for various types within a method body and so forth.
360-
//
361-
// FIXME this should be made local to typeck, but it is currently used by one lint
362-
pub ast_ty_to_ty_cache: RefCell<NodeMap<Ty<'tcx>>>,
363-
364359
// FIXME no dep tracking, but we should be able to remove this
365360
pub ty_param_defs: RefCell<NodeMap<ty::TypeParameterDef<'tcx>>>,
366361

@@ -664,7 +659,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
664659
tcache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
665660
rcache: RefCell::new(FnvHashMap()),
666661
tc_cache: RefCell::new(FnvHashMap()),
667-
ast_ty_to_ty_cache: RefCell::new(NodeMap()),
668662
impl_or_trait_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
669663
trait_item_def_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
670664
trait_items_cache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),

src/librustc/ty/sty.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ pub enum TypeVariants<'tcx> {
9393
/// Substs here, possibly against intuition, *may* contain `TyParam`s.
9494
/// That is, even after substitution it is possible that there are type
9595
/// variables. This happens when the `TyEnum` corresponds to an enum
96-
/// definition and not a concrete use of it. To get the correct `TyEnum`
97-
/// from the tcx, use the `NodeId` from the `ast::Ty` and look it up in
98-
/// the `ast_ty_to_ty_cache`. This is probably true for `TyStruct` as
99-
/// well.
96+
/// definition and not a concrete use of it. This is true for `TyStruct`
97+
/// as well.
10098
TyEnum(AdtDef<'tcx>, &'tcx Substs<'tcx>),
10199

102100
/// A structure type, defined with `struct`.

src/librustc_metadata/astencode.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,8 @@ impl tr for Def {
362362
match *self {
363363
Def::Fn(did) => Def::Fn(did.tr(dcx)),
364364
Def::Method(did) => Def::Method(did.tr(dcx)),
365-
Def::SelfTy(opt_did, impl_ids) => { Def::SelfTy(opt_did.map(|did| did.tr(dcx)),
366-
impl_ids.map(|(nid1, nid2)| {
367-
(dcx.tr_id(nid1),
368-
dcx.tr_id(nid2))
369-
})) }
365+
Def::SelfTy(opt_did, impl_id) => { Def::SelfTy(opt_did.map(|did| did.tr(dcx)),
366+
impl_id.map(|id| dcx.tr_id(id))) }
370367
Def::Mod(did) => { Def::Mod(did.tr(dcx)) }
371368
Def::ForeignMod(did) => { Def::ForeignMod(did.tr(dcx)) }
372369
Def::Static(did, m) => { Def::Static(did.tr(dcx), m) }

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ impl<'a> Resolver<'a> {
19381938
// Resolve the self type.
19391939
this.visit_ty(self_type);
19401940

1941-
this.with_self_rib(Def::SelfTy(trait_id, Some((item_id, self_type.id))), |this| {
1941+
this.with_self_rib(Def::SelfTy(trait_id, Some(item_id)), |this| {
19421942
this.with_current_self_type(self_type, |this| {
19431943
for impl_item in impl_items {
19441944
this.resolve_visibility(&impl_item.vis);

src/librustc_typeck/astconv.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,
12721272
// Find the type of the associated item, and the trait where the associated
12731273
// item is declared.
12741274
let bound = match (&ty.sty, ty_path_def) {
1275-
(_, Def::SelfTy(Some(trait_did), Some((impl_id, _)))) => {
1275+
(_, Def::SelfTy(Some(trait_did), Some(impl_id))) => {
12761276
// `Self` in an impl of a trait - we have a concrete self type and a
12771277
// trait reference.
12781278
let trait_ref = tcx.impl_trait_ref(tcx.map.local_def_id(impl_id)).unwrap();
@@ -1479,17 +1479,14 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,
14791479
tcx.prohibit_type_params(base_segments);
14801480
tcx.mk_param(space, index, name)
14811481
}
1482-
Def::SelfTy(_, Some((_, self_ty_id))) => {
1482+
Def::SelfTy(_, Some(impl_id)) => {
14831483
// Self in impl (we know the concrete type).
14841484
tcx.prohibit_type_params(base_segments);
1485-
if let Some(&ty) = tcx.ast_ty_to_ty_cache.borrow().get(&self_ty_id) {
1486-
if let Some(free_substs) = this.get_free_substs() {
1487-
ty.subst(tcx, free_substs)
1488-
} else {
1489-
ty
1490-
}
1485+
let ty = tcx.node_id_to_type(impl_id);
1486+
if let Some(free_substs) = this.get_free_substs() {
1487+
ty.subst(tcx, free_substs)
14911488
} else {
1492-
span_bug!(span, "self type has not been fully resolved")
1489+
ty
14931490
}
14941491
}
14951492
Def::SelfTy(Some(_), None) => {
@@ -1585,12 +1582,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,
15851582

15861583
let tcx = this.tcx();
15871584

1588-
if let Some(&ty) = tcx.ast_ty_to_ty_cache.borrow().get(&ast_ty.id) {
1589-
debug!("ast_ty_to_ty: id={:?} ty={:?} (cached)", ast_ty.id, ty);
1590-
return ty;
1591-
}
1592-
1593-
let typ = match ast_ty.node {
1585+
match ast_ty.node {
15941586
hir::TyVec(ref ty) => {
15951587
tcx.mk_slice(ast_ty_to_ty(this, rscope, &ty))
15961588
}
@@ -1714,11 +1706,7 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx, 'tcx>,
17141706
// handled specially and will not descend into this routine.
17151707
this.ty_infer(None, None, None, ast_ty.span)
17161708
}
1717-
};
1718-
1719-
debug!("ast_ty_to_ty: id={:?} ty={:?}", ast_ty.id, typ);
1720-
tcx.ast_ty_to_ty_cache.borrow_mut().insert(ast_ty.id, typ);
1721-
return typ;
1709+
}
17221710
}
17231711

17241712
pub fn ty_of_arg<'tcx>(this: &AstConv<'tcx, 'tcx>,

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2696,7 +2696,7 @@ fn register_def(cx: &DocContext, def: Def) -> DefId {
26962696
Def::Static(i, _) => (i, TypeStatic),
26972697
Def::Variant(i, _) => (i, TypeEnum),
26982698
Def::SelfTy(Some(def_id), _) => (def_id, TypeTrait),
2699-
Def::SelfTy(_, Some((impl_id, _))) => return cx.map.local_def_id(impl_id),
2699+
Def::SelfTy(_, Some(impl_id)) => return cx.map.local_def_id(impl_id),
27002700
_ => return def.def_id()
27012701
};
27022702
if did.is_local() { return did }

0 commit comments

Comments
 (0)