提交 9c3c3068 编写于 作者: E Eduard-Mihai Burtescu

rustc_typeck: move the leaves (generics, trait_def, adt_def) to on-demand.

上级 3146ee86
......@@ -750,16 +750,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
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();
......
......@@ -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);
......
......@@ -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.
......@@ -248,7 +241,7 @@ fn create_substs_for_ast_path(&self,
// 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 {
......@@ -485,7 +478,7 @@ fn create_substs_for_ast_trait_ref(&self,
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(_) => {
......@@ -1019,7 +1012,7 @@ pub fn def_to_ty(&self,
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))
}
......@@ -1186,7 +1179,7 @@ pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
// 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);
......
......@@ -1353,18 +1353,10 @@ fn ast_ty_to_ty_cache(&self) -> &RefCell<NodeMap<Ty<'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
}
......
此差异已折叠。
......@@ -110,6 +110,7 @@
use rustc::infer::InferOk;
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::traits::{ObligationCause, ObligationCauseCode, Reveal};
use session::config;
use util::common::time;
......@@ -284,6 +285,10 @@ fn check_for_entry_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
}
}
pub fn provide(providers: &mut Providers) {
collect::provide(providers);
}
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
-> Result<(), usize> {
let time_passes = tcx.sess.time_passes();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册