1
1
use decoder:: Metadata ;
2
- use table:: PerDefTable ;
2
+ use table:: { Table , TableBuilder } ;
3
3
4
4
use rustc:: hir;
5
5
use rustc:: hir:: def:: { self , CtorKind } ;
@@ -15,7 +15,7 @@ use rustc_target::spec::{PanicStrategy, TargetTriple};
15
15
use rustc_index:: vec:: IndexVec ;
16
16
use rustc_data_structures:: svh:: Svh ;
17
17
use rustc_data_structures:: sync:: MetadataRef ;
18
- use rustc_serialize:: Encodable ;
18
+ use rustc_serialize:: opaque :: Encoder ;
19
19
use syntax:: { ast, attr} ;
20
20
use syntax:: edition:: Edition ;
21
21
use syntax:: symbol:: Symbol ;
@@ -59,7 +59,7 @@ trait LazyMeta {
59
59
fn min_size ( meta : Self :: Meta ) -> usize ;
60
60
}
61
61
62
- impl < T : Encodable > LazyMeta for T {
62
+ impl < T > LazyMeta for T {
63
63
type Meta = ( ) ;
64
64
65
65
fn min_size ( _: ( ) ) -> usize {
@@ -68,7 +68,7 @@ impl<T: Encodable> LazyMeta for T {
68
68
}
69
69
}
70
70
71
- impl < T : Encodable > LazyMeta for [ T ] {
71
+ impl < T > LazyMeta for [ T ] {
72
72
type Meta = usize ;
73
73
74
74
fn min_size ( len : usize ) -> usize {
@@ -124,13 +124,13 @@ impl<T: ?Sized + LazyMeta> Lazy<T> {
124
124
}
125
125
}
126
126
127
- impl < T : Encodable > Lazy < T > {
127
+ impl < T > Lazy < T > {
128
128
fn from_position ( position : NonZeroUsize ) -> Lazy < T > {
129
129
Lazy :: from_position_and_meta ( position, ( ) )
130
130
}
131
131
}
132
132
133
- impl < T : Encodable > Lazy < [ T ] > {
133
+ impl < T > Lazy < [ T ] > {
134
134
fn empty ( ) -> Lazy < [ T ] > {
135
135
Lazy :: from_position_and_meta ( NonZeroUsize :: new ( 1 ) . unwrap ( ) , 0 )
136
136
}
@@ -166,8 +166,7 @@ enum LazyState {
166
166
// manually, instead of relying on the default, to get the correct variance.
167
167
// Only needed when `T` itself contains a parameter (e.g. `'tcx`).
168
168
macro_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 >} ;
171
170
( [ $T: ty] ) => { Lazy <[ $T] , usize >} ;
172
171
( $T: ty) => { Lazy <$T, ( ) >} ;
173
172
}
@@ -232,31 +231,53 @@ crate struct TraitImpls {
232
231
impls : Lazy < [ DefIndex ] > ,
233
232
}
234
233
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>) >,
251
272
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
252
273
// doesn't handle shorthands in its own (de)serialization impls,
253
274
// as it's an `enum` for which we want to derive (de)serialization,
254
275
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
255
276
// 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>>) >,
260
281
}
261
282
262
283
#[ derive( Copy , Clone , RustcEncodable , RustcDecodable ) ]
0 commit comments