1
1
use decoder:: Metadata ;
2
- use table:: Table ;
2
+ use table:: { Table , TableBuilder } ;
3
3
4
4
use rustc:: hir;
5
5
use rustc:: hir:: def:: { self , CtorKind } ;
@@ -15,6 +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:: opaque:: Encoder ;
18
19
use syntax:: { ast, attr} ;
19
20
use syntax:: edition:: Edition ;
20
21
use syntax:: symbol:: Symbol ;
@@ -230,31 +231,53 @@ crate struct TraitImpls {
230
231
impls : Lazy < [ DefIndex ] > ,
231
232
}
232
233
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>) >,
249
272
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
250
273
// doesn't handle shorthands in its own (de)serialization impls,
251
274
// as it's an `enum` for which we want to derive (de)serialization,
252
275
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
253
276
// 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>>) >,
258
281
}
259
282
260
283
#[ derive( Copy , Clone , RustcEncodable , RustcDecodable ) ]
0 commit comments