@@ -11,7 +11,6 @@ use rustc_data_structures::fx::FxHashMap;
11
11
use rustc_data_structures:: svh:: Svh ;
12
12
use rustc_data_structures:: sync:: { Lock , LockGuard , Lrc , OnceCell } ;
13
13
use rustc_data_structures:: unhash:: UnhashMap ;
14
- use rustc_errors:: ErrorReported ;
15
14
use rustc_expand:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
16
15
use rustc_expand:: proc_macro:: { AttrProcMacro , BangProcMacro , ProcMacroDerive } ;
17
16
use rustc_hir as hir;
@@ -21,10 +20,12 @@ use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
21
20
use rustc_hir:: diagnostic_items:: DiagnosticItems ;
22
21
use rustc_hir:: lang_items;
23
22
use rustc_index:: vec:: { Idx , IndexVec } ;
23
+ use rustc_middle:: arena:: ArenaAllocatable ;
24
24
use rustc_middle:: metadata:: ModChild ;
25
25
use rustc_middle:: middle:: exported_symbols:: { ExportedSymbol , SymbolExportLevel } ;
26
+ use rustc_middle:: middle:: stability:: DeprecationEntry ;
27
+ use rustc_middle:: mir;
26
28
use rustc_middle:: mir:: interpret:: { AllocDecodingSession , AllocDecodingState } ;
27
- use rustc_middle:: mir:: { self , Body , Promoted } ;
28
29
use rustc_middle:: thir;
29
30
use rustc_middle:: ty:: codec:: TyDecoder ;
30
31
use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
@@ -278,6 +279,99 @@ impl<'a: 'x, 'tcx: 'x, 'x, T: Decodable<DecodeContext<'a, 'tcx>>> Lazy<[T]> {
278
279
}
279
280
}
280
281
282
+ trait LazyQueryDecodable < ' a , ' tcx , T > {
283
+ fn decode_query (
284
+ self ,
285
+ cdata : CrateMetadataRef < ' a > ,
286
+ tcx : TyCtxt < ' tcx > ,
287
+ err : impl FnOnce ( ) -> !,
288
+ ) -> T ;
289
+ }
290
+
291
+ impl < ' a , ' tcx , T > LazyQueryDecodable < ' a , ' tcx , T > for Option < Lazy < T > >
292
+ where
293
+ T : Decodable < DecodeContext < ' a , ' tcx > > ,
294
+ {
295
+ fn decode_query (
296
+ self ,
297
+ cdata : CrateMetadataRef < ' a > ,
298
+ tcx : TyCtxt < ' tcx > ,
299
+ err : impl FnOnce ( ) -> !,
300
+ ) -> T {
301
+ if let Some ( l) = self { l. decode ( ( cdata, tcx) ) } else { err ( ) }
302
+ }
303
+ }
304
+
305
+ impl < ' a , ' tcx , T > LazyQueryDecodable < ' a , ' tcx , & ' tcx T > for Option < Lazy < T > >
306
+ where
307
+ T : Decodable < DecodeContext < ' a , ' tcx > > ,
308
+ T : ArenaAllocatable < ' tcx > ,
309
+ {
310
+ fn decode_query (
311
+ self ,
312
+ cdata : CrateMetadataRef < ' a > ,
313
+ tcx : TyCtxt < ' tcx > ,
314
+ err : impl FnOnce ( ) -> !,
315
+ ) -> & ' tcx T {
316
+ if let Some ( l) = self { tcx. arena . alloc ( l. decode ( ( cdata, tcx) ) ) } else { err ( ) }
317
+ }
318
+ }
319
+
320
+ impl < ' a , ' tcx , T > LazyQueryDecodable < ' a , ' tcx , Option < T > > for Option < Lazy < T > >
321
+ where
322
+ T : Decodable < DecodeContext < ' a , ' tcx > > ,
323
+ {
324
+ fn decode_query (
325
+ self ,
326
+ cdata : CrateMetadataRef < ' a > ,
327
+ tcx : TyCtxt < ' tcx > ,
328
+ _err : impl FnOnce ( ) -> !,
329
+ ) -> Option < T > {
330
+ self . map ( |l| l. decode ( ( cdata, tcx) ) )
331
+ }
332
+ }
333
+
334
+ impl < ' a , ' tcx , T , E > LazyQueryDecodable < ' a , ' tcx , Result < Option < T > , E > > for Option < Lazy < T > >
335
+ where
336
+ T : Decodable < DecodeContext < ' a , ' tcx > > ,
337
+ {
338
+ fn decode_query (
339
+ self ,
340
+ cdata : CrateMetadataRef < ' a > ,
341
+ tcx : TyCtxt < ' tcx > ,
342
+ _err : impl FnOnce ( ) -> !,
343
+ ) -> Result < Option < T > , E > {
344
+ Ok ( self . map ( |l| l. decode ( ( cdata, tcx) ) ) )
345
+ }
346
+ }
347
+
348
+ impl < ' a , ' tcx , T > LazyQueryDecodable < ' a , ' tcx , & ' tcx [ T ] > for Option < Lazy < [ T ] , usize > >
349
+ where
350
+ T : Decodable < DecodeContext < ' a , ' tcx > > + Copy ,
351
+ {
352
+ fn decode_query (
353
+ self ,
354
+ cdata : CrateMetadataRef < ' a > ,
355
+ tcx : TyCtxt < ' tcx > ,
356
+ _err : impl FnOnce ( ) -> !,
357
+ ) -> & ' tcx [ T ] {
358
+ if let Some ( l) = self { tcx. arena . alloc_from_iter ( l. decode ( ( cdata, tcx) ) ) } else { & [ ] }
359
+ }
360
+ }
361
+
362
+ impl < ' a , ' tcx > LazyQueryDecodable < ' a , ' tcx , Option < DeprecationEntry > >
363
+ for Option < Lazy < attr:: Deprecation > >
364
+ {
365
+ fn decode_query (
366
+ self ,
367
+ cdata : CrateMetadataRef < ' a > ,
368
+ tcx : TyCtxt < ' tcx > ,
369
+ _err : impl FnOnce ( ) -> !,
370
+ ) -> Option < DeprecationEntry > {
371
+ self . map ( |l| l. decode ( ( cdata, tcx) ) ) . map ( DeprecationEntry :: external)
372
+ }
373
+ }
374
+
281
375
impl < ' a , ' tcx > DecodeContext < ' a , ' tcx > {
282
376
#[ inline]
283
377
fn tcx ( & self ) -> TyCtxt < ' tcx > {
@@ -716,7 +810,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
716
810
717
811
fn opt_item_ident ( self , item_index : DefIndex , sess : & Session ) -> Option < Ident > {
718
812
let name = self . def_key ( item_index) . disambiguated_data . data . get_opt_name ( ) ?;
719
- let span = match self . root . tables . ident_span . get ( self , item_index) {
813
+ let span = match self . root . tables . def_ident_span . get ( self , item_index) {
720
814
Some ( lazy_span) => lazy_span. decode ( ( self , sess) ) ,
721
815
None => {
722
816
// FIXME: this weird case of a name with no span is specific to `extern crate`
@@ -750,20 +844,22 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
750
844
}
751
845
752
846
fn def_kind ( self , item_id : DefIndex ) -> DefKind {
753
- self . root . tables . def_kind . get ( self , item_id) . map ( |k| k. decode ( self ) ) . unwrap_or_else ( || {
754
- bug ! (
755
- "CrateMetadata::def_kind({:?}): id not found, in crate {:?} with number {}" ,
756
- item_id,
757
- self . root. name,
758
- self . cnum,
759
- )
760
- } )
847
+ self . root . tables . opt_def_kind . get ( self , item_id) . map ( |k| k. decode ( self ) ) . unwrap_or_else (
848
+ || {
849
+ bug ! (
850
+ "CrateMetadata::def_kind({:?}): id not found, in crate {:?} with number {}" ,
851
+ item_id,
852
+ self . root. name,
853
+ self . cnum,
854
+ )
855
+ } ,
856
+ )
761
857
}
762
858
763
859
fn get_span ( self , index : DefIndex , sess : & Session ) -> Span {
764
860
self . root
765
861
. tables
766
- . span
862
+ . def_span
767
863
. get ( self , index)
768
864
. unwrap_or_else ( || panic ! ( "Missing span for {:?}" , index) )
769
865
. decode ( ( self , sess) )
@@ -908,71 +1004,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
908
1004
tcx. alloc_adt_def ( did, adt_kind, variants, repr)
909
1005
}
910
1006
911
- fn get_explicit_predicates (
912
- self ,
913
- item_id : DefIndex ,
914
- tcx : TyCtxt < ' tcx > ,
915
- ) -> ty:: GenericPredicates < ' tcx > {
916
- self . root . tables . explicit_predicates . get ( self , item_id) . unwrap ( ) . decode ( ( self , tcx) )
917
- }
918
-
919
- fn get_inferred_outlives (
920
- self ,
921
- item_id : DefIndex ,
922
- tcx : TyCtxt < ' tcx > ,
923
- ) -> & ' tcx [ ( ty:: Predicate < ' tcx > , Span ) ] {
924
- self . root
925
- . tables
926
- . inferred_outlives
927
- . get ( self , item_id)
928
- . map ( |predicates| tcx. arena . alloc_from_iter ( predicates. decode ( ( self , tcx) ) ) )
929
- . unwrap_or_default ( )
930
- }
931
-
932
- fn get_super_predicates (
933
- self ,
934
- item_id : DefIndex ,
935
- tcx : TyCtxt < ' tcx > ,
936
- ) -> ty:: GenericPredicates < ' tcx > {
937
- self . root . tables . super_predicates . get ( self , item_id) . unwrap ( ) . decode ( ( self , tcx) )
938
- }
939
-
940
- fn get_explicit_item_bounds (
941
- self ,
942
- item_id : DefIndex ,
943
- tcx : TyCtxt < ' tcx > ,
944
- ) -> & ' tcx [ ( ty:: Predicate < ' tcx > , Span ) ] {
945
- self . root
946
- . tables
947
- . explicit_item_bounds
948
- . get ( self , item_id)
949
- . map ( |bounds| tcx. arena . alloc_from_iter ( bounds. decode ( ( self , tcx) ) ) )
950
- . unwrap_or_default ( )
951
- }
952
-
953
1007
fn get_generics ( self , item_id : DefIndex , sess : & Session ) -> ty:: Generics {
954
- self . root . tables . generics . get ( self , item_id) . unwrap ( ) . decode ( ( self , sess) )
955
- }
956
-
957
- fn get_type ( self , id : DefIndex , tcx : TyCtxt < ' tcx > ) -> Ty < ' tcx > {
958
- self . root
959
- . tables
960
- . ty
961
- . get ( self , id)
962
- . unwrap_or_else ( || panic ! ( "Not a type: {:?}" , id) )
963
- . decode ( ( self , tcx) )
964
- }
965
-
966
- fn get_stability ( self , id : DefIndex ) -> Option < attr:: Stability > {
967
- self . root . tables . stability . get ( self , id) . map ( |stab| stab. decode ( self ) )
968
- }
969
-
970
- fn get_const_stability ( self , id : DefIndex ) -> Option < attr:: ConstStability > {
971
- self . root . tables . const_stability . get ( self , id) . map ( |stab| stab. decode ( self ) )
972
- }
973
-
974
- fn get_deprecation ( self , id : DefIndex ) -> Option < attr:: Deprecation > {
975
- self . root . tables . deprecation . get ( self , id) . map ( |depr| depr. decode ( self ) )
1008
+ self . root . tables . generics_of . get ( self , item_id) . unwrap ( ) . decode ( ( self , sess) )
976
1009
}
977
1010
978
1011
fn get_visibility ( self , id : DefIndex ) -> ty:: Visibility {
@@ -1010,22 +1043,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1010
1043
self . get_impl_data ( id) . coerce_unsized_info
1011
1044
}
1012
1045
1013
- fn get_impl_trait ( self , id : DefIndex , tcx : TyCtxt < ' tcx > ) -> Option < ty:: TraitRef < ' tcx > > {
1014
- self . root . tables . impl_trait_ref . get ( self , id) . map ( |tr| tr. decode ( ( self , tcx) ) )
1015
- }
1016
-
1017
1046
fn get_expn_that_defined ( self , id : DefIndex , sess : & Session ) -> ExpnId {
1018
1047
self . root . tables . expn_that_defined . get ( self , id) . unwrap ( ) . decode ( ( self , sess) )
1019
1048
}
1020
1049
1021
- fn get_const_param_default (
1022
- self ,
1023
- tcx : TyCtxt < ' tcx > ,
1024
- id : DefIndex ,
1025
- ) -> rustc_middle:: ty:: Const < ' tcx > {
1026
- self . root . tables . const_defaults . get ( self , id) . unwrap ( ) . decode ( ( self , tcx) )
1027
- }
1028
-
1029
1050
/// Iterates over all the stability attributes in the given crate.
1030
1051
fn get_lib_features ( self , tcx : TyCtxt < ' tcx > ) -> & ' tcx [ ( Symbol , Option < Symbol > ) ] {
1031
1052
tcx. arena . alloc_from_iter ( self . root . lib_features . decode ( self ) )
@@ -1163,7 +1184,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1163
1184
}
1164
1185
1165
1186
fn is_item_mir_available ( self , id : DefIndex ) -> bool {
1166
- self . root . tables . mir . get ( self , id) . is_some ( )
1187
+ self . root . tables . optimized_mir . get ( self , id) . is_some ( )
1167
1188
}
1168
1189
1169
1190
fn module_expansion ( self , id : DefIndex , sess : & Session ) -> ExpnId {
@@ -1175,60 +1196,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1175
1196
}
1176
1197
}
1177
1198
1178
- fn get_optimized_mir ( self , tcx : TyCtxt < ' tcx > , id : DefIndex ) -> Body < ' tcx > {
1179
- self . root
1180
- . tables
1181
- . mir
1182
- . get ( self , id)
1183
- . unwrap_or_else ( || {
1184
- bug ! ( "get_optimized_mir: missing MIR for `{:?}`" , self . local_def_id( id) )
1185
- } )
1186
- . decode ( ( self , tcx) )
1187
- }
1188
-
1189
- fn get_mir_for_ctfe ( self , tcx : TyCtxt < ' tcx > , id : DefIndex ) -> Body < ' tcx > {
1190
- self . root
1191
- . tables
1192
- . mir_for_ctfe
1193
- . get ( self , id)
1194
- . unwrap_or_else ( || {
1195
- bug ! ( "get_mir_for_ctfe: missing MIR for `{:?}`" , self . local_def_id( id) )
1196
- } )
1197
- . decode ( ( self , tcx) )
1198
- }
1199
-
1200
- fn get_thir_abstract_const (
1201
- self ,
1202
- tcx : TyCtxt < ' tcx > ,
1203
- id : DefIndex ,
1204
- ) -> Result < Option < & ' tcx [ thir:: abstract_const:: Node < ' tcx > ] > , ErrorReported > {
1205
- self . root
1206
- . tables
1207
- . thir_abstract_consts
1208
- . get ( self , id)
1209
- . map_or ( Ok ( None ) , |v| Ok ( Some ( v. decode ( ( self , tcx) ) ) ) )
1210
- }
1211
-
1212
- fn get_unused_generic_params ( self , id : DefIndex ) -> FiniteBitSet < u32 > {
1213
- self . root
1214
- . tables
1215
- . unused_generic_params
1216
- . get ( self , id)
1217
- . map ( |params| params. decode ( self ) )
1218
- . unwrap_or_default ( )
1219
- }
1220
-
1221
- fn get_promoted_mir ( self , tcx : TyCtxt < ' tcx > , id : DefIndex ) -> IndexVec < Promoted , Body < ' tcx > > {
1222
- self . root
1223
- . tables
1224
- . promoted_mir
1225
- . get ( self , id)
1226
- . unwrap_or_else ( || {
1227
- bug ! ( "get_promoted_mir: missing MIR for `{:?}`" , self . local_def_id( id) )
1228
- } )
1229
- . decode ( ( self , tcx) )
1230
- }
1231
-
1232
1199
fn mir_const_qualif ( self , id : DefIndex ) -> mir:: ConstQualifs {
1233
1200
match self . kind ( id) {
1234
1201
EntryKind :: AnonConst ( qualif, _)
@@ -1288,10 +1255,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1288
1255
}
1289
1256
}
1290
1257
1291
- fn get_item_variances ( self , id : DefIndex ) -> impl Iterator < Item = ty:: Variance > + ' a {
1292
- self . root . tables . variances . get ( self , id) . unwrap_or_else ( Lazy :: empty) . decode ( self )
1293
- }
1294
-
1295
1258
fn get_ctor_def_id_and_kind ( self , node_id : DefIndex ) -> Option < ( DefId , CtorKind ) > {
1296
1259
match self . kind ( node_id) {
1297
1260
EntryKind :: Struct ( data, _) | EntryKind :: Variant ( data) => {
@@ -1479,7 +1442,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1479
1442
EntryKind :: AssocFn ( data) => data. decode ( self ) . fn_data . param_names ,
1480
1443
_ => Lazy :: empty ( ) ,
1481
1444
} ;
1482
- tcx . arena . alloc_from_iter ( param_names . decode ( ( self , tcx) ) )
1445
+ LazyQueryDecodable :: decode_query ( Some ( param_names ) , self , tcx, || unreachable ! ( ) )
1483
1446
}
1484
1447
1485
1448
fn exported_symbols (
@@ -1551,10 +1514,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1551
1514
}
1552
1515
}
1553
1516
1554
- fn fn_sig ( self , id : DefIndex , tcx : TyCtxt < ' tcx > ) -> ty:: PolyFnSig < ' tcx > {
1555
- self . root . tables . fn_sig . get ( self , id) . unwrap ( ) . decode ( ( self , tcx) )
1556
- }
1557
-
1558
1517
#[ inline]
1559
1518
fn def_key ( self , index : DefIndex ) -> DefKey {
1560
1519
* self
0 commit comments