11use decoder:: Metadata ;
2- use table:: Table ;
2+ use table:: { Table , TableBuilder } ;
33
44use rustc:: hir;
55use rustc:: hir:: def:: { self , CtorKind } ;
@@ -15,6 +15,7 @@ use rustc_target::spec::{PanicStrategy, TargetTriple};
1515use rustc_index:: vec:: IndexVec ;
1616use rustc_data_structures:: svh:: Svh ;
1717use rustc_data_structures:: sync:: MetadataRef ;
18+ use rustc_serialize:: opaque:: Encoder ;
1819use syntax:: { ast, attr} ;
1920use syntax:: edition:: Edition ;
2021use syntax:: symbol:: Symbol ;
@@ -230,31 +231,53 @@ crate struct TraitImpls {
230231 impls : Lazy < [ DefIndex ] > ,
231232}
232233
233- #[ derive( RustcEncodable , RustcDecodable ) ]
234- crate struct LazyPerDefTables < ' tcx > {
235- kind : Lazy ! ( Table <DefIndex , Lazy !( EntryKind <' tcx>) >) ,
236- visibility : Lazy ! ( Table <DefIndex , Lazy <ty:: Visibility >>) ,
237- span : Lazy ! ( Table <DefIndex , Lazy <Span >>) ,
238- attributes : Lazy ! ( Table <DefIndex , Lazy <[ ast:: Attribute ] >>) ,
239- children : Lazy ! ( Table <DefIndex , Lazy <[ DefIndex ] >>) ,
240- stability : Lazy ! ( Table <DefIndex , Lazy <attr:: Stability >>) ,
241- deprecation : Lazy ! ( Table <DefIndex , Lazy <attr:: Deprecation >>) ,
242- ty : Lazy ! ( Table <DefIndex , Lazy !( Ty <' tcx>) >) ,
243- fn_sig : Lazy ! ( Table <DefIndex , Lazy !( ty:: PolyFnSig <' tcx>) >) ,
244- impl_trait_ref : Lazy ! ( Table <DefIndex , Lazy !( ty:: TraitRef <' tcx>) >) ,
245- inherent_impls : Lazy ! ( Table <DefIndex , Lazy <[ DefIndex ] >>) ,
246- variances : Lazy ! ( Table <DefIndex , Lazy <[ ty:: Variance ] >>) ,
247- generics : Lazy ! ( Table <DefIndex , Lazy <ty:: Generics >>) ,
248- explicit_predicates : Lazy ! ( Table <DefIndex , Lazy !( ty:: GenericPredicates <' tcx>) >) ,
234+ /// Define `LazyPerDefTables` and `PerDefTableBuilders` at the same time.
235+ macro_rules! define_per_def_tables {
236+ ( $( $name: ident: Table <DefIndex , $T: ty>) ,+ $( , ) ?) => {
237+ #[ derive( RustcEncodable , RustcDecodable ) ]
238+ crate struct LazyPerDefTables <' tcx> {
239+ $( $name: Lazy !( Table <DefIndex , $T>) ) ,+
240+ }
241+
242+ #[ derive( Default ) ]
243+ struct PerDefTableBuilders <' tcx> {
244+ $( $name: TableBuilder <DefIndex , $T>) ,+
245+ }
246+
247+ impl PerDefTableBuilders <' tcx> {
248+ fn encode( & self , buf: & mut Encoder ) -> LazyPerDefTables <' tcx> {
249+ LazyPerDefTables {
250+ $( $name: self . $name. encode( buf) ) ,+
251+ }
252+ }
253+ }
254+ }
255+ }
256+
257+ define_per_def_tables ! {
258+ kind: Table <DefIndex , Lazy !( EntryKind <' tcx>) >,
259+ visibility: Table <DefIndex , Lazy <ty:: Visibility >>,
260+ span: Table <DefIndex , Lazy <Span >>,
261+ attributes: Table <DefIndex , Lazy <[ ast:: Attribute ] >>,
262+ children: Table <DefIndex , Lazy <[ DefIndex ] >>,
263+ stability: Table <DefIndex , Lazy <attr:: Stability >>,
264+ deprecation: Table <DefIndex , Lazy <attr:: Deprecation >>,
265+ ty: Table <DefIndex , Lazy !( Ty <' tcx>) >,
266+ fn_sig: Table <DefIndex , Lazy !( ty:: PolyFnSig <' tcx>) >,
267+ impl_trait_ref: Table <DefIndex , Lazy !( ty:: TraitRef <' tcx>) >,
268+ inherent_impls: Table <DefIndex , Lazy <[ DefIndex ] >>,
269+ variances: Table <DefIndex , Lazy <[ ty:: Variance ] >>,
270+ generics: Table <DefIndex , Lazy <ty:: Generics >>,
271+ explicit_predicates: Table <DefIndex , Lazy !( ty:: GenericPredicates <' tcx>) >,
249272 // FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
250273 // doesn't handle shorthands in its own (de)serialization impls,
251274 // as it's an `enum` for which we want to derive (de)serialization,
252275 // so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
253276 // Also, as an optimization, a missing entry indicates an empty `&[]`.
254- inferred_outlives : Lazy ! ( Table <DefIndex , Lazy !( & ' tcx [ ( ty:: Predicate <' tcx>, Span ) ] ) >) ,
255- super_predicates : Lazy ! ( Table <DefIndex , Lazy !( ty:: GenericPredicates <' tcx>) >) ,
256- mir : Lazy ! ( Table <DefIndex , Lazy !( mir:: Body <' tcx>) >) ,
257- promoted_mir : Lazy ! ( Table <DefIndex , Lazy !( IndexVec <mir:: Promoted , mir:: Body <' tcx>>) >) ,
277+ inferred_outlives: Table <DefIndex , Lazy !( & ' tcx [ ( ty:: Predicate <' tcx>, Span ) ] ) >,
278+ super_predicates: Table <DefIndex , Lazy !( ty:: GenericPredicates <' tcx>) >,
279+ mir: Table <DefIndex , Lazy !( mir:: Body <' tcx>) >,
280+ promoted_mir: Table <DefIndex , Lazy !( IndexVec <mir:: Promoted , mir:: Body <' tcx>>) >,
258281}
259282
260283#[ derive( Copy , Clone , RustcEncodable , RustcDecodable ) ]
0 commit comments