Skip to content

Commit 9ff4f57

Browse files
committed
move job of creating local-def-ids to ast-map (with a few stragglers)
1 parent 2dd139f commit 9ff4f57

Some content is hidden

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

51 files changed

+414
-326
lines changed

src/librustc/front/map/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub use self::Node::*;
1212
pub use self::PathElem::*;
1313
use self::MapEntry::*;
1414

15+
use metadata::cstore::LOCAL_CRATE;
1516
use metadata::inline::InlinedItem;
1617
use metadata::inline::InlinedItem as II;
1718
use middle::def_id::DefId;
@@ -267,6 +268,18 @@ pub struct Map<'ast> {
267268
}
268269

269270
impl<'ast> Map<'ast> {
271+
pub fn local_def_id(&self, node: NodeId) -> DefId {
272+
DefId::xxx_local(node)
273+
}
274+
275+
pub fn as_local_node_id(&self, def_id: DefId) -> Option<NodeId> {
276+
if def_id.krate == LOCAL_CRATE {
277+
Some(def_id.node)
278+
} else {
279+
None
280+
}
281+
}
282+
270283
fn entry_count(&self) -> usize {
271284
self.map.borrow().len()
272285
}
@@ -383,7 +396,7 @@ impl<'ast> Map<'ast> {
383396
match self.find_entry(parent) {
384397
Some(RootInlinedParent(&InlinedParent {ii: II::TraitItem(did, _), ..})) => did,
385398
Some(RootInlinedParent(&InlinedParent {ii: II::ImplItem(did, _), ..})) => did,
386-
_ => DefId::local(parent)
399+
_ => self.local_def_id(parent)
387400
}
388401
}
389402

@@ -1134,3 +1147,4 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
11341147
}
11351148
}
11361149
}
1150+

src/librustc/metadata/encoder.rs

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn def_to_string(did: DefId) -> String {
119119
fn encode_item_variances(rbml_w: &mut Encoder,
120120
ecx: &EncodeContext,
121121
id: NodeId) {
122-
let v = ecx.tcx.item_variances(DefId::local(id));
122+
let v = ecx.tcx.item_variances(ecx.tcx.map.local_def_id(id));
123123
rbml_w.start_tag(tag_item_variances);
124124
v.encode(rbml_w);
125125
rbml_w.end_tag();
@@ -130,8 +130,8 @@ fn encode_bounds_and_type_for_item<'a, 'tcx>(rbml_w: &mut Encoder,
130130
id: NodeId) {
131131
encode_bounds_and_type(rbml_w,
132132
ecx,
133-
&ecx.tcx.lookup_item_type(DefId::local(id)),
134-
&ecx.tcx.lookup_predicates(DefId::local(id)));
133+
&ecx.tcx.lookup_item_type(ecx.tcx.map.local_def_id(id)),
134+
&ecx.tcx.lookup_predicates(ecx.tcx.map.local_def_id(id)));
135135
}
136136

137137
fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder,
@@ -278,7 +278,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
278278
debug!("encode_enum_variant_info(id={})", id);
279279

280280
let mut disr_val = 0;
281-
let def = ecx.tcx.lookup_adt_def(DefId::local(id));
281+
let def = ecx.tcx.lookup_adt_def(ecx.tcx.map.local_def_id(id));
282282
for variant in &def.variants {
283283
let vid = variant.did;
284284
assert!(vid.is_local());
@@ -302,7 +302,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
302302
ty::VariantKind::Dict => 'V'
303303
});
304304
encode_name(rbml_w, variant.name);
305-
encode_parent_item(rbml_w, DefId::local(id));
305+
encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(id));
306306
encode_visibility(rbml_w, vis);
307307

