@@ -2,8 +2,9 @@ use crate::rmeta::def_path_hash_map::DefPathHashMapRef;
22use crate :: rmeta:: table:: { FixedSizeEncoding , TableBuilder } ;
33use crate :: rmeta:: * ;
44
5+ use rustc_data_structures:: fingerprint:: Fingerprint ;
56use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
6- use rustc_data_structures:: stable_hasher:: StableHasher ;
7+ use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
78use rustc_data_structures:: sync:: { join, par_iter, Lrc , ParallelIterator } ;
89use rustc_hir as hir;
910use rustc_hir:: def:: DefKind ;
@@ -578,6 +579,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
578579 }
579580
580581 fn encode_crate_root ( & mut self ) -> Lazy < CrateRoot < ' tcx > > {
582+ let tcx = self . tcx ;
581583 let mut i = self . position ( ) ;
582584
583585 // Encode the crate deps
@@ -623,8 +625,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
623625 let impls = self . encode_impls ( ) ;
624626 let impls_bytes = self . position ( ) - i;
625627
626- let tcx = self . tcx ;
627-
628+ i = self . position ( ) ;
629+ let incoherent_impls = self . encode_incoherent_impls ( ) ;
630+ let incoherent_impls_bytes = self . position ( ) - i;
628631 // Encode MIR.
629632 i = self . position ( ) ;
630633 self . encode_mir ( ) ;
@@ -734,6 +737,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
734737 source_map,
735738 traits,
736739 impls,
740+ incoherent_impls,
737741 exported_symbols,
738742 interpret_alloc_index,
739743 tables,
@@ -762,6 +766,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
762766 eprintln ! ( " source_map bytes: {}" , source_map_bytes) ;
763767 eprintln ! ( " traits bytes: {}" , traits_bytes) ;
764768 eprintln ! ( " impls bytes: {}" , impls_bytes) ;
769+ eprintln ! ( "incoherent_impls bytes: {}" , incoherent_impls_bytes) ;
765770 eprintln ! ( " exp. symbols bytes: {}" , exported_symbols_bytes) ;
766771 eprintln ! ( " def-path table bytes: {}" , def_path_table_bytes) ;
767772 eprintln ! ( " def-path hashes bytes: {}" , def_path_hash_map_bytes) ;
@@ -1813,6 +1818,33 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18131818 self . lazy ( & all_impls)
18141819 }
18151820
1821+ fn encode_incoherent_impls ( & mut self ) -> Lazy < [ IncoherentImpls ] > {
1822+ debug ! ( "EncodeContext::encode_traits_and_impls()" ) ;
1823+ empty_proc_macro ! ( self ) ;
1824+ let tcx = self . tcx ;
1825+ let mut ctx = tcx. create_stable_hashing_context ( ) ;
1826+ let mut all_impls: Vec < _ > = tcx. crate_inherent_impls ( ( ) ) . incoherent_impls . iter ( ) . collect ( ) ;
1827+ all_impls. sort_by_cached_key ( |& ( & simp, _) | {
1828+ let mut hasher = StableHasher :: new ( ) ;
1829+ simp. hash_stable ( & mut ctx, & mut hasher) ;
1830+ hasher. finish :: < Fingerprint > ( ) ;
1831+ } ) ;
1832+ let all_impls: Vec < _ > = all_impls
1833+ . into_iter ( )
1834+ . map ( |( & simp, impls) | {
1835+ let mut impls: Vec < _ > =
1836+ impls. into_iter ( ) . map ( |def_id| def_id. local_def_index ) . collect ( ) ;
1837+ impls. sort_by_cached_key ( |& local_def_index| {
1838+ tcx. hir ( ) . def_path_hash ( LocalDefId { local_def_index } )
1839+ } ) ;
1840+
1841+ IncoherentImpls { self_ty : simp, impls : self . lazy ( impls) }
1842+ } )
1843+ . collect ( ) ;
1844+
1845+ self . lazy ( & all_impls)
1846+ }
1847+
18161848 // Encodes all symbols exported from this crate into the metadata.
18171849 //
18181850 // This pass is seeded off the reachability list calculated in the
0 commit comments