Skip to content

Commit 1f54df1

Browse files
Encapsulate sub-table access in TypeckTables and validate keys on each access.
1 parent bdfd78d commit 1f54df1

File tree

31 files changed

+463
-316
lines changed

31 files changed

+463
-316
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
//! This module contains `HashStable` implementations for various data types
1212
//! from rustc::ty in no particular order.
1313
14-
use hir::def_id::DefId;
15-
use ich::{self, StableHashingContext, NodeIdHashingMode};
14+
use ich::StableHashingContext;
1615
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
1716
StableHasherResult};
1817
use std::hash as std_hash;
@@ -612,71 +611,6 @@ impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> {
612611
ty
613612
});
614613

615-
616-
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
617-
for ty::TypeckTables<'gcx> {
618-
fn hash_stable<W: StableHasherResult>(&self,
619-
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
620-
hasher: &mut StableHasher<W>) {
621-
let ty::TypeckTables {
622-
local_id_root,
623-
ref type_dependent_defs,
624-
ref node_types,
625-
ref node_substs,
626-
ref adjustments,
627-
ref pat_binding_modes,
628-
ref upvar_capture_map,
629-
ref closure_tys,
630-
ref closure_kinds,
631-
ref liberated_fn_sigs,
632-
ref fru_field_types,
633-
634-
ref cast_kinds,
635-
636-
ref used_trait_imports,
637-
tainted_by_errors,
638-
ref free_region_map,
639-
} = *self;
640-
641-
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
642-
ich::hash_stable_itemlocalmap(hcx, hasher, type_dependent_defs);
643-
ich::hash_stable_itemlocalmap(hcx, hasher, node_types);
644-
ich::hash_stable_itemlocalmap(hcx, hasher, node_substs);
645-
ich::hash_stable_itemlocalmap(hcx, hasher, adjustments);
646-
ich::hash_stable_itemlocalmap(hcx, hasher, pat_binding_modes);
647-
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
648-
let ty::UpvarId {
649-
var_id,
650-
closure_expr_id
651-
} = *up_var_id;
652-
653-
let var_def_id = DefId {
654-
krate: local_id_root.krate,
655-
index: var_id,
656-
};
657-
let closure_def_id = DefId {
658-
krate: local_id_root.krate,
659-
index: closure_expr_id,
660-
};
661-
(hcx.def_path_hash(var_def_id), hcx.def_path_hash(closure_def_id))
662-
});
663-
664-
ich::hash_stable_itemlocalmap(hcx, hasher, closure_tys);
665-
ich::hash_stable_itemlocalmap(hcx, hasher, closure_kinds);
666-
ich::hash_stable_itemlocalmap(hcx, hasher, liberated_fn_sigs);
667-
ich::hash_stable_itemlocalmap(hcx, hasher, fru_field_types);
668-
ich::hash_stable_itemlocalmap(hcx, hasher, cast_kinds);
669-
670-
ich::hash_stable_hashset(hcx, hasher, used_trait_imports, |hcx, def_id| {
671-
hcx.def_path_hash(*def_id)
672-
});
673-
674-
tainted_by_errors.hash_stable(hcx, hasher);
675-
free_region_map.hash_stable(hcx, hasher);
676-
})
677-
}
678-
}
679-
680614
impl_stable_hash_for!(enum ty::fast_reject::SimplifiedType {
681615
BoolSimplifiedType,
682616
CharSimplifiedType,

src/librustc/infer/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,11 +1331,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13311331
{
13321332
if let Some(tables) = self.in_progress_tables {
13331333
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
1334-
let tables = tables.borrow();
13351334
let hir_id = self.tcx.hir.node_to_hir_id(id);
1336-
tables.validate_hir_id(hir_id);
1337-
return tables.closure_kinds
1338-
.get(&hir_id.local_id)
1335+
return tables.borrow()
1336+
.closure_kinds()
1337+
.get(hir_id)
13391338
.cloned()
13401339
.map(|(kind, _)| kind);
13411340
}
@@ -1355,10 +1354,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13551354
pub fn fn_sig(&self, def_id: DefId) -> ty::PolyFnSig<'tcx> {
13561355
if let Some(tables) = self.in_progress_tables {
13571356
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
1358-
let tables = tables.borrow();
13591357
let hir_id = self.tcx.hir.node_to_hir_id(id);
1360-
tables.validate_hir_id(hir_id);
1361-
if let Some(&ty) = tables.closure_tys.get(&hir_id.local_id) {
1358+
if let Some(&ty) = tables.borrow().closure_tys().get(hir_id) {
13621359
return ty;
13631360
}
13641361
}

src/librustc/middle/dead.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9494
}
9595
}
9696

97-
fn lookup_and_handle_method(&mut self, id: hir::ItemLocalId) {
98-
self.check_def_id(self.tables.type_dependent_defs[&id].def_id());
97+
fn lookup_and_handle_method(&mut self, id: hir::HirId) {
98+
self.check_def_id(self.tables.type_dependent_defs()[id].def_id());
9999
}
100100

101101
fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {
@@ -241,7 +241,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
241241
self.handle_definition(def);
242242
}
243243
hir::ExprMethodCall(..) => {
244-
self.lookup_and_handle_method(expr.hir_id.local_id);
244+
self.lookup_and_handle_method(expr.hir_id);
245245
}
246246
hir::ExprField(ref lhs, ref name) => {
247247
self.handle_field_access(&lhs, name.node);

src/librustc/middle/effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
166166
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
167167
match expr.node {
168168
hir::ExprMethodCall(..) => {
169-
let def_id = self.tables.type_dependent_defs[&expr.hir_id.local_id].def_id();
169+
let def_id = self.tables.type_dependent_defs()[expr.hir_id].def_id();
170170
let sig = self.tcx.fn_sig(def_id);
171171
debug!("effect: method call case, signature is {:?}",
172172
sig);

src/librustc/middle/expr_use_visitor.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
537537
}
538538
ty::TyError => { }
539539
_ => {
540-
let def_id = self.mc.tables.type_dependent_defs[&call.hir_id.local_id].def_id();
540+
let def_id = self.mc.tables.type_dependent_defs()[call.hir_id].def_id();
541541
match OverloadedCallType::from_method_id(self.tcx(), def_id) {
542542
FnMutOverloadedCall => {
543543
let call_scope_r = self.tcx().node_scope_region(call.id);
@@ -797,8 +797,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
797797
pat);
798798
return_if_err!(self.mc.cat_pattern(cmt_discr, pat, |cmt_pat, pat| {
799799
if let PatKind::Binding(..) = pat.node {
800-
self.mc.tables.validate_hir_id(pat.hir_id);
801-
let bm = *self.mc.tables.pat_binding_modes.get(&pat.hir_id.local_id)
800+
let bm = *self.mc.tables.pat_binding_modes().get(pat.hir_id)
802801
.expect("missing binding mode");
803802
match bm {
804803
ty::BindByReference(..) =>
@@ -824,8 +823,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
824823
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |cmt_pat, pat| {
825824
if let PatKind::Binding(_, def_id, ..) = pat.node {
826825
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}", cmt_pat, pat, match_mode);
827-
mc.tables.validate_hir_id(pat.hir_id);
828-
let bm = *mc.tables.pat_binding_modes.get(&pat.hir_id.local_id)
826+
let bm = *mc.tables.pat_binding_modes().get(pat.hir_id)
829827
.expect("missing binding mode");
830828

831829
// pat_ty: the type of the binding being produced.

src/librustc/middle/mem_categorization.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,8 @@ impl MutabilityCategory {
334334
let ret = match tcx.hir.get(id) {
335335
hir_map::NodeLocal(p) => match p.node {
336336
PatKind::Binding(..) => {
337-
338-
tables.validate_hir_id(p.hir_id);
339-
let bm = *tables.pat_binding_modes
340-
.get(&p.hir_id.local_id)
337+
let bm = *tables.pat_binding_modes()
338+
.get(p.hir_id)
341339
.expect("missing binding mode");
342340
if bm == ty::BindByValue(hir::MutMutable) {
343341
McDeclared
@@ -485,10 +483,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
485483
// fundamental fix to this conflated use of the node id.
486484
let ret_ty = match pat.node {
487485
PatKind::Binding(..) => {
488-
self.tables.validate_hir_id(pat.hir_id);
489486
let bm = *self.tables
490-
.pat_binding_modes
491-
.get(&pat.hir_id.local_id)
487+
.pat_binding_modes()
488+
.get(pat.hir_id)
492489
.expect("missing binding mode");
493490

494491
if let ty::BindByReference(_) = bm {
@@ -698,7 +695,6 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
698695
-> McResult<cmt<'tcx>>
699696
{
700697
let fn_hir_id = self.tcx.hir.node_to_hir_id(fn_node_id);
701-
self.tables.validate_hir_id(fn_hir_id);
702698

703699
// An upvar can have up to 3 components. We translate first to a
704700
// `Categorization::Upvar`, which is itself a fiction -- it represents the reference to the
@@ -723,7 +719,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
723719
// FnMut | copied -> &'env mut | upvar -> &'env mut -> &'up bk
724720
// FnOnce | copied | upvar -> &'up bk
725721

726-
let kind = match self.tables.closure_kinds.get(&fn_hir_id.local_id) {
722+
let kind = match self.tables.closure_kinds().get(fn_hir_id) {
727723
Some(&(kind, _)) => kind,
728724
None => span_bug!(span, "missing closure kind")
729725
};

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
110110
Some(self.tables.qpath_def(qpath, expr.hir_id))
111111
}
112112
hir::ExprMethodCall(..) => {
113-
Some(self.tables.type_dependent_defs[&expr.hir_id.local_id])
113+
Some(self.tables.type_dependent_defs()[expr.hir_id])
114114
}
115115
_ => None
116116
};

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
684684
if let Some(tables) = self.in_progress_tables {
685685
let tables = tables.borrow();
686686
let closure_hir_id = self.tcx.hir.node_to_hir_id(node_id);
687-
tables.validate_hir_id(closure_hir_id);
688-
match tables.closure_kinds.get(&closure_hir_id.local_id) {
687+
match tables.closure_kinds().get(closure_hir_id) {
689688
Some(&(ty::ClosureKind::FnOnce, Some((span, name)))) => {
690689
err.span_note(span, &format!(
691690
"closure is `FnOnce` because it moves the \

0 commit comments

Comments
 (0)