about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorcjkenn <cam.j.kennedy@gmail.com>2017-10-15 14:50:40 -0700
committercjkenn <cam.j.kennedy@gmail.com>2017-10-19 23:22:04 -0700
commitada809917dc4b6f7a48fb60df06c3753bc8a74f3 (patch)
tree7cf4a05fbb288edb97cbd85f9f1463668fc5d11b /src
parentf6d7514545cbe83e771a400d04049b96dfb210cd (diff)
downloadrust-ada809917dc4b6f7a48fb60df06c3753bc8a74f3.tar.gz
rust-ada809917dc4b6f7a48fb60df06c3753bc8a74f3.zip
Initial work to remove typeck_tables call from check_unused
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/context.rs6
-rw-r--r--src/librustc_typeck/check/method/mod.rs9
-rw-r--r--src/librustc_typeck/check/mod.rs9
-rw-r--r--src/librustc_typeck/check/writeback.rs4
-rw-r--r--src/librustc_typeck/check_unused.rs7
5 files changed, 25 insertions, 10 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 24ba38cf147..77889b7c10e 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -388,7 +388,7 @@ pub struct TypeckTables<'tcx> {
 
     /// Set of trait imports actually used in the method resolution.
     /// This is used for warning unused imports.
-    pub used_trait_imports: DefIdSet,
+    pub used_trait_imports: Rc<RefCell<DefIdSet>>,
 
     /// If any errors occurred while type-checking this body,
     /// this field will be set to `true`.
@@ -418,7 +418,7 @@ impl<'tcx> TypeckTables<'tcx> {
             liberated_fn_sigs: ItemLocalMap(),
             fru_field_types: ItemLocalMap(),
             cast_kinds: ItemLocalMap(),
-            used_trait_imports: DefIdSet(),
+            used_trait_imports: Rc::new(RefCell::new(DefIdSet())),
             tainted_by_errors: false,
             free_region_map: FreeRegionMap::new(),
         }
@@ -782,7 +782,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
             cast_kinds.hash_stable(hcx, hasher);
             generator_sigs.hash_stable(hcx, hasher);
             generator_interiors.hash_stable(hcx, hasher);
-            used_trait_imports.hash_stable(hcx, hasher);
+            used_trait_imports.borrow_mut().hash_stable(hcx, hasher);
             tainted_by_errors.hash_stable(hcx, hasher);
             free_region_map.hash_stable(hcx, hasher);
         })
diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs
index d4eda13c6cd..a0c93df8068 100644
--- a/src/librustc_typeck/check/method/mod.rs
+++ b/src/librustc_typeck/check/method/mod.rs
@@ -163,7 +163,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
         if let Some(import_id) = pick.import_id {
             let import_def_id = self.tcx.hir.local_def_id(import_id);
             debug!("used_trait_import: {:?}", import_def_id);
-            self.tables.borrow_mut().used_trait_imports.insert(import_def_id);
+
+            let tables = self.tables.borrow_mut();
+            let mut ut = tables.used_trait_imports.borrow_mut();
+            ut.insert(import_def_id);
         }
 
         self.tcx.check_stability(pick.item.def_id, call_expr.id, span);
@@ -361,7 +364,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
         if let Some(import_id) = pick.import_id {
             let import_def_id = self.tcx.hir.local_def_id(import_id);
             debug!("used_trait_import: {:?}", import_def_id);
-            self.tables.borrow_mut().used_trait_imports.insert(import_def_id);
+            let tables = self.tables.borrow_mut();
+            let mut ut = tables.used_trait_imports.borrow_mut();
+            ut.insert(import_def_id);
         }
 
         let def = pick.item.def();
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 0ebccbc835f..f6b4dd8470c 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -106,9 +106,10 @@ use session::{CompileIncomplete, Session};
 use TypeAndSubsts;
 use lint;
 use util::common::{ErrorReported, indenter};
-use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
+use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, NodeMap};
 
 use std::cell::{Cell, RefCell, Ref, RefMut};
+use std::rc::Rc;
 use std::collections::hash_map::Entry;
 use std::cmp;
 use std::fmt::Display;
@@ -921,6 +922,12 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     tables
 }
 
+pub fn get_used_trait_imports<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                                        def_id: DefId)
+                                        -> Rc<RefCell<DefIdSet>> {
+    Rc::clone(&tcx.typeck_tables_of(def_id).used_trait_imports)
+}
+
 fn check_abi<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, abi: Abi) {
     if !tcx.sess.target.target.is_abi_supported(abi) {
         struct_span_err!(tcx.sess, span, E0570,
diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs
index b3648d357e5..b6f2551da20 100644
--- a/src/librustc_typeck/check/writeback.rs
+++ b/src/librustc_typeck/check/writeback.rs
@@ -23,6 +23,8 @@ use rustc::util::nodemap::DefIdSet;
 use syntax::ast;
 use syntax_pos::Span;
 use std::mem;
+use std::rc::Rc;
+use std::cell::RefCell;
 
 ///////////////////////////////////////////////////////////////////////////
 // Entry point
@@ -49,7 +51,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
         wbcx.visit_generator_interiors();
 
         let used_trait_imports = mem::replace(&mut self.tables.borrow_mut().used_trait_imports,
-                                              DefIdSet());
+                                              Rc::new(RefCell::new(DefIdSet())));
         debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
         wbcx.tables.used_trait_imports = used_trait_imports;
 
diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs
index 0c35b5e6834..cd2bd8499cf 100644
--- a/src/librustc_typeck/check_unused.rs
+++ b/src/librustc_typeck/check_unused.rs
@@ -19,6 +19,8 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
 use rustc::hir;
 use rustc::util::nodemap::DefIdSet;
 
+use check::get_used_trait_imports;
+
 struct CheckVisitor<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     used_trait_imports: DefIdSet,
@@ -66,10 +68,9 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
     let mut used_trait_imports = DefIdSet();
     for &body_id in tcx.hir.krate().bodies.keys() {
         let item_def_id = tcx.hir.body_owner_def_id(body_id);
-        let tables = tcx.typeck_tables_of(item_def_id);
-        let imports = &tables.used_trait_imports;
+        let imports = get_used_trait_imports(tcx, item_def_id);
         debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
-        used_trait_imports.extend(imports);
+        used_trait_imports.extend(imports.borrow().iter());
     }
 
     let mut visitor = CheckVisitor { tcx, used_trait_imports };