]> git.lizzy.rs Git - rust.git/commitdiff
Initial work to remove typeck_tables call from check_unused
authorcjkenn <cam.j.kennedy@gmail.com>
Sun, 15 Oct 2017 21:50:40 +0000 (14:50 -0700)
committercjkenn <cam.j.kennedy@gmail.com>
Fri, 20 Oct 2017 06:22:04 +0000 (23:22 -0700)
src/librustc/ty/context.rs
src/librustc_typeck/check/method/mod.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/writeback.rs
src/librustc_typeck/check_unused.rs

index 24ba38cf147796449be3a2883fba992892a54fff..77889b7c10e86298d2d99774aaef6ff1d08e9a01 100644 (file)
@@ -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 @@ pub fn empty(local_id_root: Option<DefId>) -> 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 @@ fn hash_stable<W: StableHasherResult>(&self,
             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);
         })
index d4eda13c6cd402c8655bd58ac34875e713247d37..a0c93df80689c2c4b1e4482994df0b86da43cfd0 100644 (file)
@@ -163,7 +163,10 @@ pub fn lookup_method(&self,
         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 @@ pub fn resolve_ufcs(&self,
         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();
index 0ebccbc835fc1bd6972af5143eec67d84d6ccfd5..f6b4dd8470c0c3001212b1b7392105829ee0f700 100644 (file)
 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,
index b3648d357e51580127e0922e590a88fe235634cb..b6f2551da207775571e989796424a5090459dc2a 100644 (file)
@@ -23,6 +23,8 @@
 use syntax::ast;
 use syntax_pos::Span;
 use std::mem;
+use std::rc::Rc;
+use std::cell::RefCell;
 
 ///////////////////////////////////////////////////////////////////////////
 // Entry point
@@ -49,7 +51,7 @@ pub fn resolve_type_vars_in_body(&self, body: &'gcx hir::Body)
         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;
 
index 0c35b5e6834deb2a87b62dd5b2e1074d9b9e8d94..cd2bd8499cf3878359594c484165339da86043c0 100644 (file)
@@ -19,6 +19,8 @@
 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 };