11use decoder:: Metadata ;
2- use table:: PerDefTable ;
2+ use table:: { Table , TableBuilder } ;
33
44use rustc:: hir;
55use rustc:: hir:: def:: { self , CtorKind } ;
@@ -15,7 +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:: Encodable ;
18+ use rustc_serialize:: opaque :: Encoder ;
1919use syntax:: { ast, attr} ;
2020use syntax:: edition:: Edition ;
2121use syntax:: symbol:: Symbol ;
@@ -59,7 +59,7 @@ trait LazyMeta {
5959 fn min_size ( meta : Self :: Meta ) -> usize ;
6060}
6161
62- impl < T : Encodable > LazyMeta for T {
62+ impl < T > LazyMeta for T {
6363 type Meta = ( ) ;
6464
6565 fn min_size ( _: ( ) ) -> usize {
@@ -68,7 +68,7 @@ impl<T: Encodable> LazyMeta for T {
6868 }
6969}
7070
71- impl < T : Encodable > LazyMeta for [ T ] {
71+ impl < T > LazyMeta for [ T ] {
7272 type Meta = usize ;
7373
7474 fn min_size ( len : usize ) -> usize {
@@ -124,13 +124,13 @@ impl<T: ?Sized + LazyMeta> Lazy<T> {
124124 }
125125}
126126
127- impl < T : Encodable > Lazy < T > {
127+ impl < T > Lazy < T > {
128128 fn from_position ( position : NonZeroUsize ) -> Lazy < T > {
129129 Lazy :: from_position_and_meta ( position, ( ) )
130130 }
131131}
132132
133- impl < T : Encodable > Lazy < [ T ] > {
133+ impl < T > Lazy < [ T ] > {
134134 fn empty ( ) -> Lazy < [ T ] > {
135135 Lazy :: from_position_and_meta ( NonZeroUsize :: new ( 1 ) . unwrap ( ) , 0 )
136136 }
@@ -166,8 +166,7 @@ enum LazyState {
166166// manually, instead of relying on the default, to get the correct variance.
167167// Only needed when `T` itself contains a parameter (e.g. `'tcx`).
168168macro_rules! Lazy {
169- ( Table <$T: ty>) => { Lazy <Table <$T>, usize >} ;
170- ( PerDefTable <$T: ty>) => { Lazy <PerDefTable <$T>, usize >} ;
169+ ( Table <$I: ty, $T: ty>) => { Lazy <Table <$I, $T>, usize >} ;
171170 ( [ $T: ty] ) => { Lazy <[ $T] , usize >} ;
172171 ( $T: ty) => { Lazy <$T, ( ) >} ;
173172}
@@ -232,31 +231,53 @@ crate struct TraitImpls {
232231 impls : Lazy < [ DefIndex ] > ,
233232}
234233
235- #[ derive( RustcEncodable , RustcDecodable ) ]
236- crate struct LazyPerDefTables < ' tcx > {
237- kind : Lazy ! ( PerDefTable <Lazy !( EntryKind <' tcx>) >) ,
238- visibility : Lazy ! ( PerDefTable <Lazy <ty:: Visibility >>) ,
239- span : Lazy ! ( PerDefTable <Lazy <Span >>) ,
240- attributes : Lazy ! ( PerDefTable <Lazy <[ ast:: Attribute ] >>) ,
241- children : Lazy ! ( PerDefTable <Lazy <[ DefIndex ] >>) ,
242- stability : Lazy ! ( PerDefTable <Lazy <attr:: Stability >>) ,
243- deprecation : Lazy ! ( PerDefTable <Lazy <attr:: Deprecation >>) ,
244- ty : Lazy ! ( PerDefTable <Lazy !( Ty <' tcx>) >) ,
245- fn_sig : Lazy ! ( PerDefTable <Lazy !( ty:: PolyFnSig <' tcx>) >) ,
246- impl_trait_ref : Lazy ! ( PerDefTable <Lazy !( ty:: TraitRef <' tcx>) >) ,
247- inherent_impls : Lazy ! ( PerDefTable <Lazy <[ DefIndex ] >>) ,
248- variances : Lazy ! ( PerDefTable <Lazy <[ ty:: Variance ] >>) ,
249- generics : Lazy ! ( PerDefTable <Lazy <ty:: Generics >>) ,
250- explicit_predicates : Lazy ! ( PerDefTable <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>) >,
251272 // FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
252273 // doesn't handle shorthands in its own (de)serialization impls,
253274 // as it's an `enum` for which we want to derive (de)serialization,
254275 // so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
255276 // Also, as an optimization, a missing entry indicates an empty `&[]`.
256- inferred_outlives : Lazy ! ( PerDefTable < Lazy !( & ' tcx [ ( ty:: Predicate <' tcx>, Span ) ] ) >) ,
257- super_predicates : Lazy ! ( PerDefTable < Lazy !( ty:: GenericPredicates <' tcx>) >) ,
258- mir : Lazy ! ( PerDefTable < Lazy !( mir:: Body <' tcx>) >) ,
259- promoted_mir : Lazy ! ( PerDefTable < 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>>) >,
260281}
261282
262283#[ derive( Copy , Clone , RustcEncodable , RustcDecodable ) ]
0 commit comments