From e387e6c7c82bed6a32631a04bc66f3957384faa8 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Fri, 11 Mar 2016 16:29:12 +0200 Subject: [PATCH] typeck: merge CollectCtxt and collect::CollectCtxt. --- src/librustc_typeck/collect.rs | 18 ++++-------------- src/librustc_typeck/lib.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 19807ab840b..787324897a3 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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>, -} - /// 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), diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 7e298c63ccc..c65b12b1829 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -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>, + + /// This stack is used to identify cycles in the user's source. + /// Note that these cycles can cross multiple items. + pub stack: RefCell>, + 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)); })?;