@@ -799,6 +799,38 @@ fn should_inline(attrs: &[Attribute]) -> bool {
799
799
}
800
800
}
801
801
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
+
802
834
fn encode_info_for_item ( ecx : & EncodeContext ,
803
835
ebml_w : & mut writer:: Encoder ,
804
836
item: @item,
@@ -902,6 +934,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
902
934
( ecx. encode_inlined_item ) ( ecx, ebml_w, path, ii_item ( item) ) ;
903
935
encode_path ( ecx, ebml_w, path, ast_map:: path_name ( item. ident ) ) ;
904
936
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
+
905
941
ebml_w. end_tag ( ) ;
906
942
907
943
encode_enum_variant_info ( ecx,
@@ -954,6 +990,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
954
990
}
955
991
}
956
992
993
+ // Encode inherent implementations for this structure.
994
+ encode_inherent_implementations ( ecx, ebml_w, def_id) ;
995
+
957
996
/* Each class has its own index -- encode it */
958
997
let bkts = create_index ( idx) ;
959
998
encode_index ( ebml_w, bkts, write_i64) ;
@@ -1069,6 +1108,10 @@ fn encode_info_for_item(ecx: &EncodeContext,
1069
1108
let trait_ref = ty:: node_id_to_trait_ref ( ecx. tcx , ast_trait_ref. ref_id ) ;
1070
1109
encode_trait_ref ( ebml_w, ecx, trait_ref, tag_item_super_trait_ref) ;
1071
1110
}
1111
+
1112
+ // Encode the implementations of this trait.
1113
+ encode_extension_implementations ( ecx, ebml_w, def_id) ;
1114
+
1072
1115
ebml_w. end_tag ( ) ;
1073
1116
1074
1117
// Now output the method info for each method.
@@ -1130,6 +1173,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
1130
1173
1131
1174
ebml_w. end_tag ( ) ;
1132
1175
}
1176
+
1177
+ // Encode inherent implementations for this trait.
1178
+ encode_inherent_implementations ( ecx, ebml_w, def_id) ;
1133
1179
}
1134
1180
item_mac( * ) => fail ! ( "item macros unimplemented" )
1135
1181
}
@@ -1523,17 +1569,36 @@ struct ImplVisitor<'self> {
1523
1569
impl < ' self > Visitor < ( ) > for ImplVisitor < ' self > {
1524
1570
fn visit_item ( & mut self , item : @item, _: ( ) ) {
1525
1571
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
+ }
1530
1585
}
1531
1586
_ => { }
1532
1587
}
1533
1588
visit:: walk_item ( self , item, ( ) ) ;
1534
1589
}
1535
1590
}
1536
1591
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.
1537
1602
fn encode_impls ( ecx : & EncodeContext ,
1538
1603
crate : & Crate ,
1539
1604
ebml_w : & mut writer:: Encoder ) {
0 commit comments