Skip to content

Commit ef4352f

Browse files
committed
rustc_metadata: group information into less tags.
1 parent 6742b23 commit ef4352f

File tree

35 files changed

+972
-1533
lines changed

35 files changed

+972
-1533
lines changed

src/librustc/hir/def.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ pub enum Def {
1818
Fn(DefId),
1919
SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */),
2020
Mod(DefId),
21-
ForeignMod(DefId),
2221
Static(DefId, bool /* is_mutbl */),
2322
Const(DefId),
2423
AssociatedConst(DefId),
2524
Local(DefId),
26-
Variant(DefId /* enum */, DefId /* variant */),
25+
Variant(DefId),
2726
Enum(DefId),
2827
TyAlias(DefId),
29-
AssociatedTy(DefId /* trait */, DefId),
28+
AssociatedTy(DefId),
3029
Trait(DefId),
3130
PrimTy(hir::PrimTy),
3231
TyParam(DefId),
@@ -101,8 +100,8 @@ pub struct Export {
101100
impl Def {
102101
pub fn def_id(&self) -> DefId {
103102
match *self {
104-
Def::Fn(id) | Def::Mod(id) | Def::ForeignMod(id) | Def::Static(id, _) |
105-
Def::Variant(_, id) | Def::Enum(id) | Def::TyAlias(id) | Def::AssociatedTy(_, id) |
103+
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
104+
Def::Variant(id) | Def::Enum(id) | Def::TyAlias(id) | Def::AssociatedTy(id) |
106105
Def::TyParam(id) | Def::Struct(id) | Def::Union(id) | Def::Trait(id) |
107106
Def::Method(id) | Def::Const(id) | Def::AssociatedConst(id) |
108107
Def::Local(id) | Def::Upvar(id, ..) => {
@@ -122,7 +121,6 @@ impl Def {
122121
match *self {
123122
Def::Fn(..) => "function",
124123
Def::Mod(..) => "module",
125-
Def::ForeignMod(..) => "foreign module",
126124
Def::Static(..) => "static",
127125
Def::Variant(..) => "variant",
128126
Def::Enum(..) => "enum",

src/librustc/hir/pat_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
174174
PatKind::Path(..) |
175175
PatKind::Struct(..) => {
176176
match dm.get(&p.id) {
177-
Some(&PathResolution { base_def: Def::Variant(_, id), .. }) => {
177+
Some(&PathResolution { base_def: Def::Variant(id), .. }) => {
178178
variants.push(id);
179179
}
180180
_ => ()

src/librustc/middle/cstore.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,9 @@ pub trait CrateStore<'tcx> {
135135
fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
136136
-> ty::ClosureTy<'tcx>;
137137
fn item_variances(&self, def: DefId) -> Vec<ty::Variance>;
138-
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr>;
139138
fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
140139
-> Ty<'tcx>;
141140
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
142-
fn item_name(&self, def: DefId) -> ast::Name;
143141
fn opt_item_name(&self, def: DefId) -> Option<ast::Name>;
144142
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
145143
-> ty::GenericPredicates<'tcx>;
@@ -150,7 +148,7 @@ pub trait CrateStore<'tcx> {
150148
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
151149
fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
152150
fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>;
153-
fn method_arg_names(&self, did: DefId) -> Vec<String>;
151+
fn fn_arg_names(&self, did: DefId) -> Vec<String>;
154152
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
155153

156154
// trait info
@@ -211,7 +209,6 @@ pub trait CrateStore<'tcx> {
211209
fn def_key(&self, def: DefId) -> hir_map::DefKey;
212210
fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath>;
213211
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>;
214-
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>;
215212
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
216213
fn item_children(&self, did: DefId) -> Vec<ChildItem>;
217214

@@ -297,13 +294,11 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
297294
fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
298295
-> ty::ClosureTy<'tcx> { bug!("closure_ty") }
299296
fn item_variances(&self, def: DefId) -> Vec<ty::Variance> { bug!("item_variances") }
300-
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr> { bug!("repr_attrs") }
301297
fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
302298
-> Ty<'tcx> { bug!("item_type") }
303299
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
304300
bug!("visible_parent_map")
305301
}
306-
fn item_name(&self, def: DefId) -> ast::Name { bug!("item_name") }
307302
fn opt_item_name(&self, def: DefId) -> Option<ast::Name> { bug!("opt_item_name") }
308303
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
309304
-> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
@@ -316,7 +311,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
316311
{ bug!("trait_def") }
317312
fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>
318313
{ bug!("adt_def") }
319-
fn method_arg_names(&self, did: DefId) -> Vec<String> { bug!("method_arg_names") }
314+
fn fn_arg_names(&self, did: DefId) -> Vec<String> { bug!("fn_arg_names") }
320315
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
321316

322317
// trait info
@@ -393,8 +388,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
393388
}
394389
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
395390
{ bug!("struct_ctor_def_id") }
396-
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>
397-
{ bug!("tuple_struct_definition_if_ctor") }
398391
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
399392
fn item_children(&self, did: DefId) -> Vec<ChildItem> { bug!("item_children") }
400393

src/librustc/middle/dead.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
108108
_ if self.ignore_non_const_paths => (),
109109
Def::PrimTy(_) => (),
110110
Def::SelfTy(..) => (),
111-
Def::Variant(enum_id, variant_id) => {
112-
self.check_def_id(enum_id);
111+
Def::Variant(variant_id) => {
112+
if let Some(enum_id) = self.tcx.parent_def_id(variant_id) {
113+
self.check_def_id(enum_id);
114+
}
113115
if !self.ignore_variant_stack.contains(&variant_id) {
114116
self.check_def_id(variant_id);
115117
}

src/librustc/middle/expr_use_visitor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
10031003
// the leaves of the pattern tree structure.
10041004
return_if_err!(mc.cat_pattern(cmt_discr, pat, |mc, cmt_pat, pat| {
10051005
match tcx.expect_def_or_none(pat.id) {
1006-
Some(Def::Variant(enum_did, variant_did)) => {
1006+
Some(Def::Variant(variant_did)) => {
1007+
let enum_did = tcx.parent_def_id(variant_did).unwrap();
10071008
let downcast_cmt = if tcx.lookup_adt_def(enum_did).is_univariant() {
10081009
cmt_pat
10091010
} else {

src/librustc/middle/mem_categorization.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
529529
Ok(self.cat_rvalue_node(id, span, expr_ty))
530530
}
531531

532-
Def::Mod(_) | Def::ForeignMod(_) |
532+
Def::Mod(_) |
533533
Def::Trait(_) | Def::Enum(..) | Def::TyAlias(..) | Def::PrimTy(_) |
534534
Def::TyParam(..) |
535535
Def::Label(_) | Def::SelfTy(..) |
@@ -1077,18 +1077,23 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
10771077
// alone) because PatKind::Struct can also refer to variants.
10781078
let cmt = match self.tcx().expect_def_or_none(pat.id) {
10791079
Some(Def::Err) => return Err(()),
1080-
Some(Def::Variant(enum_did, variant_did))
1080+
Some(Def::Variant(variant_did)) => {
10811081
// univariant enums do not need downcasts
1082-
if !self.tcx().lookup_adt_def(enum_did).is_univariant() => {
1082+
let enum_did = self.tcx().parent_def_id(variant_did).unwrap();
1083+
if !self.tcx().lookup_adt_def(enum_did).is_univariant() {
10831084
self.cat_downcast(pat, cmt.clone(), cmt.ty, variant_did)
1085+
} else {
1086+
cmt
10841087
}
1088+
}
10851089
_ => cmt
10861090
};
10871091

10881092
match pat.node {
10891093
PatKind::TupleStruct(_, ref subpats, ddpos) => {
10901094
let expected_len = match self.tcx().expect_def(pat.id) {
1091-
Def::Variant(enum_def, def_id) => {
1095+
Def::Variant(def_id) => {
1096+
let enum_def = self.tcx().parent_def_id(def_id).unwrap();
10921097
self.tcx().lookup_adt_def(enum_def).variant_with_id(def_id).fields.len()
10931098
}
10941099
Def::Struct(..) => {

src/librustc/ty/context.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,13 +1404,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14041404
/// Obtain the representation annotation for a struct definition.
14051405
pub fn lookup_repr_hints(self, did: DefId) -> Rc<Vec<attr::ReprAttr>> {
14061406
self.repr_hint_cache.memoize(did, || {
1407-
Rc::new(if did.is_local() {
1408-
self.get_attrs(did).iter().flat_map(|meta| {
1409-
attr::find_repr_attrs(self.sess.diagnostic(), meta).into_iter()
1410-
}).collect()
1411-
} else {
1412-
self.sess.cstore.repr_attrs(did)
1413-
})
1407+
Rc::new(self.get_attrs(did).iter().flat_map(|meta| {
1408+
attr::find_repr_attrs(self.sess.diagnostic(), meta).into_iter()
1409+
}).collect())
14141410
})
14151411
}
14161412
}

src/librustc/ty/item_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
303303
/// Returns the def-id of `def_id`'s parent in the def tree. If
304304
/// this returns `None`, then `def_id` represents a crate root or
305305
/// inlined root.
306-
fn parent_def_id(&self, def_id: DefId) -> Option<DefId> {
306+
pub fn parent_def_id(self, def_id: DefId) -> Option<DefId> {
307307
let key = self.def_key(def_id);
308308
key.parent.map(|index| DefId { krate: def_id.krate, index: index })
309309
}

src/librustc/ty/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'tcx> ImplOrTraitItem<'tcx> {
193193
match *self {
194194
ConstTraitItem(ref associated_const) => Def::AssociatedConst(associated_const.def_id),
195195
MethodTraitItem(ref method) => Def::Method(method.def_id),
196-
TypeTraitItem(ref ty) => Def::AssociatedTy(ty.container.id(), ty.def_id),
196+
TypeTraitItem(ref ty) => Def::AssociatedTy(ty.def_id),
197197
}
198198
}
199199

@@ -1666,7 +1666,7 @@ impl<'a, 'gcx, 'tcx, 'container> AdtDefData<'gcx, 'container> {
16661666

16671667
pub fn variant_of_def(&self, def: Def) -> &VariantDefData<'gcx, 'container> {
16681668
match def {
1669-
Def::Variant(_, vid) => self.variant_with_id(vid),
1669+
Def::Variant(vid) => self.variant_with_id(vid),
16701670
Def::Struct(..) | Def::Union(..) |
16711671
Def::TyAlias(..) | Def::AssociatedTy(..) => self.struct_variant(),
16721672
_ => bug!("unexpected def {:?} in variant_of_def", def)
@@ -2325,7 +2325,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23252325
// or variant or their constructors, panics otherwise.
23262326
pub fn expect_variant_def(self, def: Def) -> VariantDef<'tcx> {
23272327
match def {
2328-
Def::Variant(enum_did, did) => {
2328+
Def::Variant(did) => {
2329+
let enum_did = self.parent_def_id(did).unwrap();
23292330
self.lookup_adt_def(enum_did).variant_with_id(did)
23302331
}
23312332
Def::Struct(did) | Def::Union(did) => {
@@ -2387,7 +2388,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23872388
if let Some(id) = self.map.as_local_node_id(id) {
23882389
self.map.name(id)
23892390
} else {
2390-
self.sess.cstore.item_name(id)
2391+
self.sess.cstore.opt_item_name(id).unwrap_or_else(|| {
2392+
bug!("item_name: no name for {:?}", self.def_path(id));
2393+
})
23912394
}
23922395
}
23932396

@@ -2631,11 +2634,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26312634
let trait_ref = self.impl_trait_ref(impl_def_id).unwrap();
26322635

26332636
// Record the trait->implementation mapping.
2634-
if let Some(parent) = self.sess.cstore.impl_parent(impl_def_id) {
2635-
def.record_remote_impl(self, impl_def_id, trait_ref, parent);
2636-
} else {
2637-
def.record_remote_impl(self, impl_def_id, trait_ref, trait_id);
2638-
}
2637+
let parent = self.sess.cstore.impl_parent(impl_def_id).unwrap_or(trait_id);
2638+
def.record_remote_impl(self, impl_def_id, trait_ref, parent);
26392639

26402640
// For any methods that use a default implementation, add them to
26412641
// the map. This is a bit unfortunate.

src/librustc_const_eval/check_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
801801
match pat.node {
802802
PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) =>
803803
match cx.tcx.expect_def(pat.id) {
804-
Def::Variant(_, id) => vec![Variant(id)],
804+
Def::Variant(id) => vec![Variant(id)],
805805
Def::Struct(..) | Def::Union(..) |
806806
Def::TyAlias(..) | Def::AssociatedTy(..) => vec![Single],
807807
Def::Const(..) | Def::AssociatedConst(..) =>
@@ -913,7 +913,7 @@ pub fn specialize<'a, 'b, 'tcx>(
913913
Def::Const(..) | Def::AssociatedConst(..) =>
914914
span_bug!(pat_span, "const pattern should've \
915915
been rewritten"),
916-
Def::Variant(_, id) if *constructor != Variant(id) => None,
916+
Def::Variant(id) if *constructor != Variant(id) => None,
917917
Def::Variant(..) | Def::Struct(..) => Some(Vec::new()),
918918
def => span_bug!(pat_span, "specialize: unexpected \
919919
definition {:?}", def),
@@ -925,7 +925,7 @@ pub fn specialize<'a, 'b, 'tcx>(
925925
Def::Const(..) | Def::AssociatedConst(..) =>
926926
span_bug!(pat_span, "const pattern should've \
927927
been rewritten"),
928-
Def::Variant(_, id) if *constructor != Variant(id) => None,
928+
Def::Variant(id) if *constructor != Variant(id) => None,
929929
Def::Variant(..) | Def::Struct(..) => {
930930
match ddpos {
931931
Some(ddpos) => {

src/librustc_const_eval/eval.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ macro_rules! math {
5757
}
5858

5959
fn lookup_variant_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
60-
enum_def: DefId,
6160
variant_def: DefId)
6261
-> Option<&'tcx Expr> {
6362
fn variant_expr<'a>(variants: &'a [hir::Variant], id: ast::NodeId)
@@ -70,8 +69,8 @@ fn lookup_variant_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7069
None
7170
}
7271

73-
if let Some(enum_node_id) = tcx.map.as_local_node_id(enum_def) {
74-
let variant_node_id = tcx.map.as_local_node_id(variant_def).unwrap();
72+
if let Some(variant_node_id) = tcx.map.as_local_node_id(variant_def) {
73+
let enum_node_id = tcx.map.get_parent(variant_node_id);
7574
match tcx.map.find(enum_node_id) {
7675
None => None,
7776
Some(ast_map::NodeItem(it)) => match it.node {
@@ -289,7 +288,7 @@ pub fn const_expr_to_pat<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
289288
}
290289
let path = match def {
291290
Def::Struct(def_id) => def_to_path(tcx, def_id),
292-
Def::Variant(_, variant_did) => def_to_path(tcx, variant_did),
291+
Def::Variant(variant_did) => def_to_path(tcx, variant_did),
293292
Def::Fn(..) | Def::Method(..) => return Ok(P(hir::Pat {
294293
id: expr.id,
295294
node: PatKind::Lit(P(expr.clone())),
@@ -808,8 +807,8 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
808807
signal!(e, NonConstPath);
809808
}
810809
},
811-
Def::Variant(enum_def, variant_def) => {
812-
if let Some(const_expr) = lookup_variant_by_id(tcx, enum_def, variant_def) {
810+
Def::Variant(variant_def) => {
811+
if let Some(const_expr) = lookup_variant_by_id(tcx, variant_def) {
813812
match eval_const_expr_partial(tcx, const_expr, ty_hint, None) {
814813
Ok(val) => val,
815814
Err(err) => {

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
602602
// def-id is the same, so it suffices to hash the def-id
603603
Def::Fn(..) |
604604
Def::Mod(..) |
605-
Def::ForeignMod(..) |
606605
Def::Static(..) |
607606
Def::Variant(..) |
608607
Def::Enum(..) |

src/librustc_metadata/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cstore::CrateMetadata;
1818
use decoder::DecodeContext;
1919
use encoder::EncodeContext;
2020

21-
use middle::cstore::{InlinedItem, InlinedItemRef};
21+
use rustc::middle::cstore::{InlinedItem, InlinedItemRef};
2222
use rustc::hir::def;
2323
use rustc::hir::def_id::DefId;
2424
use rustc::ty::TyCtxt;

0 commit comments

Comments
 (0)