308308
let attrs = ecx.tcx.get_attrs(vid);
@@ -504,19 +504,19 @@ fn encode_info_for_mod(ecx: &EncodeContext,
504504
name: Name,
505505
vis: hir::Visibility) {
506506
rbml_w.start_tag(tag_items_data_item);
507-
encode_def_id(rbml_w, DefId::local(id));
507+
encode_def_id(rbml_w, ecx.tcx.map.local_def_id(id));
508508
encode_family(rbml_w, 'm');
509509
encode_name(rbml_w, name);
510510
debug!("(encoding info for module) encoding info for module ID {}", id);
511511

512512
// Encode info about all the module children.
513513
for item in &md.items {
514514
rbml_w.wr_tagged_u64(tag_mod_child,
515-
def_to_u64(DefId::local(item.id)));
515+
def_to_u64(ecx.tcx.map.local_def_id(item.id)));
516516

517517
each_auxiliary_node_id(&**item, |auxiliary_node_id| {
518518
rbml_w.wr_tagged_u64(tag_mod_child,
519-
def_to_u64(DefId::local(auxiliary_node_id)));
519+
def_to_u64(ecx.tcx.map.local_def_id(auxiliary_node_id)));
520520
true
521521
});
522522

@@ -526,14 +526,14 @@ fn encode_info_for_mod(ecx: &EncodeContext,
526526
name,
527527
did, ecx.tcx.map.node_to_string(did));
528528

529-
rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(DefId::local(did)));
529+
rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(ecx.tcx.map.local_def_id(did)));
530530
}
531531
}
532532

533533
encode_path(rbml_w, path.clone());
534534
encode_visibility(rbml_w, vis);
535535

536-
let stab = stability::lookup(ecx.tcx, DefId::local(id));
536+
let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(id));
537537
encode_stability(rbml_w, stab);
538538

539539
// Encode the reexports of this module, if this module is public.
@@ -627,7 +627,7 @@ fn encode_field<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
627627
encode_struct_field_family(rbml_w, field.vis);
628628
encode_name(rbml_w, nm);
629629
encode_bounds_and_type_for_item(rbml_w, ecx, id);
630-
encode_def_id(rbml_w, DefId::local(id));
630+
encode_def_id(rbml_w, ecx.tcx.map.local_def_id(id));
631631

632632
let stab = stability::lookup(ecx.tcx, field.did);
633633
encode_stability(rbml_w, stab);
@@ -647,18 +647,18 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
647647
});
648648

649649
rbml_w.start_tag(tag_items_data_item);
650-
encode_def_id(rbml_w, DefId::local(ctor_id));
650+
encode_def_id(rbml_w, ecx.tcx.map.local_def_id(ctor_id));
651651
encode_family(rbml_w, 'o');
652652
encode_bounds_and_type_for_item(rbml_w, ecx, ctor_id);
653653
encode_name(rbml_w, name);
654654
ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path));
655-
encode_parent_item(rbml_w, DefId::local(struct_id));
655+
encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(struct_id));
656656

657657
if ecx.item_symbols.borrow().contains_key(&ctor_id) {
658658
encode_symbol(ecx, rbml_w, ctor_id);
659659
}
660660

661-
let stab = stability::lookup(ecx.tcx, DefId::local(ctor_id));
661+
let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(ctor_id));
662662
encode_stability(rbml_w, stab);
663663

664664
// indicate that this is a tuple struct ctor, because downstream users will normally want
@@ -789,7 +789,7 @@ fn encode_info_for_associated_const(ecx: &EncodeContext,
789789
encode_visibility(rbml_w, associated_const.vis);
790790
encode_family(rbml_w, 'C');
791791

792-
encode_parent_item(rbml_w, DefId::local(parent_id));
792+
encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(parent_id));
793793
encode_item_sort(rbml_w, 'C');
794794

795795
encode_bounds_and_type_for_item(rbml_w, ecx, associated_const.def_id.local_id());
@@ -802,7 +802,10 @@ fn encode_info_for_associated_const(ecx: &EncodeContext,
802802

803803
if let Some(ii) = impl_item_opt {
804804
encode_attributes(rbml_w, &ii.attrs);
805-
encode_inlined_item(ecx, rbml_w, InlinedItemRef::ImplItem(DefId::local(parent_id), ii));
805+
encode_inlined_item(ecx,
806+
rbml_w,
807+
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
808+
ii));
806809
}
807810

