@@ -81,7 +81,7 @@ use machine::{llalign_of_min, llsize_of, llsize_of_real};
81
81
use meth;
82
82
use mir;
83
83
use monomorphize:: { self , Instance } ;
84
- use partitioning:: { self , PartitioningStrategy , InstantiationMode } ;
84
+ use partitioning:: { self , PartitioningStrategy , InstantiationMode , CodegenUnit } ;
85
85
use symbol_names_test;
86
86
use tvec;
87
87
use type_:: Type ;
@@ -2186,7 +2186,8 @@ pub fn update_linkage(ccx: &CrateContext,
2186
2186
// `llval` is a translation of an item defined in a separate
2187
2187
// compilation unit. This only makes sense if there are at least
2188
2188
// two compilation units.
2189
- assert ! ( ccx. sess( ) . opts. cg. codegen_units > 1 ) ;
2189
+ assert ! ( ccx. sess( ) . opts. cg. codegen_units > 1 ||
2190
+ ccx. sess( ) . opts. debugging_opts. incremental. is_some( ) ) ;
2190
2191
// `llval` is a copy of something defined elsewhere, so use
2191
2192
// `AvailableExternallyLinkage` to avoid duplicating code in the
2192
2193
// output.
@@ -2723,12 +2724,15 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
2723
2724
check_overflow,
2724
2725
check_dropflag) ;
2725
2726
2726
- let codegen_units = tcx. sess . opts . cg . codegen_units ;
2727
+ let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
2728
+ let codegen_unit_count = codegen_units. len ( ) ;
2729
+ assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
2730
+ tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
2731
+
2727
2732
let crate_context_list = CrateContextList :: new ( & shared_ccx, codegen_units) ;
2728
2733
2729
2734
{
2730
2735
let ccx = crate_context_list. get_ccx ( 0 ) ;
2731
- collect_translation_items ( & ccx) ;
2732
2736
2733
2737
// Translate all items. See `TransModVisitor` for
2734
2738
// details on why we walk in this particular way.
@@ -2818,7 +2822,7 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
2818
2822
}
2819
2823
}
2820
2824
2821
- if codegen_units > 1 {
2825
+ if codegen_unit_count > 1 {
2822
2826
internalize_symbols ( & crate_context_list,
2823
2827
& reachable_symbols. iter ( ) . map ( |x| & x[ ..] ) . collect ( ) ) ;
2824
2828
}
@@ -2910,10 +2914,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TransItemsWithinModVisitor<'a, 'tcx> {
2910
2914
}
2911
2915
}
2912
2916
2913
- fn collect_translation_items < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ) {
2914
- let time_passes = ccx. sess ( ) . time_passes ( ) ;
2917
+ fn collect_and_partition_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > )
2918
+ -> Vec < CodegenUnit < ' tcx > > {
2919
+ let time_passes = scx. sess ( ) . time_passes ( ) ;
2915
2920
2916
- let collection_mode = match ccx . sess ( ) . opts . debugging_opts . print_trans_items {
2921
+ let collection_mode = match scx . sess ( ) . opts . debugging_opts . print_trans_items {
2917
2922
Some ( ref s) => {
2918
2923
let mode_string = s. to_lowercase ( ) ;
2919
2924
let mode_string = mode_string. trim ( ) ;
@@ -2924,7 +2929,7 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
2924
2929
let message = format ! ( "Unknown codegen-item collection mode '{}'. \
2925
2930
Falling back to 'lazy' mode.",
2926
2931
mode_string) ;
2927
- ccx . sess ( ) . warn ( & message) ;
2932
+ scx . sess ( ) . warn ( & message) ;
2928
2933
}
2929
2934
2930
2935
TransItemCollectionMode :: Lazy
@@ -2934,27 +2939,27 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
2934
2939
} ;
2935
2940
2936
2941
let ( items, reference_map) = time ( time_passes, "translation item collection" , || {
2937
- collector:: collect_crate_translation_items ( ccx . shared ( ) , collection_mode)
2942
+ collector:: collect_crate_translation_items ( scx , collection_mode)
2938
2943
} ) ;
2939
2944
2940
- let strategy = if ccx . sess ( ) . opts . debugging_opts . incremental . is_some ( ) {
2945
+ let strategy = if scx . sess ( ) . opts . debugging_opts . incremental . is_some ( ) {
2941
2946
PartitioningStrategy :: PerModule
2942
2947
} else {
2943
- PartitioningStrategy :: FixedUnitCount ( ccx . sess ( ) . opts . cg . codegen_units )
2948
+ PartitioningStrategy :: FixedUnitCount ( scx . sess ( ) . opts . cg . codegen_units )
2944
2949
} ;
2945
2950
2946
2951
let codegen_units = time ( time_passes, "codegen unit partitioning" , || {
2947
- partitioning:: partition ( ccx . tcx ( ) ,
2952
+ partitioning:: partition ( scx . tcx ( ) ,
2948
2953
items. iter ( ) . cloned ( ) ,
2949
2954
strategy,
2950
2955
& reference_map)
2951
2956
} ) ;
2952
2957
2953
- if ccx . sess ( ) . opts . debugging_opts . print_trans_items . is_some ( ) {
2958
+ if scx . sess ( ) . opts . debugging_opts . print_trans_items . is_some ( ) {
2954
2959
let mut item_to_cgus = HashMap :: new ( ) ;
2955
2960
2956
- for cgu in codegen_units {
2957
- for ( trans_item, linkage) in cgu. items {
2961
+ for cgu in & codegen_units {
2962
+ for ( & trans_item, & linkage) in & cgu. items {
2958
2963
item_to_cgus. entry ( trans_item)
2959
2964
. or_insert ( Vec :: new ( ) )
2960
2965
. push ( ( cgu. name . clone ( ) , linkage) ) ;
@@ -2964,7 +2969,7 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
2964
2969
let mut item_keys: Vec < _ > = items
2965
2970
. iter ( )
2966
2971
. map ( |i| {
2967
- let mut output = i. to_string ( ccx . tcx ( ) ) ;
2972
+ let mut output = i. to_string ( scx . tcx ( ) ) ;
2968
2973
output. push_str ( " @@" ) ;
2969
2974
let mut empty = Vec :: new ( ) ;
2970
2975
let mut cgus = item_to_cgus. get_mut ( i) . unwrap_or ( & mut empty) ;
@@ -3003,10 +3008,12 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
3003
3008
println ! ( "TRANS_ITEM {}" , item) ;
3004
3009
}
3005
3010
3006
- let mut ccx_map = ccx . translation_items ( ) . borrow_mut ( ) ;
3011
+ let mut ccx_map = scx . translation_items ( ) . borrow_mut ( ) ;
3007
3012
3008
3013
for cgi in items {
3009
3014
ccx_map. insert ( cgi, TransItemState :: PredictedButNotGenerated ) ;
3010
3015
}
3011
3016
}
3017
+
3018
+ codegen_units
3012
3019
}
0 commit comments