@@ -54,7 +54,6 @@ use attributes;
54
54
use builder:: { Builder , MemFlags } ;
55
55
use callee;
56
56
use common:: { C_bool , C_bytes_in_context , C_i32 , C_usize } ;
57
- use rustc_mir:: monomorphize:: collector:: { self , MonoItemCollectionMode } ;
58
57
use rustc_mir:: monomorphize:: item:: DefPathBasedNames ;
59
58
use common:: { self , C_struct_in_context , C_array , val_ty} ;
60
59
use consts;
@@ -64,20 +63,19 @@ use declare;
64
63
use meth;
65
64
use mir;
66
65
use monomorphize:: Instance ;
67
- use monomorphize:: partitioning:: { self , PartitioningStrategy , CodegenUnit , CodegenUnitExt } ;
66
+ use monomorphize:: partitioning:: { CodegenUnit , CodegenUnitExt } ;
68
67
use rustc_codegen_utils:: symbol_names_test;
69
68
use time_graph;
70
- use mono_item:: { MonoItem , BaseMonoItemExt , MonoItemExt } ;
69
+ use mono_item:: { MonoItem , MonoItemExt } ;
71
70
use type_:: Type ;
72
71
use type_of:: LayoutLlvmExt ;
73
- use rustc:: util:: nodemap:: { FxHashMap , DefIdSet } ;
72
+ use rustc:: util:: nodemap:: FxHashMap ;
74
73
use CrateInfo ;
75
74
use rustc_data_structures:: small_c_str:: SmallCStr ;
76
75
use rustc_data_structures:: sync:: Lrc ;
77
76
78
77
use std:: any:: Any ;
79
78
use std:: ffi:: CString ;
80
- use std:: sync:: Arc ;
81
79
use std:: time:: { Instant , Duration } ;
82
80
use std:: i32;
83
81
use std:: cmp;
@@ -963,128 +961,6 @@ fn assert_and_save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
963
961
|| rustc_incremental:: save_dep_graph ( tcx) ) ;
964
962
}
965
963
966
- fn collect_and_partition_mono_items < ' a , ' tcx > (
967
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
968
- cnum : CrateNum ,
969
- ) -> ( Arc < DefIdSet > , Arc < Vec < Arc < CodegenUnit < ' tcx > > > > )
970
- {
971
- assert_eq ! ( cnum, LOCAL_CRATE ) ;
972
-
973
- let collection_mode = match tcx. sess . opts . debugging_opts . print_mono_items {
974
- Some ( ref s) => {
975
- let mode_string = s. to_lowercase ( ) ;
976
- let mode_string = mode_string. trim ( ) ;
977
- if mode_string == "eager" {
978
- MonoItemCollectionMode :: Eager
979
- } else {
980
- if mode_string != "lazy" {
981
- let message = format ! ( "Unknown codegen-item collection mode '{}'. \
982
- Falling back to 'lazy' mode.",
983
- mode_string) ;
984
- tcx. sess . warn ( & message) ;
985
- }
986
-
987
- MonoItemCollectionMode :: Lazy
988
- }
989
- }
990
- None => {
991
- if tcx. sess . opts . cg . link_dead_code {
992
- MonoItemCollectionMode :: Eager
993
- } else {
994
- MonoItemCollectionMode :: Lazy
995
- }
996
- }
997
- } ;
998
-
999
- let ( items, inlining_map) =
1000
- time ( tcx. sess , "monomorphization collection" , || {
1001
- collector:: collect_crate_mono_items ( tcx, collection_mode)
1002
- } ) ;
1003
-
1004
- tcx. sess . abort_if_errors ( ) ;
1005
-
1006
- :: rustc_mir:: monomorphize:: assert_symbols_are_distinct ( tcx, items. iter ( ) ) ;
1007
-
1008
- let strategy = if tcx. sess . opts . incremental . is_some ( ) {
1009
- PartitioningStrategy :: PerModule
1010
- } else {
1011
- PartitioningStrategy :: FixedUnitCount ( tcx. sess . codegen_units ( ) )
1012
- } ;
1013
-
1014
- let codegen_units = time ( tcx. sess , "codegen unit partitioning" , || {
1015
- partitioning:: partition ( tcx,
1016
- items. iter ( ) . cloned ( ) ,
1017
- strategy,
1018
- & inlining_map)
1019
- . into_iter ( )
1020
- . map ( Arc :: new)
1021
- . collect :: < Vec < _ > > ( )
1022
- } ) ;
1023
-
1024
- let mono_items: DefIdSet = items. iter ( ) . filter_map ( |mono_item| {
1025
- match * mono_item {
1026
- MonoItem :: Fn ( ref instance) => Some ( instance. def_id ( ) ) ,
1027
- MonoItem :: Static ( def_id) => Some ( def_id) ,
1028
- _ => None ,
1029
- }
1030
- } ) . collect ( ) ;
1031
-
1032
- if tcx. sess . opts . debugging_opts . print_mono_items . is_some ( ) {
1033
- let mut item_to_cgus: FxHashMap < _ , Vec < _ > > = Default :: default ( ) ;
1034
-
1035
- for cgu in & codegen_units {
1036
- for ( & mono_item, & linkage) in cgu. items ( ) {
1037
- item_to_cgus. entry ( mono_item)
1038
- . or_default ( )
1039
- . push ( ( cgu. name ( ) . clone ( ) , linkage) ) ;
1040
- }
1041
- }
1042
-
1043
- let mut item_keys: Vec < _ > = items
1044
- . iter ( )
1045
- . map ( |i| {
1046
- let mut output = i. to_string ( tcx) ;
1047
- output. push_str ( " @@" ) ;
1048
- let mut empty = Vec :: new ( ) ;
1049
- let cgus = item_to_cgus. get_mut ( i) . unwrap_or ( & mut empty) ;
1050
- cgus. as_mut_slice ( ) . sort_by_key ( |& ( ref name, _) | name. clone ( ) ) ;
1051
- cgus. dedup ( ) ;
1052
- for & ( ref cgu_name, ( linkage, _) ) in cgus. iter ( ) {
1053
- output. push_str ( " " ) ;
1054
- output. push_str ( & cgu_name. as_str ( ) ) ;
1055
-
1056
- let linkage_abbrev = match linkage {
1057
- Linkage :: External => "External" ,
1058
- Linkage :: AvailableExternally => "Available" ,
1059
- Linkage :: LinkOnceAny => "OnceAny" ,
1060
- Linkage :: LinkOnceODR => "OnceODR" ,
1061
- Linkage :: WeakAny => "WeakAny" ,
1062
- Linkage :: WeakODR => "WeakODR" ,
1063
- Linkage :: Appending => "Appending" ,
1064
- Linkage :: Internal => "Internal" ,
1065
- Linkage :: Private => "Private" ,
1066
- Linkage :: ExternalWeak => "ExternalWeak" ,
1067
- Linkage :: Common => "Common" ,
1068
- } ;
1069
-
1070
- output. push_str ( "[" ) ;
1071
- output. push_str ( linkage_abbrev) ;
1072
- output. push_str ( "]" ) ;
1073
- }
1074
- output
1075
- } )
1076
- . collect ( ) ;
1077
-
1078
- item_keys. sort ( ) ;
1079
-
1080
- for item in item_keys {
1081
- println ! ( "MONO_ITEM {}" , item) ;
1082
- }
1083
- }
1084
-
1085
- ( Arc :: new ( mono_items) , Arc :: new ( codegen_units) )
1086
- }
1087
-
1088
964
impl CrateInfo {
1089
965
pub fn new ( tcx : TyCtxt ) -> CrateInfo {
1090
966
let mut info = CrateInfo {
@@ -1174,12 +1050,6 @@ impl CrateInfo {
1174
1050
}
1175
1051
}
1176
1052
1177
- fn is_codegened_item ( tcx : TyCtxt , id : DefId ) -> bool {
1178
- let ( all_mono_items, _) =
1179
- tcx. collect_and_partition_mono_items ( LOCAL_CRATE ) ;
1180
- all_mono_items. contains ( & id)
1181
- }
1182
-
1183
1053
fn compile_codegen_unit < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1184
1054
cgu_name : InternedString )
1185
1055
-> Stats {
@@ -1270,24 +1140,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1270
1140
}
1271
1141
}
1272
1142
1273
- pub fn provide ( providers : & mut Providers ) {
1274
- providers. collect_and_partition_mono_items =
1275
- collect_and_partition_mono_items;
1276
-
1277
- providers. is_codegened_item = is_codegened_item;
1278
-
1279
- providers. codegen_unit = |tcx, name| {
1280
- let ( _, all) = tcx. collect_and_partition_mono_items ( LOCAL_CRATE ) ;
1281
- all. iter ( )
1282
- . find ( |cgu| * cgu. name ( ) == name)
1283
- . cloned ( )
1284
- . unwrap_or_else ( || panic ! ( "failed to find cgu with name {:?}" , name) )
1285
- } ;
1286
-
1287
- provide_extern ( providers) ;
1288
- }
1289
-
1290
- pub fn provide_extern ( providers : & mut Providers ) {
1143
+ pub fn provide_both ( providers : & mut Providers ) {
1291
1144
providers. dllimport_foreign_items = |tcx, krate| {
1292
1145
let module_map = tcx. foreign_modules ( krate) ;
1293
1146
let module_map = module_map. iter ( )
0 commit comments