808811
rbml_w.end_tag();
@@ -821,7 +824,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
821824
rbml_w.start_tag(tag_items_data_item);
822825

823826
encode_method_ty_fields(ecx, rbml_w, m);
824-
encode_parent_item(rbml_w, DefId::local(parent_id));
827+
encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(parent_id));
825828
encode_item_sort(rbml_w, 'r');
826829

827830
let stab = stability::lookup(ecx.tcx, m.def_id);
@@ -840,8 +843,10 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
840843
let needs_inline = any_types || is_default_impl ||
841844
attr::requests_inline(&impl_item.attrs);
842845
if needs_inline || sig.constness == hir::Constness::Const {
843-
encode_inlined_item(ecx, rbml_w, InlinedItemRef::ImplItem(DefId::local(parent_id),
844-
impl_item));
846+
encode_inlined_item(ecx,
847+
rbml_w,
848+
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
849+
impl_item));
845850
}
846851
encode_constness(rbml_w, sig.constness);
847852
if !any_types {
@@ -870,7 +875,7 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
870875
encode_name(rbml_w, associated_type.name);
871876
encode_visibility(rbml_w, associated_type.vis);
872877
encode_family(rbml_w, 'y');
873-
encode_parent_item(rbml_w, DefId::local(parent_id));
878+
encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(parent_id));
874879
encode_item_sort(rbml_w, 't');
875880

876881
let stab = stability::lookup(ecx.tcx, associated_type.def_id);
@@ -991,8 +996,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
991996
debug!("encoding info for item at {}",
992997
tcx.sess.codemap().span_to_string(item.span));
993998

994-
let def_id = DefId::local(item.id);
995-
let stab = stability::lookup(tcx, DefId::local(item.id));
999+
let def_id = ecx.tcx.map.local_def_id(item.id);
1000+
let stab = stability::lookup(tcx, ecx.tcx.map.local_def_id(item.id));
9961001

9971002
match item.node {
9981003
hir::ItemStatic(_, m, _) => {
@@ -1072,7 +1077,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
10721077
// Encode all the items in this module.
10731078
for foreign_item in &fm.items {
10741079
rbml_w.wr_tagged_u64(tag_mod_child,
1075-
def_to_u64(DefId::local(foreign_item.id)));
1080+
def_to_u64(ecx.tcx.map.local_def_id(foreign_item.id)));
10761081
}
10771082
encode_visibility(rbml_w, vis);
10781083
encode_stability(rbml_w, stab);
@@ -1102,7 +1107,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
11021107
encode_attributes(rbml_w, &item.attrs);
11031108
encode_repr_attrs(rbml_w, ecx, &item.attrs);
11041109
for v in &enum_definition.variants {
1105-
encode_variant_id(rbml_w, DefId::local(v.node.id));
1110+
encode_variant_id(rbml_w, ecx.tcx.map.local_def_id(v.node.id));
11061111
}
11071112
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
11081113
encode_path(rbml_w, path);
@@ -1174,7 +1179,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
11741179
encode_name(rbml_w, item.name);
11751180
encode_unsafety(rbml_w, unsafety);
11761181

1177-
let trait_ref = tcx.impl_trait_ref(DefId::local(item.id)).unwrap();
1182+
let trait_ref = tcx.impl_trait_ref(ecx.tcx.map.local_def_id(item.id)).unwrap();
11781183
encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref);
11791184
rbml_w.end_tag();
11801185
}
@@ -1194,7 +1199,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
11941199
encode_unsafety(rbml_w, unsafety);
11951200
encode_polarity(rbml_w, polarity);
11961201

