@@ -508,7 +508,8 @@ impl<'tcx> EncodeContext<'tcx> {
508
508
let proc_macro_data = self . encode_proc_macros ( ) ;
509
509
let proc_macro_data_bytes = self . position ( ) - i;
510
510
511
- // Encode exported symbols info.
511
+ // Encode exported symbols info. This is prefetched in `encode_metadata` so we encode
512
+ // this last to give the prefetching as much time as possible to complete.
512
513
i = self . position ( ) ;
513
514
let exported_symbols = self . tcx . exported_symbols ( LOCAL_CRATE ) ;
514
515
let exported_symbols = self . encode_exported_symbols ( & exported_symbols) ;
@@ -889,6 +890,8 @@ impl EncodeContext<'tcx> {
889
890
self . encode_generics ( def_id) ;
890
891
self . encode_explicit_predicates ( def_id) ;
891
892
self . encode_inferred_outlives ( def_id) ;
893
+
894
+ // This should be kept in sync with `PrefetchVisitor.visit_trait_item`.
892
895
self . encode_optimized_mir ( def_id) ;
893
896
self . encode_promoted_mir ( def_id) ;
894
897
}
@@ -960,6 +963,9 @@ impl EncodeContext<'tcx> {
960
963
self . encode_generics ( def_id) ;
961
964
self . encode_explicit_predicates ( def_id) ;
962
965
self . encode_inferred_outlives ( def_id) ;
966
+
967
+ // The following part should be kept in sync with `PrefetchVisitor.visit_impl_item`.
968
+
963
969
let mir = match ast_item. kind {
964
970
hir:: ImplItemKind :: Const ( ..) => true ,
965
971
hir:: ImplItemKind :: Fn ( ref sig, _) => {
@@ -1251,6 +1257,8 @@ impl EncodeContext<'tcx> {
1251
1257
_ => { }
1252
1258
}
1253
1259
1260
+ // The following part should be kept in sync with `PrefetchVisitor.visit_item`.
1261
+
1254
1262
let mir = match item. kind {
1255
1263
hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => true ,
1256
1264
hir:: ItemKind :: Fn ( ref sig, ..) => {
@@ -1699,6 +1707,7 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
1699
1707
}
1700
1708
1701
1709
/// Used to prefetch queries which will be needed later by metadata encoding.
1710
+ /// Only a subset of the queries are actually prefetched to keep this code smaller.
1702
1711
struct PrefetchVisitor < ' tcx > {
1703
1712
tcx : TyCtxt < ' tcx > ,
1704
1713
mir_keys : & ' tcx DefIdSet ,
@@ -1715,6 +1724,7 @@ impl<'tcx> PrefetchVisitor<'tcx> {
1715
1724
1716
1725
impl < ' tcx , ' v > ParItemLikeVisitor < ' v > for PrefetchVisitor < ' tcx > {
1717
1726
fn visit_item ( & self , item : & hir:: Item < ' _ > ) {
1727
+ // This should be kept in sync with `encode_info_for_item`.
1718
1728
let tcx = self . tcx ;
1719
1729
match item. kind {
1720
1730
hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => {
@@ -1734,10 +1744,12 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> {
1734
1744
}
1735
1745
1736
1746
fn visit_trait_item ( & self , trait_item : & ' v hir:: TraitItem < ' v > ) {
1747
+ // This should be kept in sync with `encode_info_for_trait_item`.
1737
1748
self . prefetch_mir ( self . tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ) ;
1738
1749
}
1739
1750
1740
1751
fn visit_impl_item ( & self , impl_item : & ' v hir:: ImplItem < ' v > ) {
1752
+ // This should be kept in sync with `encode_info_for_impl_item`.
1741
1753
let tcx = self . tcx ;
1742
1754
match impl_item. kind {
1743
1755
hir:: ImplItemKind :: Const ( ..) => {
@@ -1789,6 +1801,8 @@ pub(super) fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
1789
1801
return ;
1790
1802
}
1791
1803
// Prefetch some queries used by metadata encoding.
1804
+ // This is not necessary for correctness, but is only done for performance reasons.
1805
+ // It can be removed if it turns out to cause trouble or be detrimental to performance.
1792
1806
tcx. dep_graph . with_ignore ( || {
1793
1807
join (
1794
1808
|| {
0 commit comments