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