1197-
match tcx.custom_coerce_unsized_kinds.borrow().get(&DefId::local(item.id)) {
1202+
match tcx.custom_coerce_unsized_kinds.borrow().get(&ecx.tcx.map.local_def_id(item.id)) {
11981203
Some(&kind) => {
11991204
rbml_w.start_tag(tag_impl_coerce_unsized_kind);
12001205
kind.encode(rbml_w);
@@ -1228,7 +1233,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12281233
}
12291234
rbml_w.end_tag();
12301235
}
1231-
if let Some(trait_ref) = tcx.impl_trait_ref(DefId::local(item.id)) {
1236+
if let Some(trait_ref) = tcx.impl_trait_ref(ecx.tcx.map.local_def_id(item.id)) {
12321237
encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref);
12331238
}
12341239
encode_path(rbml_w, path.clone());
@@ -1472,7 +1477,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
14721477
});
14731478

14741479
rbml_w.start_tag(tag_items_data_item);
1475-
encode_def_id(rbml_w, DefId::local(nitem.id));
1480+
encode_def_id(rbml_w, ecx.tcx.map.local_def_id(nitem.id));
14761481
encode_visibility(rbml_w, nitem.vis);
14771482
match nitem.node {
14781483
hir::ForeignItemFn(ref fndecl, _) => {
@@ -1483,7 +1488,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
14831488
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Foreign(nitem));
14841489
}
14851490
encode_attributes(rbml_w, &*nitem.attrs);
1486-
let stab = stability::lookup(ecx.tcx, DefId::local(nitem.id));
1491+
let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(nitem.id));
14871492
encode_stability(rbml_w, stab);
14881493
encode_symbol(ecx, rbml_w, nitem.id);
14891494
encode_method_argument_names(rbml_w, &*fndecl);
@@ -1496,7 +1501,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
14961501
}
14971502
encode_bounds_and_type_for_item(rbml_w, ecx, nitem.id);
14981503
encode_attributes(rbml_w, &*nitem.attrs);
1499-
let stab = stability::lookup(ecx.tcx, DefId::local(nitem.id));
1504+
let stab = stability::lookup(ecx.tcx, ecx.tcx.map.local_def_id(nitem.id));
15001505
encode_stability(rbml_w, stab);
15011506
encode_symbol(ecx, rbml_w, nitem.id);
15021507
encode_name(rbml_w, nitem.name);
@@ -1831,7 +1836,7 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
18311836
if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() ||
18321837
def_id.krate != LOCAL_CRATE {
18331838
self.rbml_w.start_tag(tag_impls_impl);
1834-
encode_def_id(self.rbml_w, DefId::local(item.id));
1839+
encode_def_id(self.rbml_w, self.ecx.tcx.map.local_def_id(item.id));
18351840
self.rbml_w.wr_tagged_u64(tag_impls_impl_trait_def_id, def_to_u64(def_id));
18361841
self.rbml_w.end_tag();
18371842
}
@@ -1873,11 +1878,11 @@ fn encode_misc_info(ecx: &EncodeContext,
18731878
rbml_w.start_tag(tag_misc_info_crate_items);
18741879
for item in &krate.module.items {
18751880
rbml_w.wr_tagged_u64(tag_mod_child,
1876-
def_to_u64(DefId::local(item.id)));
1881+
def_to_u64(ecx.tcx.map.local_def_id(item.id)));
18771882

18781883
each_auxiliary_node_id(&**item, |auxiliary_node_id| {
18791884
rbml_w.wr_tagged_u64(tag_mod_child,
1880-
def_to_u64(DefId::local(auxiliary_node_id)));
1885+
def_to_u64(ecx.tcx.map.local_def_id(auxiliary_node_id)));
18811886
true
18821887
});
18831888
}

