Skip to content

Commit 5a6a9ed

Browse files
committed
rustc: combine partial_def_map and last_private_map into def_map.
1 parent 06f362a commit 5a6a9ed

38 files changed

+444
-449
lines changed

src/librustc/lint/builtin.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
406406

407407
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
408408
fn check_def(&mut self, sp: Span, id: ast::NodeId) {
409-
match self.cx.tcx.def_map.borrow()[id].clone() {
409+
match self.cx.tcx.def_map.borrow()[id].full_def() {
410410
def::DefPrimTy(ast::TyInt(ast::TyIs(_))) => {
411411
self.cx.span_lint(IMPROPER_CTYPES, sp,
412412
"found rust type `isize` in foreign module, while \
@@ -1000,7 +1000,8 @@ impl LintPass for NonSnakeCase {
10001000

10011001
fn check_pat(&mut self, cx: &Context, p: &ast::Pat) {
10021002
if let &ast::PatIdent(_, ref path1, _) = &p.node {
1003-
if let Some(&def::DefLocal(_)) = cx.tcx.def_map.borrow().get(&p.id) {
1003+
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
1004+
if let Some(def::DefLocal(_)) = def {
10041005
self.check_snake_case(cx, "variable", path1.node, p.span);
10051006
}
10061007
}
@@ -1065,8 +1066,8 @@ impl LintPass for NonUpperCaseGlobals {
10651066

10661067
fn check_pat(&mut self, cx: &Context, p: &ast::Pat) {
10671068
// Lint for constants that look like binding identifiers (#7526)
1068-
match (&p.node, cx.tcx.def_map.borrow().get(&p.id)) {
1069-
(&ast::PatIdent(_, ref path1, _), Some(&def::DefConst(..))) => {
1069+
match (&p.node, cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def())) {
1070+
(&ast::PatIdent(_, ref path1, _), Some(def::DefConst(..))) => {
10701071
NonUpperCaseGlobals::check_upper_case(cx, "constant in pattern",
10711072
path1.node, p.span);
10721073
}
@@ -1226,10 +1227,13 @@ impl LintPass for NonShorthandFieldPatterns {
12261227
fn check_pat(&mut self, cx: &Context, pat: &ast::Pat) {
12271228
let def_map = cx.tcx.def_map.borrow();
12281229
if let ast::PatStruct(_, ref v, _) = pat.node {
1229-
for fieldpat in v.iter()
1230-
.filter(|fieldpat| !fieldpat.node.is_shorthand)
1231-
.filter(|fieldpat| def_map.get(&fieldpat.node.pat.id)
1232-
== Some(&def::DefLocal(fieldpat.node.pat.id))) {
1230+
let field_pats = v.iter()
1231+
.filter(|fieldpat| !fieldpat.node.is_shorthand)
1232+
.filter(|fieldpat| {
1233+
let def = def_map.get(&fieldpat.node.pat.id).map(|d| d.full_def());
1234+
def == Some(def::DefLocal(fieldpat.node.pat.id))
1235+
});
1236+
for fieldpat in field_pats {
12331237
if let ast::PatIdent(_, ident, None) = fieldpat.node.pat.node {
12341238
if ident.node.as_str() == fieldpat.node.ident.as_str() {
12351239
cx.span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span,
@@ -1908,10 +1912,7 @@ impl LintPass for UnconditionalRecursion {
19081912
_: ast::Ident,
19091913
id: ast::NodeId) -> bool {
19101914
tcx.def_map.borrow().get(&id)
1911-
.map_or(false, |def| {
1912-
let did = def.def_id();
1913-
ast_util::is_local(did) && did.node == fn_id
1914-
})
1915+
.map_or(false, |def| def.def_id() == ast_util::local_def(fn_id))
19151916
}
19161917

19171918
// check if the method call `id` refers to method `method_id`

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,9 +1870,7 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
18701870
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
18711871
fn visit_item(&mut self, item: &ast::Item) {
18721872
if let ast::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
1873-
let def_map = &self.ecx.tcx.def_map;
1874-
let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
1875-
let def_id = trait_def.def_id();
1873+
let def_id = self.ecx.tcx.def_map.borrow()[trait_ref.ref_id].def_id();
18761874

18771875
// Load eagerly if this is an implementation of the Drop trait
18781876
// or if the trait is not defined in this crate.

src/librustc/middle/astconv_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
6565
tcx.sess.span_bug(ast_ty.span,
6666
&format!("unbound path {}", path.repr(tcx)))
6767
}
68-
Some(&d) => d
68+
Some(d) => d.full_def()
6969
};
7070
if let def::DefPrimTy(nty) = def {
7171
Some(prim_ty_to_ty(tcx, &path.segments[], nty))

src/librustc/middle/astencode.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use metadata::tydecode::{RegionParameter, ClosureSource};
2525
use metadata::tyencode;
2626
use middle::check_const::ConstQualif;
2727
use middle::mem_categorization::Typer;
28+
use middle::privacy::{AllPublic, LastMod};
2829
use middle::subst;
2930
use middle::subst::VecPerParamSpace;
3031
use middle::ty::{self, Ty, MethodCall, MethodCallee, MethodOrigin};
@@ -1148,10 +1149,10 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
11481149

11491150
debug!("Encoding side tables for id {}", id);
11501151

1151-
if let Some(def) = tcx.def_map.borrow().get(&id) {
1152+
if let Some(def) = tcx.def_map.borrow().get(&id).map(|d| d.full_def()) {
11521153
rbml_w.tag(c::tag_table_def, |rbml_w| {
11531154
rbml_w.id(id);
1154-
rbml_w.tag(c::tag_table_val, |rbml_w| (*def).encode(rbml_w).unwrap());
1155+
rbml_w.tag(c::tag_table_val, |rbml_w| def.encode(rbml_w).unwrap());
11551156
})
11561157
}
11571158

@@ -1851,7 +1852,12 @@ fn decode_side_tables(dcx: &DecodeContext,
18511852
match value {
18521853
c::tag_table_def => {
18531854
let def = decode_def(dcx, val_doc);
1854-
dcx.tcx.def_map.borrow_mut().insert(id, def);
1855+
dcx.tcx.def_map.borrow_mut().insert(id, def::PathResolution {
1856+
base_def: def,
1857+
// This doesn't matter cross-crate.
1858+
last_private: LastMod(AllPublic),
1859+
depth: 0
1860+
});
18551861
}
18561862
c::tag_table_node_type => {
18571863
let ty = val_dsr.read_ty(dcx);

src/librustc/middle/cfg/construct.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -610,32 +610,24 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
610610
fn find_scope(&self,
611611
expr: &ast::Expr,
612612
label: Option<ast::Ident>) -> LoopScope {
613-
match label {
614-
None => {
615-
return *self.loop_scopes.last().unwrap();
616-
}
617-
618-
Some(_) => {
619-
match self.tcx.def_map.borrow().get(&expr.id) {
620-
Some(&def::DefLabel(loop_id)) => {
621-
for l in &self.loop_scopes {
622-
if l.loop_id == loop_id {
623-
return *l;
624-
}
625-
}
626-
self.tcx.sess.span_bug(
627-
expr.span,
628-
&format!("no loop scope for id {}",
629-
loop_id));
630-
}
613+
if label.is_none() {
614+
return *self.loop_scopes.last().unwrap();
615+
}
631616

632-
r => {
633-
self.tcx.sess.span_bug(
634-
expr.span,
635-
&format!("bad entry `{:?}` in def_map for label",
636-
r));
617+
match self.tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def()) {
618+
Some(def::DefLabel(loop_id)) => {
619+
for l in &self.loop_scopes {
620+
if l.loop_id == loop_id {
621+
return *l;
637622
}
638623
}
624+
self.tcx.sess.span_bug(expr.span,
625+
&format!("no loop scope for id {}", loop_id));
626+
}
627+
628+
r => {
629+
self.tcx.sess.span_bug(expr.span,
630+
&format!("bad entry `{:?}` in def_map for label", r));
639631
}
640632
}
641633
}

src/librustc/middle/check_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
440440
}
441441
}
442442
ast::ExprPath(_) | ast::ExprQPath(_) => {
443-
let def = v.tcx.def_map.borrow().get(&e.id).cloned();
443+
let def = v.tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
444444
match def {
445445
Some(def::DefVariant(_, _, _)) => {
446446
// Count the discriminator or function pointer.
@@ -499,7 +499,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
499499
_ => break
500500
};
501501
}
502-
let def = v.tcx.def_map.borrow().get(&callee.id).cloned();
502+
let def = v.tcx.def_map.borrow().get(&callee.id).map(|d| d.full_def());
503503
match def {
504504
Some(def::DefStruct(..)) => {}
505505
Some(def::DefVariant(..)) => {

src/librustc/middle/check_match.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
242242
ast::PatIdent(ast::BindByValue(ast::MutImmutable), ident, None) => {
243243
let pat_ty = ty::pat_ty(cx.tcx, p);
244244
if let ty::ty_enum(def_id, _) = pat_ty.sty {
245-
let def = cx.tcx.def_map.borrow().get(&p.id).cloned();
245+
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
246246
if let Some(DefLocal(_)) = def {
247247
if ty::enum_variants(cx.tcx, def_id).iter().any(|variant|
248248
token::get_name(variant.name) == token::get_name(ident.node.name)
@@ -434,7 +434,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
434434
fn fold_pat(&mut self, pat: P<Pat>) -> P<Pat> {
435435
return match pat.node {
436436
ast::PatIdent(..) | ast::PatEnum(..) => {
437-
let def = self.tcx.def_map.borrow().get(&pat.id).cloned();
437+
let def = self.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def());
438438
match def {
439439
Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did) {
440440
Some(const_expr) => {
@@ -733,28 +733,28 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
733733
let pat = raw_pat(p);
734734
match pat.node {
735735
ast::PatIdent(..) =>
736-
match cx.tcx.def_map.borrow().get(&pat.id) {
737-
Some(&DefConst(..)) =>
736+
match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
737+
Some(DefConst(..)) =>
738738
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
739739
been rewritten"),
740-
Some(&DefStruct(_)) => vec!(Single),
741-
Some(&DefVariant(_, id, _)) => vec!(Variant(id)),
740+
Some(DefStruct(_)) => vec!(Single),
741+
Some(DefVariant(_, id, _)) => vec!(Variant(id)),
742742
_ => vec!()
743743
},
744744
ast::PatEnum(..) =>
745-
match cx.tcx.def_map.borrow().get(&pat.id) {
746-
Some(&DefConst(..)) =>
745+
match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
746+
Some(DefConst(..)) =>
747747
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
748748
been rewritten"),
749-
Some(&DefVariant(_, id, _)) => vec!(Variant(id)),
749+
Some(DefVariant(_, id, _)) => vec!(Variant(id)),
750750
_ => vec!(Single)
751751
},
752752
ast::PatStruct(..) =>
753-
match cx.tcx.def_map.borrow().get(&pat.id) {
754-
Some(&DefConst(..)) =>
753+
match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
754+
Some(DefConst(..)) =>
755755
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
756756
been rewritten"),
757-
Some(&DefVariant(_, id, _)) => vec!(Variant(id)),
757+
Some(DefVariant(_, id, _)) => vec!(Variant(id)),
758758
_ => vec!(Single)
759759
},
760760
ast::PatLit(ref expr) =>
@@ -847,7 +847,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
847847
Some(repeat(DUMMY_WILD_PAT).take(arity).collect()),
848848

849849
ast::PatIdent(_, _, _) => {
850-
let opt_def = cx.tcx.def_map.borrow().get(&pat_id).cloned();
850+
let opt_def = cx.tcx.def_map.borrow().get(&pat_id).map(|d| d.full_def());
851851
match opt_def {
852852
Some(DefConst(..)) =>
853853
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
@@ -862,7 +862,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
862862
}
863863

864864
ast::PatEnum(_, ref args) => {
865-
let def = cx.tcx.def_map.borrow()[pat_id].clone();
865+
let def = cx.tcx.def_map.borrow()[pat_id].full_def();
866866
match def {
867867
DefConst(..) =>
868868
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
@@ -880,7 +880,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
880880

881881
ast::PatStruct(_, ref pattern_fields, _) => {
882882
// Is this a struct or an enum variant?
883-
let def = cx.tcx.def_map.borrow()[pat_id].clone();
883+
let def = cx.tcx.def_map.borrow()[pat_id].full_def();
884884
let class_id = match def {
885885
DefConst(..) =>
886886
cx.tcx.sess.span_bug(pat_span, "const pattern should've \

src/librustc/middle/check_static_recursion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
9494
fn visit_expr(&mut self, e: &ast::Expr) {
9595
match e.node {
9696
ast::ExprPath(_) | ast::ExprQPath(_) => {
97-
match self.def_map.borrow().get(&e.id) {
98-
Some(&DefStatic(def_id, _)) |
99-
Some(&DefConst(def_id)) if
97+
match self.def_map.borrow().get(&e.id).map(|d| d.full_def()) {
98+
Some(DefStatic(def_id, _)) |
99+
Some(DefConst(def_id)) if
100100
ast_util::is_local(def_id) => {
101101
match self.ast_map.get(def_id.node) {
102102
ast_map::NodeItem(item) =>

src/librustc/middle/const_eval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::{i8, i16, i32, i64};
3131
use std::rc::Rc;
3232

3333
fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> {
34-
let opt_def = tcx.def_map.borrow().get(&e.id).cloned();
34+
let opt_def = tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
3535
match opt_def {
3636
Some(def::DefConst(def_id)) => {
3737
lookup_const_by_id(tcx, def_id)
@@ -148,11 +148,11 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
148148
ast::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect()),
149149

150150
ast::ExprCall(ref callee, ref args) => {
151-
let def = tcx.def_map.borrow()[callee.id].clone();
151+
let def = tcx.def_map.borrow()[callee.id];
152152
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) {
153153
entry.insert(def);
154154
}
155-
let path = match def {
155+
let path = match def.full_def() {
156156
def::DefStruct(def_id) => def_to_path(tcx, def_id),
157157
def::DefVariant(_, variant_did, _) => def_to_path(tcx, variant_did),
158158
_ => unreachable!()
@@ -179,7 +179,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
179179
}
180180

181181
ast::ExprPath(ref path) => {
182-
let opt_def = tcx.def_map.borrow().get(&expr.id).cloned();
182+
let opt_def = tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def());
183183
match opt_def {
184184
Some(def::DefStruct(..)) =>
185185
ast::PatStruct(path.clone(), vec![], false),
@@ -389,7 +389,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
389389
cast_const(val, ety)
390390
}
391391
ast::ExprPath(_) | ast::ExprQPath(_) => {
392-
let opt_def = tcx.def_map.borrow().get(&e.id).cloned();
392+
let opt_def = tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
393393
let (const_expr, const_ty) = match opt_def {
394394
Some(def::DefConst(def_id)) => {
395395
if ast_util::is_local(def_id) {

src/librustc/middle/dead.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7171

7272
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
7373
self.tcx.def_map.borrow().get(id).map(|def| {
74-
match def {
75-
&def::DefConst(_) => {
74+
match def.full_def() {
75+
def::DefConst(_) => {
7676
self.check_def_id(def.def_id())
7777
}
7878
_ if self.ignore_non_const_paths => (),
79-
&def::DefPrimTy(_) => (),
80-
&def::DefVariant(enum_id, variant_id, _) => {
79+
def::DefPrimTy(_) => (),
80+
def::DefVariant(enum_id, variant_id, _) => {
8181
self.check_def_id(enum_id);
8282
self.check_def_id(variant_id);
8383
}
@@ -158,7 +158,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
158158

159159
fn handle_field_pattern_match(&mut self, lhs: &ast::Pat,
160160
pats: &[codemap::Spanned<ast::FieldPat>]) {
161-
let id = match (*self.tcx.def_map.borrow())[lhs.id] {
161+
let id = match self.tcx.def_map.borrow()[lhs.id].full_def() {
162162
def::DefVariant(_, id, _) => id,
163163
_ => {
164164
match ty::ty_to_def_id(ty::node_id_to_type(self.tcx,

0 commit comments

Comments
 (0)