Skip to content

Commit

Permalink
rustc_typeck: move the leaves (generics, trait_def, adt_def) to on-de…
Browse files Browse the repository at this point in the history
…mand.
  • Loading branch information
eddyb committed Feb 25, 2017
1 parent 3146ee8 commit 9c3c306
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 335 deletions.
11 changes: 1 addition & 10 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,16 +750,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
TyInfer(infer_ty) => write!(f, "{}", infer_ty),
TyError => write!(f, "[type error]"),
TyParam(ref param_ty) => write!(f, "{}", param_ty),
TyAdt(def, substs) => {
ty::tls::with(|tcx| {
if def.did.is_local() &&
!tcx.maps.ty.borrow().contains_key(&def.did) {
write!(f, "{}<..>", tcx.item_path_str(def.did))
} else {
parameterized(f, substs, def.did, &[])
}
})
}
TyAdt(def, substs) => parameterized(f, substs, def.did, &[]),
TyDynamic(data, r) => {
write!(f, "{}", data)?;
let r = r.to_string();
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,

let mut local_providers = ty::maps::Providers::default();
mir::mir_map::provide(&mut local_providers);
typeck::provide(&mut local_providers);

let mut extern_providers = ty::maps::Providers::default();
cstore::provide(&mut extern_providers);
Expand Down
15 changes: 4 additions & 11 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ pub trait AstConv<'gcx, 'tcx> {
/// A cache used for the result of `ast_ty_to_ty_cache`
fn ast_ty_to_ty_cache(&self) -> &RefCell<NodeMap<Ty<'tcx>>>;

/// Returns the generic type and lifetime parameters for an item.
fn get_generics(&self, id: DefId) -> &'tcx ty::Generics;

/// Identify the type for an item, like a type alias, fn, or struct.
fn get_item_type(&self, span: Span, id: DefId) -> Ty<'tcx>;

/// Returns the `TraitDef` for a given trait. This allows you to
/// figure out the set of type parameters defined on the trait.
fn get_trait_def(&self, id: DefId) -> &'tcx ty::TraitDef;

/// Ensure that the super-predicates for the trait with the given
/// id are available and also for the transitive set of
/// super-predicates.
Expand Down Expand Up @@ -248,7 +241,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
// If the type is parameterized by this region, then replace this
// region with the current anon region binding (in other words,
// whatever & would get replaced with).
let decl_generics = self.get_generics(def_id);
let decl_generics = tcx.item_generics(def_id);
let expected_num_region_params = decl_generics.regions.len();
let supplied_num_region_params = lifetimes.len();
if expected_num_region_params != supplied_num_region_params {
Expand Down Expand Up @@ -485,7 +478,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
debug!("create_substs_for_ast_trait_ref(trait_segment={:?})",
trait_segment);

let trait_def = self.get_trait_def(trait_def_id);
let trait_def = self.tcx().lookup_trait_def(trait_def_id);

match trait_segment.parameters {
hir::AngleBracketedParameters(_) => {
Expand Down Expand Up @@ -1019,7 +1012,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let node_id = tcx.hir.as_local_node_id(did).unwrap();
let item_id = tcx.hir.get_parent_node(node_id);
let item_def_id = tcx.hir.local_def_id(item_id);
let generics = self.get_generics(item_def_id);
let generics = tcx.item_generics(item_def_id);
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id).index];
tcx.mk_param(index, tcx.hir.name(node_id))
}
Expand Down Expand Up @@ -1186,7 +1179,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
// Create the anonymized type.
if allow {
let def_id = tcx.hir.local_def_id(ast_ty.id);
self.get_generics(def_id);
tcx.item_generics(def_id);
let substs = Substs::identity_for_item(tcx, def_id);
let ty = tcx.mk_anon(tcx.hir.local_def_id(ast_ty.id), substs);

Expand Down
8 changes: 0 additions & 8 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,18 +1353,10 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
&self.ast_ty_to_ty_cache
}

fn get_generics(&self, id: DefId) -> &'tcx ty::Generics {
self.tcx().item_generics(id)
}

fn get_item_type(&self, _: Span, id: DefId) -> Ty<'tcx> {
self.tcx().item_type(id)
}

fn get_trait_def(&self, id: DefId) -> &'tcx ty::TraitDef {
self.tcx().lookup_trait_def(id)
}

fn ensure_super_predicates(&self, _: Span, _: DefId) {
// all super predicates are ensured during collect pass
}
Expand Down
Loading

0 comments on commit 9c3c306

Please sign in to comment.