Skip to content

Commit 783ccc4

Browse files
Make TypeckTables::type_dependent_defs use ItemLocalId instead of NodeId.
1 parent 9868352 commit 783ccc4

File tree

31 files changed

+386
-151
lines changed

31 files changed

+386
-151
lines changed

src/librustc/hir/def_id.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,11 @@ impl DefId {
201201
pub fn is_local(&self) -> bool {
202202
self.krate == LOCAL_CRATE
203203
}
204+
205+
pub fn invalid() -> DefId {
206+
DefId {
207+
krate: INVALID_CRATE,
208+
index: CRATE_DEF_INDEX,
209+
}
210+
}
204211
}

src/librustc/hir/lowering.rs

Lines changed: 113 additions & 62 deletions
Large diffs are not rendered by default.

src/librustc/hir/map/definitions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ impl Definitions {
465465
self.node_to_hir_id[node_id]
466466
}
467467

468+
pub fn find_node_for_hir_id(&self, hir_id: hir::HirId) -> ast::NodeId {
469+
self.node_to_hir_id.binary_search(&hir_id).unwrap()
470+
}
471+
468472
/// Add a definition with a parent definition.
469473
pub fn create_root_def(&mut self,
470474
crate_name: &str,

src/librustc/hir/map/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'hir> Map<'hir> {
357357
}
358358
}
359359

360+
#[inline]
360361
pub fn definitions(&self) -> &Definitions {
361362
&self.definitions
362363
}
@@ -377,21 +378,29 @@ impl<'hir> Map<'hir> {
377378
self.definitions.def_path(def_id.index)
378379
}
379380

381+
#[inline]
380382
pub fn local_def_id(&self, node: NodeId) -> DefId {
381383
self.opt_local_def_id(node).unwrap_or_else(|| {
382384
bug!("local_def_id: no entry for `{}`, which has a map of `{:?}`",
383385
node, self.find_entry(node))
384386
})
385387
}
386388

389+
#[inline]
387390
pub fn opt_local_def_id(&self, node: NodeId) -> Option<DefId> {
388391
self.definitions.opt_local_def_id(node)
389392
}
390393

394+
#[inline]
391395
pub fn as_local_node_id(&self, def_id: DefId) -> Option<NodeId> {
392396
self.definitions.as_local_node_id(def_id)
393397
}
394398

399+
#[inline]
400+
pub fn node_to_hir_id(&self, node_id: NodeId) -> HirId {
401+
self.definitions.node_to_hir_id(node_id)
402+
}
403+
395404
fn entry_count(&self) -> usize {
396405
self.map.len()
397406
}

