Skip to content

Commit ada8099

Browse files
committed
Initial work to remove typeck_tables call from check_unused
1 parent f6d7514 commit ada8099

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

src/librustc/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub struct TypeckTables<'tcx> {
388388

389389
/// Set of trait imports actually used in the method resolution.
390390
/// This is used for warning unused imports.
391-
pub used_trait_imports: DefIdSet,
391+
pub used_trait_imports: Rc<RefCell<DefIdSet>>,
392392

393393
/// If any errors occurred while type-checking this body,
394394
/// this field will be set to `true`.
@@ -418,7 +418,7 @@ impl<'tcx> TypeckTables<'tcx> {
418418
liberated_fn_sigs: ItemLocalMap(),
419419
fru_field_types: ItemLocalMap(),
420420
cast_kinds: ItemLocalMap(),
421-
used_trait_imports: DefIdSet(),
421+
used_trait_imports: Rc::new(RefCell::new(DefIdSet())),
422422
tainted_by_errors: false,
423423
free_region_map: FreeRegionMap::new(),
424424
}
@@ -782,7 +782,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for TypeckTables<'gcx> {
782782
cast_kinds.hash_stable(hcx, hasher);
783783
generator_sigs.hash_stable(hcx, hasher);
784784
generator_interiors.hash_stable(hcx, hasher);
785-
used_trait_imports.hash_stable(hcx, hasher);
785+
used_trait_imports.borrow_mut().hash_stable(hcx, hasher);
786786
tainted_by_errors.hash_stable(hcx, hasher);
787787
free_region_map.hash_stable(hcx, hasher);
788788
})

src/librustc_typeck/check/method/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
163163
if let Some(import_id) = pick.import_id {
164164
let import_def_id = self.tcx.hir.local_def_id(import_id);
165165
debug!("used_trait_import: {:?}", import_def_id);
166-
self.tables.borrow_mut().used_trait_imports.insert(import_def_id);
166+
167+
let tables = self.tables.borrow_mut();
168+
let mut ut = tables.used_trait_imports.borrow_mut();
169+
ut.insert(import_def_id);
167170
}
168171

169172
self.tcx.check_stability(pick.item.def_id, call_expr.id, span);
@@ -361,7 +364,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
361364
if let Some(import_id) = pick.import_id {
362365
let import_def_id = self.tcx.hir.local_def_id(import_id);
363366
debug!("used_trait_import: {:?}", import_def_id);
364-
self.tables.borrow_mut().used_trait_imports.insert(import_def_id);
367+
let tables = self.tables.borrow_mut();
368+
let mut ut = tables.used_trait_imports.borrow_mut();
369+
ut.insert(import_def_id);
365370
}
366371

367372
let def = pick.item.def();

src/librustc_typeck/check/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ use session::{CompileIncomplete, Session};
106106
use TypeAndSubsts;
107107
use lint;
108108
use util::common::{ErrorReported, indenter};
109-
use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
109+
use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, NodeMap};
110110

111111
use std::cell::{Cell, RefCell, Ref, RefMut};
112+
use std::rc::Rc;
112113
use std::collections::hash_map::Entry;
113114
use std::cmp;
114115
use std::fmt::Display;
@@ -921,6 +922,12 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
921922
tables
922923
}
923924

925+
pub fn get_used_trait_imports<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
926+
def_id: DefId)
927+
-> Rc<RefCell<DefIdSet>> {
928+
Rc::clone(&tcx.typeck_tables_of(def_id).used_trait_imports)
929+
}
930+
924931
fn check_abi<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, abi: Abi) {
925932
if !tcx.sess.target.target.is_abi_supported(abi) {
926933
struct_span_err!(tcx.sess, span, E0570,

src/librustc_typeck/check/writeback.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use rustc::util::nodemap::DefIdSet;
2323
use syntax::ast;
2424
use syntax_pos::Span;
2525
use std::mem;
26+
use std::rc::Rc;
27+
use std::cell::RefCell;
2628

2729
///////////////////////////////////////////////////////////////////////////
2830
// Entry point
@@ -49,7 +51,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4951
wbcx.visit_generator_interiors();
5052

5153
let used_trait_imports = mem::replace(&mut self.tables.borrow_mut().used_trait_imports,
52-
DefIdSet());
54+
Rc::new(RefCell::new(DefIdSet())));
5355
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
5456
wbcx.tables.used_trait_imports = used_trait_imports;
5557

src/librustc_typeck/check_unused.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
1919
use rustc::hir;
2020
use rustc::util::nodemap::DefIdSet;
2121

22+
use check::get_used_trait_imports;
23+
2224
struct CheckVisitor<'a, 'tcx: 'a> {
2325
tcx: TyCtxt<'a, 'tcx, 'tcx>,
2426
used_trait_imports: DefIdSet,
@@ -66,10 +68,9 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
6668
let mut used_trait_imports = DefIdSet();
6769
for &body_id in tcx.hir.krate().bodies.keys() {
6870
let item_def_id = tcx.hir.body_owner_def_id(body_id);
69-
let tables = tcx.typeck_tables_of(item_def_id);
70-
let imports = &tables.used_trait_imports;
71+
let imports = get_used_trait_imports(tcx, item_def_id);
7172
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
72-
used_trait_imports.extend(imports);
73+
used_trait_imports.extend(imports.borrow().iter());
7374
}
7475

7576
let mut visitor = CheckVisitor { tcx, used_trait_imports };

0 commit comments

Comments
 (0)