Skip to content

Commit 8734aaa

Browse files
committed
rustc_metadata: move more RBML tags to auto-serialization.
1 parent 88c5679 commit 8734aaa

File tree

40 files changed

+1077
-2132
lines changed

40 files changed

+1077
-2132
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,13 @@ pub enum DepNode<D: Clone + Debug> {
103103
// table in the tcx (or elsewhere) maps to one of these
104104
// nodes. Often we map multiple tables to the same node if there
105105
// is no point in distinguishing them (e.g., both the type and
106-
// predicates for an item wind up in `ItemSignature`). Other
107-
// times, such as `ImplItems` vs `TraitItemDefIds`, tables which
108-
// might be mergable are kept distinct because the sets of def-ids
109-
// to which they apply are disjoint, and hence we might as well
110-
// have distinct labels for easier debugging.
106+
// predicates for an item wind up in `ItemSignature`).
111107
ImplOrTraitItems(D),
112108
ItemSignature(D),
113109
FieldTy(D),
114110
SizedConstraint(D),
115-
TraitItemDefIds(D),
111+
ImplOrTraitItemIds(D),
116112
InherentImpls(D),
117-
ImplItems(D),
118113

119114
// The set of impls for a given trait. Ultimately, it would be
120115
// nice to get more fine-grained here (e.g., to include a
@@ -162,9 +157,8 @@ impl<D: Clone + Debug> DepNode<D> {
162157
ImplOrTraitItems,
163158
ItemSignature,
164159
FieldTy,
165-
TraitItemDefIds,
160+
ImplOrTraitItemIds,
166161
InherentImpls,
167-
ImplItems,
168162
TraitImpls,
169163
ReprHints,
170164
}
@@ -231,9 +225,8 @@ impl<D: Clone + Debug> DepNode<D> {
231225
ItemSignature(ref d) => op(d).map(ItemSignature),
232226
FieldTy(ref d) => op(d).map(FieldTy),
233227
SizedConstraint(ref d) => op(d).map(SizedConstraint),
234-
TraitItemDefIds(ref d) => op(d).map(TraitItemDefIds),
228+
ImplOrTraitItemIds(ref d) => op(d).map(ImplOrTraitItemIds),
235229
InherentImpls(ref d) => op(d).map(InherentImpls),
236-
ImplItems(ref d) => op(d).map(ImplItems),
237230
TraitImpls(ref d) => op(d).map(TraitImpls),
238231
TraitItems(ref d) => op(d).map(TraitItems),
239232
ReprHints(ref d) => op(d).map(ReprHints),

src/librustc/hir/def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub type DefMap = NodeMap<PathResolution>;
9292
// within.
9393
pub type ExportMap = NodeMap<Vec<Export>>;
9494

95-
#[derive(Copy, Clone)]
95+
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
9696
pub struct Export {
9797
pub name: ast::Name, // The name of the target.
9898
pub def_id: DefId, // The definition of the target.

src/librustc/hir/map/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,22 +580,24 @@ impl<'ast> Map<'ast> {
580580
}
581581
}
582582

583-
pub fn expect_struct(&self, id: NodeId) -> &'ast VariantData {
583+
pub fn expect_variant_data(&self, id: NodeId) -> &'ast VariantData {
584584
match self.find(id) {
585585
Some(NodeItem(i)) => {
586586
match i.node {
587-
ItemStruct(ref struct_def, _) => struct_def,
588-
_ => bug!("struct ID bound to non-struct")
587+
ItemStruct(ref struct_def, _) |
588+
ItemUnion(ref struct_def, _) => struct_def,
589+
_ => {
590+
bug!("struct ID bound to non-struct {}",
591+
self.node_to_string(id));
592+
}
589593
}
590594
}
591-
Some(NodeVariant(variant)) => {
592-
if variant.node.data.is_struct() {
593-
&variant.node.data
594-
} else {
595-
bug!("struct ID bound to enum variant that isn't struct-like")
596-
}
595+
Some(NodeStructCtor(data)) => data,
596+
Some(NodeVariant(variant)) => &variant.node.data,
597+
_ => {
598+
bug!("expected struct or variant, found {}",
599+
self.node_to_string(id));
597600
}
598-
_ => bug!("expected struct, found {}", self.node_to_string(id)),
599601
}
600602
}
601603

src/librustc/middle/cstore.rs

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ use hir::map as hir_map;
2828
use hir::map::definitions::DefKey;
2929
use hir::svh::Svh;
3030
use middle::lang_items;
31-
use ty::{self, Ty, TyCtxt, VariantKind};
31+
use ty::{self, Ty, TyCtxt};
3232
use mir::repr::Mir;
3333
use mir::mir_map::MirMap;
3434
use session::Session;
3535
use session::config::PanicStrategy;
3636
use session::search_paths::PathKind;
37-
use util::nodemap::{FnvHashMap, NodeSet, DefIdMap};
38-
use std::rc::Rc;
37+
use util::nodemap::{NodeSet, DefIdMap};
3938
use std::path::PathBuf;
4039
use syntax::ast;
4140
use syntax::attr;
@@ -47,7 +46,6 @@ use rustc_back::target::Target;
4746
use hir;
4847
use hir::intravisit::Visitor;
4948

50-
pub use self::DefLike::{DlDef, DlField, DlImpl};
5149
pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
5250

5351
// lonely orphan structs and enums looking for a better home
@@ -67,27 +65,17 @@ pub struct CrateSource {
6765
pub cnum: CrateNum,
6866
}
6967

70-
#[derive(Copy, Debug, PartialEq, Clone)]
68+
#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
7169
pub enum LinkagePreference {
7270
RequireDynamic,
7371
RequireStatic,
7472
}
7573

76-
enum_from_u32! {
77-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
78-
pub enum NativeLibraryKind {
79-
NativeStatic, // native static library (.a archive)
80-
NativeFramework, // OSX-specific
81-
NativeUnknown, // default way to specify a dynamic library
82-
}
83-
}
84-
85-
// Something that a name can resolve to.
86-
#[derive(Copy, Clone, Debug)]
87-
pub enum DefLike {
88-
DlDef(Def),
89-
DlImpl(DefId),
90-
DlField
74+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
75+
pub enum NativeLibraryKind {
76+
NativeStatic, // native static library (.a archive)
77+
NativeFramework, // OSX-specific
78+
NativeUnknown, // default way to specify a dynamic library
9179
}
9280

9381
/// The data we save and restore about an inlined item or method. This is not
@@ -110,7 +98,7 @@ pub enum InlinedItemRef<'a> {
11098

11199
#[derive(Copy, Clone)]
112100
pub struct ChildItem {
113-
pub def: DefLike,
101+
pub def: Def,
114102
pub name: ast::Name,
115103
pub vis: ty::Visibility,
116104
}
@@ -166,21 +154,15 @@ pub trait CrateStore<'tcx> {
166154
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
167155

168156
// trait info
169-
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId>;
170-
fn provided_trait_methods<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
171-
-> Vec<Rc<ty::Method<'tcx>>>;
172-
fn trait_item_def_ids(&self, def: DefId)
173-
-> Vec<ty::ImplOrTraitItemId>;
157+
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
174158

175159
// impl info
176-
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
160+
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
177161
fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
178162
-> Option<ty::TraitRef<'tcx>>;
179-
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity>;
163+
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
180164
fn custom_coerce_unsized_kind(&self, def: DefId)
181165
-> Option<ty::adjustment::CustomCoerceUnsized>;
182-
fn associated_consts<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
183-
-> Vec<Rc<ty::AssociatedConst<'tcx>>>;
184166
fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;
185167

186168
// trait/impl-item info
@@ -191,12 +173,10 @@ pub trait CrateStore<'tcx> {
191173
// flags
192174
fn is_const_fn(&self, did: DefId) -> bool;
193175
fn is_defaulted_trait(&self, did: DefId) -> bool;
194-
fn is_impl(&self, did: DefId) -> bool;
195176
fn is_default_impl(&self, impl_did: DefId) -> bool;
196177
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool;
197178
fn is_foreign_item(&self, did: DefId) -> bool;
198179
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
199-
fn is_typedef(&self, did: DefId) -> bool;
200180

201181
// crate metadata
202182
fn dylib_dependency_formats(&self, cnum: CrateNum)
@@ -218,8 +198,6 @@ pub trait CrateStore<'tcx> {
218198
fn original_crate_name(&self, cnum: CrateNum) -> InternedString;
219199
fn crate_hash(&self, cnum: CrateNum) -> Svh;
220200
fn crate_disambiguator(&self, cnum: CrateNum) -> InternedString;
221-
fn crate_struct_field_attrs(&self, cnum: CrateNum)
222-
-> FnvHashMap<DefId, Vec<ast::Attribute>>;
223201
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
224202
fn native_libraries(&self, cnum: CrateNum) -> Vec<(NativeLibraryKind, String)>;
225203
fn reachable_ids(&self, cnum: CrateNum) -> Vec<DefId>;
@@ -232,12 +210,10 @@ pub trait CrateStore<'tcx> {
232210
-> Option<DefIndex>;
233211
fn def_key(&self, def: DefId) -> hir_map::DefKey;
234212
fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath>;
235-
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind>;
236213
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>;
237214
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>;
238215
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
239216
fn item_children(&self, did: DefId) -> Vec<ChildItem>;
240-
fn crate_top_level_items(&self, cnum: CrateNum) -> Vec<ChildItem>;
241217

242218
// misc. metadata
243219
fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
@@ -344,11 +320,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
344320
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
345321

346322
// trait info
347-
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId> { vec![] }
348-
fn provided_trait_methods<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
349-
-> Vec<Rc<ty::Method<'tcx>>> { bug!("provided_trait_methods") }
350-
fn trait_item_def_ids(&self, def: DefId)
351-
-> Vec<ty::ImplOrTraitItemId> { bug!("trait_item_def_ids") }
323+
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] }
352324
fn def_index_for_def_key(&self,
353325
cnum: CrateNum,
354326
def: DefKey)
@@ -357,16 +329,14 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
357329
}
358330

