Skip to content

Commit 9c3c306

Browse files
committed
rustc_typeck: move the leaves (generics, trait_def, adt_def) to on-demand.
1 parent 3146ee8 commit 9c3c306

File tree

6 files changed

+288
-335
lines changed

6 files changed

+288
-335
lines changed

src/librustc/util/ppaux.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -750,16 +750,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
750750
TyInfer(infer_ty) => write!(f, "{}", infer_ty),
751751
TyError => write!(f, "[type error]"),
752752
TyParam(ref param_ty) => write!(f, "{}", param_ty),
753-
TyAdt(def, substs) => {
754-
ty::tls::with(|tcx| {
755-
if def.did.is_local() &&
756-
!tcx.maps.ty.borrow().contains_key(&def.did) {
757-
write!(f, "{}<..>", tcx.item_path_str(def.did))
758-
} else {
759-
parameterized(f, substs, def.did, &[])
760-
}
761-
})
762-
}
753+
TyAdt(def, substs) => parameterized(f, substs, def.did, &[]),
763754
TyDynamic(data, r) => {
764755
write!(f, "{}", data)?;
765756
let r = r.to_string();

src/librustc_driver/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
873873

874874
let mut local_providers = ty::maps::Providers::default();
875875
mir::mir_map::provide(&mut local_providers);
876+
typeck::provide(&mut local_providers);
876877

877878
let mut extern_providers = ty::maps::Providers::default();
878879
cstore::provide(&mut extern_providers);

src/librustc_typeck/astconv.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,9 @@ pub trait AstConv<'gcx, 'tcx> {
5151
/// A cache used for the result of `ast_ty_to_ty_cache`
5252
fn ast_ty_to_ty_cache(&self) -> &RefCell<NodeMap<Ty<'tcx>>>;
5353

54-
/// Returns the generic type and lifetime parameters for an item.
55-
fn get_generics(&self, id: DefId) -> &'tcx ty::Generics;
56-
5754
/// Identify the type for an item, like a type alias, fn, or struct.
5855
fn get_item_type(&self, span: Span, id: DefId) -> Ty<'tcx>;
5956

60-
/// Returns the `TraitDef` for a given trait. This allows you to
61-
/// figure out the set of type parameters defined on the trait.
62-
fn get_trait_def(&self, id: DefId) -> &'tcx ty::TraitDef;
63-
6457
/// Ensure that the super-predicates for the trait with the given
6558
/// id are available and also for the transitive set of
6659
/// super-predicates.
@@ -248,7 +241,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
248241
// If the type is parameterized by this region, then replace this
249242
// region with the current anon region binding (in other words,
250243
// whatever & would get replaced with).
251-
let decl_generics = self.get_generics(def_id);
244+
let decl_generics = tcx.item_generics(def_id);
252245
let expected_num_region_params = decl_generics.regions.len();
253246
let supplied_num_region_params = lifetimes.len();
254247
if expected_num_region_params != supplied_num_region_params {
@@ -485,7 +478,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
485478
debug!("create_substs_for_ast_trait_ref(trait_segment={:?})",
486479
trait_segment);
487480

488-
let trait_def = self.get_trait_def(trait_def_id);
481+
let trait_def = self.tcx().lookup_trait_def(trait_def_id);
489482

490483
match trait_segment.parameters {
491484
hir::AngleBracketedParameters(_) => {
@@ -1019,7 +1012,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
10191012
let node_id = tcx.hir.as_local_node_id(did).unwrap();
10201013
let item_id = tcx.hir.get_parent_node(node_id);
10211014
let item_def_id = tcx.hir.local_def_id(item_id);
1022-
let generics = self.get_generics(item_def_id);
1015+
let generics = tcx.item_generics(item_def_id);
10231016
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id).index];
10241017
tcx.mk_param(index, tcx.hir.name(node_id))
10251018
}
@@ -1186,7 +1179,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11861179
// Create the anonymized type.
11871180
if allow {
11881181
let def_id = tcx.hir.local_def_id(ast_ty.id);
1189-
self.get_generics(def_id);
1182+
tcx.item_generics(def_id);
11901183
let substs = Substs::identity_for_item(tcx, def_id);
11911184
let ty = tcx.mk_anon(tcx.hir.local_def_id(ast_ty.id), substs);
11921185

src/librustc_typeck/check/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1353,18 +1353,10 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
13531353
&self.ast_ty_to_ty_cache
13541354
}
13551355

1356-
fn get_generics(&self, id: DefId) -> &'tcx ty::Generics {
1357-
self.tcx().item_generics(id)
1358-
}
1359-
13601356
fn get_item_type(&self, _: Span, id: DefId) -> Ty<'tcx> {
13611357
self.tcx().item_type(id)
13621358
}
13631359

1364-
fn get_trait_def(&self, id: DefId) -> &'tcx ty::TraitDef {
1365-
self.tcx().lookup_trait_def(id)
1366-
}
1367-
13681360
fn ensure_super_predicates(&self, _: Span, _: DefId) {
13691361
// all super predicates are ensured during collect pass
13701362
}

0 commit comments

Comments
 (0)