@@ -508,7 +508,8 @@ impl<'tcx> EncodeContext<'tcx> {
508508 let proc_macro_data = self . encode_proc_macros ( ) ;
509509 let proc_macro_data_bytes = self . position ( ) - i;
510510
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.
512513 i = self . position ( ) ;
513514 let exported_symbols = self . tcx . exported_symbols ( LOCAL_CRATE ) ;
514515 let exported_symbols = self . encode_exported_symbols ( & exported_symbols) ;
@@ -889,6 +890,8 @@ impl EncodeContext<'tcx> {
889890 self . encode_generics ( def_id) ;
890891 self . encode_explicit_predicates ( def_id) ;
891892 self . encode_inferred_outlives ( def_id) ;
893+
894+ // This should be kept in sync with `PrefetchVisitor.visit_trait_item`.
892895 self . encode_optimized_mir ( def_id) ;
893896 self . encode_promoted_mir ( def_id) ;
894897 }
@@ -960,6 +963,9 @@ impl EncodeContext<'tcx> {
960963 self . encode_generics ( def_id) ;
961964 self . encode_explicit_predicates ( def_id) ;
962965 self . encode_inferred_outlives ( def_id) ;
966+
967+ // The following part should be kept in sync with `PrefetchVisitor.visit_impl_item`.
968+
963969 let mir = match ast_item. kind {
964970 hir:: ImplItemKind :: Const ( ..) => true ,
965971 hir:: ImplItemKind :: Fn ( ref sig, _) => {
@@ -1251,6 +1257,8 @@ impl EncodeContext<'tcx> {
12511257 _ => { }
12521258 }
12531259
1260+ // The following part should be kept in sync with `PrefetchVisitor.visit_item`.
1261+
12541262 let mir = match item. kind {
12551263 hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => true ,
12561264 hir:: ItemKind :: Fn ( ref sig, ..) => {
@@ -1699,6 +1707,7 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
16991707}
17001708
17011709/// 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.
17021711struct PrefetchVisitor < ' tcx > {
17031712 tcx : TyCtxt < ' tcx > ,
17041713 mir_keys : & ' tcx DefIdSet ,
@@ -1715,6 +1724,7 @@ impl<'tcx> PrefetchVisitor<'tcx> {
17151724
17161725impl < ' tcx , ' v > ParItemLikeVisitor < ' v > for PrefetchVisitor < ' tcx > {
17171726 fn visit_item ( & self , item : & hir:: Item < ' _ > ) {
1727+ // This should be kept in sync with `encode_info_for_item`.
17181728 let tcx = self . tcx ;
17191729 match item. kind {
17201730 hir:: ItemKind :: Static ( ..) | hir:: ItemKind :: Const ( ..) => {
@@ -1734,10 +1744,12 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> {
17341744 }
17351745
17361746 fn visit_trait_item ( & self , trait_item : & ' v hir:: TraitItem < ' v > ) {
1747+ // This should be kept in sync with `encode_info_for_trait_item`.
17371748 self . prefetch_mir ( self . tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ) ;
17381749 }
17391750
17401751 fn visit_impl_item ( & self , impl_item : & ' v hir:: ImplItem < ' v > ) {
1752+ // This should be kept in sync with `encode_info_for_impl_item`.
17411753 let tcx = self . tcx ;
17421754 match impl_item. kind {
17431755 hir:: ImplItemKind :: Const ( ..) => {
@@ -1789,6 +1801,8 @@ pub(super) fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
17891801 return ;
17901802 }
17911803 // 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.
17921806 tcx. dep_graph . with_ignore ( || {
17931807 join (
17941808 || {
0 commit comments