typeck: merge CollectCtxt and collect::CollectCtxt.
This commit is contained in:
parent
8600a67782
commit
e387e6c7c8
@ -79,11 +79,10 @@ use rustc::dep_graph::DepNode;
|
||||
use rustc::hir::map as hir_map;
|
||||
use util::common::{ErrorReported, MemoizationMap};
|
||||
use util::nodemap::FnvHashMap;
|
||||
use write_ty_to_tcx;
|
||||
use {CrateCtxt, write_ty_to_tcx};
|
||||
|
||||
use rustc_const_math::ConstInt;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashSet;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::rc::Rc;
|
||||
@ -101,22 +100,13 @@ use rustc::hir::print as pprust;
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Main entry point
|
||||
|
||||
pub fn collect_item_types(tcx: &TyCtxt) {
|
||||
let ccx = &CrateCtxt { tcx: tcx, stack: RefCell::new(Vec::new()) };
|
||||
let mut visitor = CollectItemTypesVisitor{ ccx: ccx };
|
||||
pub fn collect_item_types(ccx: &CrateCtxt) {
|
||||
let mut visitor = CollectItemTypesVisitor { ccx: ccx };
|
||||
ccx.tcx.visit_all_items_in_krate(DepNode::CollectItem, &mut visitor);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct CrateCtxt<'a,'tcx:'a> {
|
||||
tcx: &'a TyCtxt<'tcx>,
|
||||
|
||||
// This stack is used to identify cycles in the user's source.
|
||||
// Note that these cycles can cross multiple items.
|
||||
stack: RefCell<Vec<AstConvRequest>>,
|
||||
}
|
||||
|
||||
/// Context specific to some particular item. This is what implements
|
||||
/// AstConv. It has information about the predicates that are defined
|
||||
/// on the trait. Unfortunately, this predicate information is
|
||||
@ -134,7 +124,7 @@ struct ItemCtxt<'a,'tcx:'a> {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
enum AstConvRequest {
|
||||
pub enum AstConvRequest {
|
||||
GetItemTypeScheme(DefId),
|
||||
GetTraitDef(DefId),
|
||||
EnsureSuperPredicates(DefId),
|
||||
|
@ -138,11 +138,17 @@ pub struct TypeAndSubsts<'tcx> {
|
||||
pub struct CrateCtxt<'a, 'tcx: 'a> {
|
||||
// A mapping from method call sites to traits that have that method.
|
||||
pub trait_map: hir::TraitMap,
|
||||
|
||||
/// A vector of every trait accessible in the whole crate
|
||||
/// (i.e. including those from subcrates). This is used only for
|
||||
/// error reporting, and so is lazily initialised and generally
|
||||
/// shouldn't taint the common path (hence the RefCell).
|
||||
pub all_traits: RefCell<Option<check::method::AllTraitsVec>>,
|
||||
|
||||
/// This stack is used to identify cycles in the user's source.
|
||||
/// Note that these cycles can cross multiple items.
|
||||
pub stack: RefCell<Vec<collect::AstConvRequest>>,
|
||||
|
||||
pub tcx: &'a TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
@ -337,6 +343,7 @@ pub fn check_crate(tcx: &TyCtxt, trait_map: hir::TraitMap) -> CompileResult {
|
||||
let ccx = CrateCtxt {
|
||||
trait_map: trait_map,
|
||||
all_traits: RefCell::new(None),
|
||||
stack: RefCell::new(Vec::new()),
|
||||
tcx: tcx
|
||||
};
|
||||
|
||||
@ -344,7 +351,7 @@ pub fn check_crate(tcx: &TyCtxt, trait_map: hir::TraitMap) -> CompileResult {
|
||||
// have valid types and not error
|
||||
tcx.sess.track_errors(|| {
|
||||
time(time_passes, "type collecting", ||
|
||||
collect::collect_item_types(tcx));
|
||||
collect::collect_item_types(&ccx));
|
||||
|
||||
})?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user