@@ -865,20 +865,6 @@ fn encode_inherent_implementations(ecx: &EncodeContext,
865865    } 
866866} 
867867
868- // Encodes the implementations of a trait defined in this crate. 
869- fn  encode_extension_implementations ( ecx :  & EncodeContext , 
870-                                     rbml_w :  & mut  Encoder , 
871-                                     trait_def_id :  DefId )  { 
872-     assert ! ( trait_def_id. is_local( ) ) ; 
873-     let  def = ecx. tcx . lookup_trait_def ( trait_def_id) ; 
874- 
875-     def. for_each_impl ( ecx. tcx ,  |impl_def_id| { 
876-         rbml_w. start_tag ( tag_items_data_item_extension_impl) ; 
877-         encode_def_id ( rbml_w,  impl_def_id) ; 
878-         rbml_w. end_tag ( ) ; 
879-     } ) ; 
880- } 
881- 
882868fn  encode_stability ( rbml_w :  & mut  Encoder ,  stab_opt :  Option < & attr:: Stability > )  { 
883869    stab_opt. map ( |stab| { 
884870        rbml_w. start_tag ( tag_items_data_item_stability) ; 
@@ -1256,9 +1242,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
12561242        } 
12571243        encode_path ( rbml_w,  path. clone ( ) ) ; 
12581244
1259-         // Encode the implementations of this trait. 
1260-         encode_extension_implementations ( ecx,  rbml_w,  def_id) ; 
1261- 
12621245        // Encode inherent implementations for this trait. 
12631246        encode_inherent_implementations ( ecx,  rbml_w,  def_id) ; 
12641247
@@ -1763,53 +1746,44 @@ fn encode_struct_field_attrs(ecx: &EncodeContext,
17631746
17641747
17651748
1766- struct  ImplVisitor < ' a ,  ' b : ' a ,   ' c : ' a ,   ' tcx : ' b >  { 
1767-     ecx :  & ' a  EncodeContext < ' b ,   ' tcx > , 
1768-     rbml_w :   & ' a   mut   Encoder < ' c > , 
1749+ struct  ImplVisitor < ' a ,  ' tcx : ' a >  { 
1750+     tcx :  & ' a  ty :: ctxt < ' tcx > , 
1751+     impls :   FnvHashMap < DefId ,   Vec < DefId > > 
17691752} 
17701753
1771- impl < ' a ,  ' b ,   ' c ,   ' tcx ,  ' v >  Visitor < ' v >  for  ImplVisitor < ' a ,   ' b ,   ' c ,  ' tcx >  { 
1754+ impl < ' a ,  ' tcx ,  ' v >  Visitor < ' v >  for  ImplVisitor < ' a ,  ' tcx >  { 
17721755    fn  visit_item ( & mut  self ,  item :  & hir:: Item )  { 
1773-         if  let  hir:: ItemImpl ( _,  _,  _,  Some ( ref  trait_ref) ,  _,  _)  = item. node  { 
1774-             let  def_id = self . ecx . tcx . def_map . borrow ( ) . get ( & trait_ref. ref_id ) . unwrap ( ) . def_id ( ) ; 
1775- 
1776-             // Load eagerly if this is an implementation of the Drop trait 
1777-             // or if the trait is not defined in this crate. 
1778-             if  Some ( def_id)  == self . ecx . tcx . lang_items . drop_trait ( )  ||
1779-                     def_id. krate  != LOCAL_CRATE  { 
1780-                 self . rbml_w . start_tag ( tag_impls_impl) ; 
1781-                 encode_def_id ( self . rbml_w ,  self . ecx . tcx . map . local_def_id ( item. id ) ) ; 
1782-                 self . rbml_w . wr_tagged_u64 ( tag_impls_impl_trait_def_id,  def_to_u64 ( def_id) ) ; 
1783-                 self . rbml_w . end_tag ( ) ; 
1756+         if  let  hir:: ItemImpl ( ..)  = item. node  { 
1757+             let  impl_id = self . tcx . map . local_def_id ( item. id ) ; 
1758+             if  let  Some ( trait_ref)  = self . tcx . impl_trait_ref ( impl_id)  { 
1759+                 self . impls . entry ( trait_ref. def_id ) 
1760+                     . or_insert ( vec ! [ ] ) 
1761+                     . push ( impl_id) ; 
17841762            } 
17851763        } 
17861764        visit:: walk_item ( self ,  item) ; 
17871765    } 
17881766} 
17891767
1790- /// Encodes implementations that are eagerly loaded. 
1791- /// 
1792- /// None of this is necessary in theory; we can load all implementations 
1793- /// lazily. However, in two cases the optimizations to lazily load 
1794- /// implementations are not yet implemented. These two cases, which require us 
1795- /// to load implementations eagerly, are: 
1796- /// 
1797- /// * Destructors (implementations of the Drop trait). 
1798- /// 
1799- /// * Implementations of traits not defined in this crate. 
1768+ /// Encodes an index, mapping each trait to its (local) implementations. 
18001769fn  encode_impls < ' a > ( ecx :  & ' a  EncodeContext , 
18011770                    krate :  & hir:: Crate , 
18021771                    rbml_w :  & ' a  mut  Encoder )  { 
1803-     rbml_w. start_tag ( tag_impls) ; 
1772+     let  mut  visitor = ImplVisitor  { 
1773+         tcx :  ecx. tcx , 
1774+         impls :  FnvHashMap ( ) 
1775+     } ; 
1776+     visit:: walk_crate ( & mut  visitor,  krate) ; 
18041777
1805-     { 
1806-         let  mut  visitor = ImplVisitor  { 
1807-             ecx :  ecx, 
1808-             rbml_w :  rbml_w, 
1809-         } ; 
1810-         visit:: walk_crate ( & mut  visitor,  krate) ; 
1778+     rbml_w. start_tag ( tag_impls) ; 
1779+     for  ( trait_,  trait_impls)  in  visitor. impls  { 
1780+         rbml_w. start_tag ( tag_impls_trait) ; 
1781+         encode_def_id ( rbml_w,  trait_) ; 
1782+         for  impl_ in  trait_impls { 
1783+             rbml_w. wr_tagged_u64 ( tag_impls_trait_impl,  def_to_u64 ( impl_) ) ; 
1784+         } 
1785+         rbml_w. end_tag ( ) ; 
18111786    } 
1812- 
18131787    rbml_w. end_tag ( ) ; 
18141788} 
18151789
0 commit comments