359331
// impl info
360-
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
361-
{ bug!("impl_items") }
332+
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
333+
{ bug!("impl_or_trait_items") }
362334
fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
363335
-> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }
364-
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity> { bug!("impl_polarity") }
336+
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity { bug!("impl_polarity") }
365337
fn custom_coerce_unsized_kind(&self, def: DefId)
366338
-> Option<ty::adjustment::CustomCoerceUnsized>
367339
{ bug!("custom_coerce_unsized_kind") }
368-
fn associated_consts<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
369-
-> Vec<Rc<ty::AssociatedConst<'tcx>>> { bug!("associated_consts") }
370340
fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }
371341

372342
// trait/impl-item info
@@ -377,13 +347,11 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
377347
// flags
378348
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
379349
fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
380-
fn is_impl(&self, did: DefId) -> bool { bug!("is_impl") }
381350
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
382351
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool
383352
{ bug!("is_extern_item") }
384353
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
385354
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
386-
fn is_typedef(&self, did: DefId) -> bool { bug!("is_typedef") }
387355

388356
// crate metadata
389357
fn dylib_dependency_formats(&self, cnum: CrateNum)
@@ -411,9 +379,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
411379
fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
412380
fn crate_disambiguator(&self, cnum: CrateNum)
413381
-> InternedString { bug!("crate_disambiguator") }
414-
fn crate_struct_field_attrs(&self, cnum: CrateNum)
415-
-> FnvHashMap<DefId, Vec<ast::Attribute>>
416-
{ bug!("crate_struct_field_attrs") }
417382
fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
418383
{ bug!("plugin_registrar_fn") }
419384
fn native_libraries(&self, cnum: CrateNum) -> Vec<(NativeLibraryKind, String)>
@@ -426,15 +391,12 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
426391
fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath> {
427392
bug!("relative_def_path")
428393
}
429-
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind> { bug!("variant_kind") }
430394
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
431395
{ bug!("struct_ctor_def_id") }
432396
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>
433397
{ bug!("tuple_struct_definition_if_ctor") }
434398
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
435399
fn item_children(&self, did: DefId) -> Vec<ChildItem> { bug!("item_children") }
436-
fn crate_top_level_items(&self, cnum: CrateNum) -> Vec<ChildItem>
437-
{ bug!("crate_top_level_items") }
438400