src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,14 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
213213
// by the receiver-matching code in collect, which won't
214214
// be going down this code path, and anyway I will kill it
215215
// the moment wfcheck becomes the standard.
216-
let node_id = self.parse_uint() as ast::NodeId;
217-
assert_eq!(self.next(), '|');
216+
let def_id = self.parse_def(NominalType);
218217
let space = self.parse_param_space();
219218
assert_eq!(self.next(), '|');
220219
let index = self.parse_u32();
221220
assert_eq!(self.next(), '|');
222221
let name = token::intern(&self.parse_str(']'));
223222
ty::ReEarlyBound(ty::EarlyBoundRegion {
224-
param_id: node_id,
223+
param_id: def_id,
225224
space: space,
226225
index: index,
227226
name: name

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
250250
}
251251
ty::ReEarlyBound(ref data) => {
252252
mywrite!(w, "B[{}|{}|{}|{}]",
253-
data.param_id,
253+
(cx.ds)(data.param_id),
254254
data.space.to_uint(),
255255
data.index,
256256
data.name);

src/librustc/middle/astencode.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
934934
rbml_w.tag(c::tag_table_upvar_capture_map, |rbml_w| {
935935
rbml_w.id(id);
936936

937-
let var_id = freevar.def.def_id().node;
937+
let var_id = freevar.def.node_id();
938938
let upvar_id = ty::UpvarId {
939939
var_id: var_id,
940940
closure_expr_id: id
@@ -997,14 +997,14 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
997997
})
998998
}
999999

1000-
if let Some(closure_type) = tcx.tables.borrow().closure_tys.get(&DefId::local(id)) {
1000+
if let Some(closure_type) = tcx.tables.borrow().closure_tys.get(&tcx.map.local_def_id(id)) {
10011001
rbml_w.tag(c::tag_table_closure_tys, |rbml_w| {
10021002
rbml_w.id(id);
10031003
rbml_w.emit_closure_type(ecx, closure_type);
10041004
})
10051005
}
10061006

1007-
if let Some(closure_kind) = tcx.tables.borrow().closure_kinds.get(&DefId::local(id)) {
1007+
if let Some(closure_kind) = tcx.tables.borrow().closure_kinds.get(&tcx.map.local_def_id(id)) {
10081008
rbml_w.tag(c::tag_table_closure_kinds, |rbml_w| {
10091009
rbml_w.id(id);
10101010
encode_closure_kind(rbml_w, *closure_kind)
@@ -1476,14 +1476,16 @@ fn decode_side_tables(dcx: &DecodeContext,
14761476
c::tag_table_closure_tys => {
14771477
let closure_ty =
14781478
val_dsr.read_closure_ty(dcx);
1479-
dcx.tcx.tables.borrow_mut().closure_tys.insert(DefId::local(id),
1480-
closure_ty);
1479+
dcx.tcx.tables.borrow_mut().closure_tys.insert(
1480+
dcx.tcx.map.local_def_id(id),
1481+
closure_ty);
14811482
}
14821483
c::tag_table_closure_kinds => {
14831484
let closure_kind =
14841485
val_dsr.read_closure_kind(dcx);
1485-
dcx.tcx.tables.borrow_mut().closure_kinds.insert(DefId::local(id),
1486-
closure_kind);
1486+
dcx.tcx.tables.borrow_mut().closure_kinds.insert(
1487+
dcx.tcx.map.local_def_id(id),
1488+
closure_kind);
14871489
}
14881490
c::tag_table_cast_kinds => {
14891491
let cast_kind =

src/librustc/middle/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
8888
self.tcx.def_map.borrow().get(id).map(|def| {
8989
match def.full_def() {
9090
def::DefConst(_) | def::DefAssociatedConst(..) => {
91-
self.check_def_id(def.def_id())
91+
self.check_def_id(def.def_id());
9292
}
9393
_ if self.ignore_non_const_paths => (),
9494
def::DefPrimTy(_) => (),
@@ -481,7 +481,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
481481
// method of a private type is used, but the type itself is never
482482
// called directly.
483483
let impl_items = self.tcx.impl_items.borrow();
484-
match self.tcx.inherent_impls.borrow().get(&DefId::local(id)) {
484+
match self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) {
485485
None => (),
486486
Some(impl_list) => {
487487
for impl_did in impl_list.iter() {

0 commit comments

Comments
 (0)