@@ -799,6 +799,38 @@ fn should_inline(attrs: &[Attribute]) -> bool {
799799 }
800800}
801801
802+ // Encodes the inherent implementations of a structure, enumeration, or trait.
803+ fn encode_inherent_implementations ( ecx : & EncodeContext ,
804+ ebml_w : & mut writer:: Encoder ,
805+ def_id : def_id ) {
806+ match ecx. tcx . inherent_impls . find ( & def_id) {
807+ None => { }
808+ Some ( & implementations) => {
809+ for implementation in implementations. iter ( ) {
810+ ebml_w. start_tag ( tag_items_data_item_inherent_impl) ;
811+ encode_def_id ( ebml_w, implementation. did ) ;
812+ ebml_w. end_tag ( ) ;
813+ }
814+ }
815+ }
816+ }
817+
818+ // Encodes the implementations of a trait defined in this crate.
819+ fn encode_extension_implementations ( ecx : & EncodeContext ,
820+ ebml_w : & mut writer:: Encoder ,
821+ trait_def_id : def_id ) {
822+ match ecx. tcx . trait_impls . find ( & trait_def_id) {
823+ None => { }
824+ Some ( & implementations) => {
825+ for implementation in implementations. iter ( ) {
826+ ebml_w. start_tag ( tag_items_data_item_extension_impl) ;
827+ encode_def_id ( ebml_w, implementation. did ) ;
828+ ebml_w. end_tag ( ) ;
829+ }
830+ }
831+ }
832+ }
833+
802834fn encode_info_for_item ( ecx : & EncodeContext ,
803835 ebml_w : & mut writer:: Encoder ,
804836 item: @item,
@@ -902,6 +934,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
902934 ( ecx. encode_inlined_item ) ( ecx, ebml_w, path, ii_item ( item) ) ;
903935 encode_path ( ecx, ebml_w, path, ast_map:: path_name ( item. ident ) ) ;
904936 encode_region_param ( ecx, ebml_w, item) ;
937+
938+ // Encode inherent implementations for this enumeration.
939+ encode_inherent_implementations ( ecx, ebml_w, def_id) ;
940+
905941 ebml_w. end_tag ( ) ;
906942
907943 encode_enum_variant_info ( ecx,
@@ -954,6 +990,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
954990 }
955991 }
956992
993+ // Encode inherent implementations for this structure.
994+ encode_inherent_implementations ( ecx, ebml_w, def_id) ;
995+
957996 /* Each class has its own index -- encode it */
958997 let bkts = create_index ( idx) ;
959998 encode_index ( ebml_w, bkts, write_i64) ;
@@ -1069,6 +1108,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
10691108 let trait_ref = ty:: node_id_to_trait_ref ( ecx. tcx , ast_trait_ref. ref_id ) ;
10701109 encode_trait_ref ( ebml_w, ecx, trait_ref, tag_item_super_trait_ref) ;
10711110 }
1111+
1112+ // Encode the implementations of this trait.
1113+ encode_extension_implementations ( ecx, ebml_w, def_id) ;
1114+
10721115 ebml_w. end_tag ( ) ;
10731116
10741117 // Now output the method info for each method.
@@ -1130,6 +1173,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
11301173
11311174 ebml_w. end_tag ( ) ;
11321175 }
1176+
1177+ // Encode inherent implementations for this trait.
1178+ encode_inherent_implementations ( ecx, ebml_w, def_id) ;
11331179 }
11341180 item_mac( * ) => fail ! ( "item macros unimplemented" )
11351181 }
@@ -1523,17 +1569,36 @@ struct ImplVisitor<'self> {
15231569impl < ' self > Visitor < ( ) > for ImplVisitor < ' self > {
15241570 fn visit_item ( & mut self , item : @item, _: ( ) ) {
15251571 match item. node {
1526- item_impl( * ) => {
1527- self . ebml_w . start_tag ( tag_impls_impl) ;
1528- encode_def_id ( self . ebml_w , local_def ( item. id ) ) ;
1529- self . ebml_w . end_tag ( ) ;
1572+ item_impl( _, Some ( ref trait_ref) , _, _) => {
1573+ let def_map = self . ecx . tcx . def_map ;
1574+ let trait_def = def_map. get_copy ( & trait_ref. ref_id ) ;
1575+ let def_id = ast_util:: def_id_of_def ( trait_def) ;
1576+
1577+ // Load eagerly if this is an implementation of the Drop trait
1578+ // or if the trait is not defined in this crate.
1579+ if def_id == self . ecx . tcx . lang_items . drop_trait ( ) . unwrap ( ) ||
1580+ def_id. crate != LOCAL_CRATE {
1581+ self . ebml_w . start_tag ( tag_impls_impl) ;
1582+ encode_def_id ( self . ebml_w , local_def ( item. id ) ) ;
1583+ self . ebml_w . end_tag ( ) ;
1584+ }
15301585 }
15311586 _ => { }
15321587 }
15331588 visit:: walk_item ( self , item, ( ) ) ;
15341589 }
15351590}
15361591
1592+ /// Encodes implementations that are eagerly loaded.
1593+ ///
1594+ /// None of this is necessary in theory; we can load all implementations
1595+ /// lazily. However, in two cases the optimizations to lazily load
1596+ /// implementations are not yet implemented. These two cases, which require us
1597+ /// to load implementations eagerly, are:
1598+ ///
1599+ /// * Destructors (implementations of the Drop trait).
1600+ ///
1601+ /// * Implementations of traits not defined in this crate.
15371602fn encode_impls ( ecx : & EncodeContext ,
15381603 crate : & Crate ,
15391604 ebml_w : & mut writer:: Encoder ) {
0 commit comments