439401
// misc. metadata
440402
fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
470470
// This is done to handle the case where, for example, the static
471471
// method of a private type is used, but the type itself is never
472472
// called directly.
473-
let impl_items = self.tcx.impl_items.borrow();
473+
let impl_items = self.tcx.impl_or_trait_item_ids.borrow();
474474
if let Some(impl_list) =
475475
self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) {
476476
for impl_did in impl_list.iter() {

src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ macro_rules! language_item_table {
4343

4444

4545
enum_from_u32! {
46-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
46+
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
4747
pub enum LangItem {
4848
$($variant,)*
4949
}

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl Passes {
493493
}
494494
}
495495

496-
#[derive(Clone, PartialEq, Hash)]
496+
#[derive(Clone, PartialEq, Hash, RustcEncodable, RustcDecodable)]
497497
pub enum PanicStrategy {
498498
Unwind,
499499
Abort,

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
814814
fn filter_negative_impls(&self, candidate: SelectionCandidate<'tcx>)
815815
-> SelectionResult<'tcx, SelectionCandidate<'tcx>> {
816816
if let ImplCandidate(def_id) = candidate {
817-
if self.tcx().trait_impl_polarity(def_id) == Some(hir::ImplPolarity::Negative) {
817+
if self.tcx().trait_impl_polarity(def_id) == hir::ImplPolarity::Negative {
818818
return Err(Unimplemented)
819819
}
820820
}

0 commit comments

Comments
 (0)