src/librustc/hir/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ pub const CRATE_HIR_ID: HirId = HirId {
129129

130130
pub const DUMMY_HIR_ID: HirId = HirId {
131131
owner: CRATE_DEF_INDEX,
132-
local_id: ItemLocalId(!0)
132+
local_id: DUMMY_ITEM_LOCAL_ID,
133133
};
134134

135+
pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId(!0);
136+
135137
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
136138
pub struct Lifetime {
137139
pub id: NodeId,
@@ -547,6 +549,7 @@ pub struct Block {
547549
/// without a semicolon, if any
548550
pub expr: Option<P<Expr>>,
549551
pub id: NodeId,
552+
pub hir_id: HirId,
550553
/// Distinguishes between `unsafe { ... }` and `{ ... }`
551554
pub rules: BlockCheckMode,
552555
pub span: Span,
@@ -560,6 +563,7 @@ pub struct Block {
560563
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
561564
pub struct Pat {
562565
pub id: NodeId,
566+
pub hir_id: HirId,
563567
pub node: PatKind,
564568
pub span: Span,
565569
}
@@ -986,6 +990,7 @@ pub struct Expr {
986990
pub span: Span,
987991
pub node: Expr_,
988992
pub attrs: ThinVec<Attribute>,
993+
pub hir_id: HirId,
989994
}
990995

991996
impl fmt::Debug for Expr {
@@ -1423,6 +1428,7 @@ pub struct InlineAsm {
14231428
pub struct Arg {
14241429
pub pat: P<Pat>,
14251430
pub id: NodeId,
1431+
pub hir_id: HirId,
14261432
}
14271433

14281434
/// Represents the header (not the body) of a function declaration

src/librustc/ich/impls_hir.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::B
359359
ref stmts,
360360
ref expr,
361361
id,
362+
hir_id: _,
362363
rules,
363364
span,
364365
targeted_by_break,
@@ -423,6 +424,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::P
423424

424425
let hir::Pat {
425426
id,
427+
hir_id: _,
426428
ref node,
427429
ref span
428430
} = *self;
@@ -551,6 +553,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::E
551553
hcx.while_hashing_hir_bodies(true, |hcx| {
552554
let hir::Expr {
553555
id,
556+
hir_id: _,
554557
ref span,
555558
ref node,
556559
ref attrs
@@ -1021,7 +1024,8 @@ impl_stable_hash_for!(enum hir::Stmt_ {
10211024

10221025
impl_stable_hash_for!(struct hir::Arg {
10231026
pat,
1024-
id
1027+
id,
1028+
hir_id
10251029
});
10261030

10271031
impl_stable_hash_for!(struct hir::Body {

src/librustc/ich/impls_ty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ for ty::TypeckTables<'gcx> {
618618
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
619619
hasher: &mut StableHasher<W>) {
620620
let ty::TypeckTables {
621+
local_id_root: _,
621622
ref type_dependent_defs,
622623
ref node_types,
623624
ref node_substs,
@@ -637,7 +638,9 @@ for ty::TypeckTables<'gcx> {
637638
} = *self;
638639

639640
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
640-
ich::hash_stable_nodemap(hcx, hasher, type_dependent_defs);
641+
ich::hash_stable_hashmap(hcx, hasher, type_dependent_defs, |_, item_local_id| {
642+
*item_local_id
643+
});
641644
ich::hash_stable_nodemap(hcx, hasher, node_types);
642645
ich::hash_stable_nodemap(hcx, hasher, node_substs);
643646
ich::hash_stable_nodemap(hcx, hasher, adjustments);

src/librustc/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
358358
impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
359359
/// Used only by `rustc_typeck` during body type-checking/inference,
360360
/// will initialize `in_progress_tables` with fresh `TypeckTables`.
361-
pub fn with_fresh_in_progress_tables(mut self) -> Self {
362-
self.fresh_tables = Some(RefCell::new(ty::TypeckTables::empty()));
361+
pub fn with_fresh_in_progress_tables(mut self, table_owner: DefId) -> Self {
362+
self.fresh_tables = Some(RefCell::new(ty::TypeckTables::empty(table_owner)));
363363
self
364364
}
365365

src/librustc/lint/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use syntax::ast;
4343
use syntax_pos::{MultiSpan, Span};
4444
use errors::DiagnosticBuilder;
4545
use hir;
46-
use hir::def_id::LOCAL_CRATE;
46+
use hir::def_id::{DefId, LOCAL_CRATE};
4747
use hir::intravisit as hir_visit;
4848
use syntax::visit as ast_visit;
4949

@@ -986,7 +986,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
986986

987987
let mut cx = LateContext {
988988
tcx,
989-
tables: &ty::TypeckTables::empty(),
989+
tables: &ty::TypeckTables::empty(DefId::invalid()),
990990
param_env: ty::ParamEnv::empty(Reveal::UserFacing),
991991
access_levels,
992992
lint_sess: LintSession::new(&tcx.sess.lint_store),

src/librustc/middle/dead.rs

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

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

@@ -119,6 +119,8 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
119119

120120
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, def: Def,
121121
pats: &[codemap::Spanned<hir::FieldPat>]) {
122+
123+
122124
let variant = match self.tables.node_id_to_type(lhs.id).sty {
123125
ty::TyAdt(adt, _) => adt.variant_of_def(def),
124126
_ => span_bug!(lhs.span, "non-ADT in struct pattern")
@@ -235,11 +237,11 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
235237
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
236238
match expr.node {
237239
hir::ExprPath(ref qpath @ hir::QPath::TypeRelative(..)) => {
238-
let def = self.tables.qpath_def(qpath, expr.id);
240+
let def = self.tables.qpath_def(qpath, expr.hir_id);
239241
self.handle_definition(def);
240242
}
241243
hir::ExprMethodCall(..) => {
242-
self.lookup_and_handle_method(expr.id);
244+
self.lookup_and_handle_method(expr.hir_id.local_id);
243245
}
244246
hir::ExprField(ref lhs, ref name) => {
245247
self.handle_field_access(&lhs, name.node);
@@ -282,7 +284,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
282284
self.handle_field_pattern_match(pat, path.def, fields);
283285
}
284286
PatKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
285-
let def = self.tables.qpath_def(qpath, pat.id);
287+
let def = self.tables.qpath_def(qpath, pat.hir_id);
286288
self.handle_definition(def);
287289
}
288290
_ => ()
@@ -425,7 +427,7 @@ fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
425427
let mut symbol_visitor = MarkSymbolVisitor {
426428
worklist,
427429
tcx,
428-
tables: &ty::TypeckTables::empty(),
430+
tables: &ty::TypeckTables::empty(DefId::invalid()),
429431
live_symbols: box FxHashSet(),
430432
struct_has_extern_repr: false,
431433
ignore_non_const_paths: false,

0 commit comments

Comments
 (0)