Skip to content

Commit 962633c

Browse files
committed
rustc: embed path resolutions into the HIR instead of keeping DefMap.
1 parent bc09654 commit 962633c

File tree

55 files changed

+927
-925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+927
-925
lines changed

src/librustc/cfg/construct.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
use rustc_data_structures::graph;
1212
use cfg::*;
13-
use hir::def::Def;
14-
use hir::pat_util;
1513
use ty::{self, TyCtxt};
1614
use syntax::ast;
1715
use syntax::ptr::P;
@@ -284,15 +282,15 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
284282

285283
hir::ExprBreak(label, ref opt_expr) => {
286284
let v = self.opt_expr(opt_expr, pred);
287-
let loop_scope = self.find_scope(expr, label.map(|l| l.node));
285+
let loop_scope = self.find_scope(expr, label);
288286
let b = self.add_ast_node(expr.id, &[v]);
289287
self.add_exiting_edge(expr, b,
290288
loop_scope, loop_scope.break_index);
291289
self.add_unreachable_node()
292290
}
293291

294292
hir::ExprAgain(label) => {
295-
let loop_scope = self.find_scope(expr, label.map(|l| l.node));
293+
let loop_scope = self.find_scope(expr, label);
296294
let a = self.add_ast_node(expr.id, &[pred]);
297295
self.add_exiting_edge(expr, a,
298296
loop_scope, loop_scope.continue_index);
@@ -457,7 +455,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
457455
// Visit the guard expression
458456
let guard_exit = self.expr(&guard, guard_start);
459457

460-
let this_has_bindings = pat_util::pat_contains_bindings_or_wild(&pat);
458+
let this_has_bindings = pat.contains_bindings_or_wild();
461459

462460
// If both this pattern and the previous pattern
463461
// were free of bindings, they must consist only
@@ -570,23 +568,16 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
570568

571569
fn find_scope(&self,
572570
expr: &hir::Expr,
573-
label: Option<ast::Name>) -> LoopScope {
574-
if label.is_none() {
575-
return *self.loop_scopes.last().unwrap();
576-
}
577-
578-
match self.tcx.expect_def(expr.id) {
579-
Def::Label(loop_id) => {
571+
label: Option<hir::Label>) -> LoopScope {
572+
match label {
573+
None => *self.loop_scopes.last().unwrap(),
574+
Some(label) => {
580575
for l in &self.loop_scopes {
581-
if l.loop_id == loop_id {
576+
if l.loop_id == label.loop_id {
582577
return *l;
583578
}
584579
}
585-
span_bug!(expr.span, "no loop scope for id {}", loop_id);
586-
}
587-
588-
r => {
589-
span_bug!(expr.span, "bad entry `{:?}` in def_map for label", r);
580+
span_bug!(expr.span, "no loop scope for id {}", label.loop_id);
590581
}
591582
}
592583
}

src/librustc/hir/def.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ impl PathResolution {
8383
PathResolution { base_def: def, depth: 0 }
8484
}
8585

86-
/// Get the definition, if fully resolved, otherwise panic.
87-
pub fn full_def(&self) -> Def {
88-
if self.depth != 0 {
89-
bug!("path not fully resolved: {:?}", self);
90-
}
91-
self.base_def
92-
}
93-
9486
pub fn kind_name(&self) -> &'static str {
9587
if self.depth != 0 {
9688
"associated item"

src/librustc/hir/intravisit.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use syntax::ast::{NodeId, CRATE_NODE_ID, Name, Attribute};
3838
use syntax::codemap::Spanned;
3939
use syntax_pos::Span;
4040
use hir::*;
41+
use hir::def::Def;
4142
use hir::map::Map;
4243
use super::itemlikevisit::DeepVisitor;
4344

@@ -155,6 +156,9 @@ pub trait Visitor<'v> : Sized {
155156
fn visit_id(&mut self, _node_id: NodeId) {
156157
// Nothing to do.
157158
}
159+
fn visit_def_mention(&mut self, _def: Def) {
160+
// Nothing to do.
161+
}
158162
fn visit_name(&mut self, _span: Span, _name: Name) {
159163
// Nothing to do.
160164
}
@@ -507,6 +511,7 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: Nod
507511
}
508512

509513
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
514+
visitor.visit_def_mention(path.def);
510515
for segment in &path.segments {
511516
visitor.visit_path_segment(path.span, segment);
512517
}
@@ -566,7 +571,8 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
566571
PatKind::Ref(ref subpattern, _) => {
567572
visitor.visit_pat(subpattern)
568573
}
569-
PatKind::Binding(_, ref pth1, ref optional_subpattern) => {
574+
PatKind::Binding(_, def_id, ref pth1, ref optional_subpattern) => {
575+
visitor.visit_def_mention(Def::Local(def_id));
570576
visitor.visit_name(pth1.span, pth1.node);
571577
walk_list!(visitor, visit_pat, optional_subpattern);
572578
}
@@ -907,12 +913,18 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
907913
ExprPath(ref qpath) => {
908914
visitor.visit_qpath(qpath, expression.id, expression.span);
909915
}
910-
ExprBreak(ref opt_sp_name, ref opt_expr) => {
911-
walk_opt_sp_name(visitor, opt_sp_name);
916+
ExprBreak(None, ref opt_expr) => {
912917
walk_list!(visitor, visit_expr, opt_expr);
913918
}
914-
ExprAgain(ref opt_sp_name) => {
915-
walk_opt_sp_name(visitor, opt_sp_name);
919+
ExprBreak(Some(label), ref opt_expr) => {
920+
visitor.visit_def_mention(Def::Label(label.loop_id));
921+
visitor.visit_name(label.span, label.name);
922+
walk_list!(visitor, visit_expr, opt_expr);
923+
}
924+
ExprAgain(None) => {}
925+
ExprAgain(Some(label)) => {
926+
visitor.visit_def_mention(Def::Label(label.loop_id));
927+
visitor.visit_name(label.span, label.name);
916928
}
917929
ExprRet(ref optional_expression) => {
918930
walk_list!(visitor, visit_expr, optional_expression);

0 commit comments

Comments
 (0)