@@ -68,7 +68,7 @@ use common::{node_id_type, fulfill_obligation};
68
68
use common:: { type_is_immediate, type_is_zero_size, val_ty} ;
69
69
use common;
70
70
use consts;
71
- use context:: { SharedCrateContext , CrateContextList } ;
71
+ use context:: SharedCrateContext ;
72
72
use controlflow;
73
73
use datum;
74
74
use debuginfo:: { self , DebugLoc , ToDebugLoc } ;
@@ -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 , CodegenUnit } ;
84
+ use partitioning:: { self , PartitioningStrategy , InstantiationMode } ;
85
85
use symbol_names_test;
86
86
use tvec;
87
87
use type_:: Type ;
@@ -664,7 +664,7 @@ pub fn coerce_unsized_into<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
664
664
}
665
665
}
666
666
667
- pub fn custom_coerce_unsize_info < ' scx , ' tcx > ( scx : & SharedCrateContext < ' scx , ' tcx > ,
667
+ pub fn custom_coerce_unsize_info < ' ccx , ' tcx > ( ccx : & CrateContext < ' ccx , ' tcx > ,
668
668
source_ty : Ty < ' tcx > ,
669
669
target_ty : Ty < ' tcx > )
670
670
-> CustomCoerceUnsized {
@@ -674,13 +674,13 @@ pub fn custom_coerce_unsize_info<'scx, 'tcx>(scx: &SharedCrateContext<'scx, 'tcx
674
674
subst:: VecPerParamSpace :: empty ( ) ) ;
675
675
676
676
let trait_ref = ty:: Binder ( ty:: TraitRef {
677
- def_id : scx . tcx ( ) . lang_items . coerce_unsized_trait ( ) . unwrap ( ) ,
678
- substs : scx . tcx ( ) . mk_substs ( trait_substs)
677
+ def_id : ccx . tcx ( ) . lang_items . coerce_unsized_trait ( ) . unwrap ( ) ,
678
+ substs : ccx . tcx ( ) . mk_substs ( trait_substs)
679
679
} ) ;
680
680
681
- match fulfill_obligation ( scx , DUMMY_SP , trait_ref) {
681
+ match fulfill_obligation ( ccx , DUMMY_SP , trait_ref) {
682
682
traits:: VtableImpl ( traits:: VtableImplData { impl_def_id, .. } ) => {
683
- scx . tcx ( ) . custom_coerce_unsized_kind ( impl_def_id)
683
+ ccx . tcx ( ) . custom_coerce_unsized_kind ( impl_def_id)
684
684
}
685
685
vtable => {
686
686
bug ! ( "invalid CoerceUnsized vtable: {:?}" , vtable) ;
@@ -1824,7 +1824,7 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1824
1824
closure_env : closure:: ClosureEnv ) {
1825
1825
ccx. stats ( ) . n_closures . set ( ccx. stats ( ) . n_closures . get ( ) + 1 ) ;
1826
1826
1827
- if collector:: collecting_debug_information ( ccx. shared ( ) ) {
1827
+ if collector:: collecting_debug_information ( ccx) {
1828
1828
ccx. record_translation_item_as_generated ( TransItem :: Fn ( instance) ) ;
1829
1829
}
1830
1830
@@ -2188,8 +2188,7 @@ pub fn update_linkage(ccx: &CrateContext,
2188
2188
// `llval` is a translation of an item defined in a separate
2189
2189
// compilation unit. This only makes sense if there are at least
2190
2190
// two compilation units.
2191
- assert ! ( ccx. sess( ) . opts. cg. codegen_units > 1 ||
2192
- ccx. sess( ) . opts. debugging_opts. incremental. is_some( ) ) ;
2191
+ assert ! ( ccx. sess( ) . opts. cg. codegen_units > 1 ) ;
2193
2192
// `llval` is a copy of something defined elsewhere, so use
2194
2193
// `AvailableExternallyLinkage` to avoid duplicating code in the
2195
2194
// output.
@@ -2525,7 +2524,7 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>,
2525
2524
2526
2525
/// Find any symbols that are defined in one compilation unit, but not declared
2527
2526
/// in any other compilation unit. Give these symbols internal linkage.
2528
- fn internalize_symbols ( cx : & CrateContextList , reachable : & HashSet < & str > ) {
2527
+ fn internalize_symbols ( cx : & SharedCrateContext , reachable : & HashSet < & str > ) {
2529
2528
unsafe {
2530
2529
let mut declared = HashSet :: new ( ) ;
2531
2530
@@ -2580,12 +2579,12 @@ fn internalize_symbols(cx: &CrateContextList, reachable: &HashSet<&str>) {
2580
2579
// when using MSVC linker. We do this only for data, as linker can fix up
2581
2580
// code references on its own.
2582
2581
// See #26591, #27438
2583
- fn create_imps ( cx : & CrateContextList ) {
2582
+ fn create_imps ( cx : & SharedCrateContext ) {
2584
2583
// The x86 ABI seems to require that leading underscores are added to symbol
2585
2584
// names, so we need an extra underscore on 32-bit. There's also a leading
2586
2585
// '\x01' here which disables LLVM's symbol mangling (e.g. no extra
2587
2586
// underscores added in front).
2588
- let prefix = if cx. shared ( ) . sess ( ) . target . target . target_pointer_width == "32" {
2587
+ let prefix = if cx. sess ( ) . target . target . target_pointer_width == "32" {
2589
2588
"\x01 __imp__"
2590
2589
} else {
2591
2590
"\x01 __imp_"
@@ -2662,10 +2661,10 @@ fn iter_functions(llmod: llvm::ModuleRef) -> ValueIter {
2662
2661
///
2663
2662
/// This list is later used by linkers to determine the set of symbols needed to
2664
2663
/// be exposed from a dynamic library and it's also encoded into the metadata.
2665
- pub fn filter_reachable_ids ( scx : & SharedCrateContext ) -> NodeSet {
2666
- scx . reachable ( ) . iter ( ) . map ( |x| * x) . filter ( |id| {
2664
+ pub fn filter_reachable_ids ( ccx : & SharedCrateContext ) -> NodeSet {
2665
+ ccx . reachable ( ) . iter ( ) . map ( |x| * x) . filter ( |id| {
2667
2666
// First, only worry about nodes which have a symbol name
2668
- scx . item_symbols ( ) . borrow ( ) . contains_key ( id)
2667
+ ccx . item_symbols ( ) . borrow ( ) . contains_key ( id)
2669
2668
} ) . filter ( |& id| {
2670
2669
// Next, we want to ignore some FFI functions that are not exposed from
2671
2670
// this crate. Reachable FFI functions can be lumped into two
@@ -2680,9 +2679,9 @@ pub fn filter_reachable_ids(scx: &SharedCrateContext) -> NodeSet {
2680
2679
//
2681
2680
// As a result, if this id is an FFI item (foreign item) then we only
2682
2681
// let it through if it's included statically.
2683
- match scx . tcx ( ) . map . get ( id) {
2682
+ match ccx . tcx ( ) . map . get ( id) {
2684
2683
hir_map:: NodeForeignItem ( ..) => {
2685
- scx . sess ( ) . cstore . is_statically_included_foreign_item ( id)
2684
+ ccx . sess ( ) . cstore . is_statically_included_foreign_item ( id)
2686
2685
}
2687
2686
_ => true ,
2688
2687
}
@@ -2717,7 +2716,10 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
2717
2716
2718
2717
let link_meta = link:: build_link_meta ( & tcx, name) ;
2719
2718
2720
- let shared_ccx = SharedCrateContext :: new ( tcx,
2719
+ let codegen_units = tcx. sess . opts . cg . codegen_units ;
2720
+ let shared_ccx = SharedCrateContext :: new ( & link_meta. crate_name ,
2721
+ codegen_units,
2722
+ tcx,
2721
2723
& mir_map,
2722
2724
export_map,
2723
2725
Sha256 :: new ( ) ,
@@ -2726,15 +2728,9 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
2726
2728
check_overflow,
2727
2729
check_dropflag) ;
2728
2730
2729
- let codegen_units = collect_and_partition_translation_items ( & shared_ccx) ;
2730
- let codegen_unit_count = codegen_units. len ( ) ;
2731
- assert ! ( tcx. sess. opts. cg. codegen_units == codegen_unit_count ||
2732
- tcx. sess. opts. debugging_opts. incremental. is_some( ) ) ;
2733
-
2734
- let crate_context_list = CrateContextList :: new ( & shared_ccx, codegen_units) ;
2735
-
2736
2731
{
2737
- let ccx = crate_context_list. get_ccx ( 0 ) ;
2732
+ let ccx = shared_ccx. get_ccx ( 0 ) ;
2733
+ collect_translation_items ( & ccx) ;
2738
2734
2739
2735
// Translate all items. See `TransModVisitor` for
2740
2736
// details on why we walk in this particular way.
@@ -2744,12 +2740,12 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
2744
2740
krate. visit_all_items ( & mut TransModVisitor { ccx : & ccx } ) ;
2745
2741
}
2746
2742
2747
- collector:: print_collection_results ( ccx. shared ( ) ) ;
2743
+ collector:: print_collection_results ( & ccx) ;
2748
2744
2749
2745
symbol_names_test:: report_symbol_names ( & ccx) ;
2750
2746
}
2751
2747
2752
- for ccx in crate_context_list . iter ( ) {
2748
+ for ccx in shared_ccx . iter ( ) {
2753
2749
if ccx. sess ( ) . opts . debuginfo != NoDebugInfo {
2754
2750
debuginfo:: finalize ( & ccx) ;
2755
2751
}
@@ -2798,7 +2794,7 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
2798
2794
}
2799
2795
}
2800
2796
2801
- let modules = crate_context_list . iter ( )
2797
+ let modules = shared_ccx . iter ( )
2802
2798
. map ( |ccx| ModuleTranslation { llcx : ccx. llcx ( ) , llmod : ccx. llmod ( ) } )
2803
2799
. collect ( ) ;
2804
2800
@@ -2824,14 +2820,14 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
2824
2820
}
2825
2821
}
2826
2822
2827
- if codegen_unit_count > 1 {
2828
- internalize_symbols ( & crate_context_list ,
2823
+ if codegen_units > 1 {
2824
+ internalize_symbols ( & shared_ccx ,
2829
2825
& reachable_symbols. iter ( ) . map ( |x| & x[ ..] ) . collect ( ) ) ;
2830
2826
}
2831
2827
2832
2828
if sess. target . target . options . is_like_msvc &&
2833
2829
sess. crate_types . borrow ( ) . iter ( ) . any ( |ct| * ct == config:: CrateTypeRlib ) {
2834
- create_imps ( & crate_context_list ) ;
2830
+ create_imps ( & shared_ccx ) ;
2835
2831
}
2836
2832
2837
2833
let metadata_module = ModuleTranslation {
@@ -2916,11 +2912,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TransItemsWithinModVisitor<'a, 'tcx> {
2916
2912
}
2917
2913
}
2918
2914
2919
- fn collect_and_partition_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > )
2920
- -> Vec < CodegenUnit < ' tcx > > {
2921
- let time_passes = scx. sess ( ) . time_passes ( ) ;
2915
+ fn collect_translation_items < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ) {
2916
+ let time_passes = ccx. sess ( ) . time_passes ( ) ;
2922
2917
2923
- let collection_mode = match scx . sess ( ) . opts . debugging_opts . print_trans_items {
2918
+ let collection_mode = match ccx . sess ( ) . opts . debugging_opts . print_trans_items {
2924
2919
Some ( ref s) => {
2925
2920
let mode_string = s. to_lowercase ( ) ;
2926
2921
let mode_string = mode_string. trim ( ) ;
@@ -2931,7 +2926,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
2931
2926
let message = format ! ( "Unknown codegen-item collection mode '{}'. \
2932
2927
Falling back to 'lazy' mode.",
2933
2928
mode_string) ;
2934
- scx . sess ( ) . warn ( & message) ;
2929
+ ccx . sess ( ) . warn ( & message) ;
2935
2930
}
2936
2931
2937
2932
TransItemCollectionMode :: Lazy
@@ -2941,27 +2936,27 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
2941
2936
} ;
2942
2937
2943
2938
let ( items, reference_map) = time ( time_passes, "translation item collection" , || {
2944
- collector:: collect_crate_translation_items ( scx , collection_mode)
2939
+ collector:: collect_crate_translation_items ( & ccx , collection_mode)
2945
2940
} ) ;
2946
2941
2947
- let strategy = if scx . sess ( ) . opts . debugging_opts . incremental . is_some ( ) {
2942
+ let strategy = if ccx . sess ( ) . opts . debugging_opts . incremental . is_some ( ) {
2948
2943
PartitioningStrategy :: PerModule
2949
2944
} else {
2950
- PartitioningStrategy :: FixedUnitCount ( scx . sess ( ) . opts . cg . codegen_units )
2945
+ PartitioningStrategy :: FixedUnitCount ( ccx . sess ( ) . opts . cg . codegen_units )
2951
2946
} ;
2952
2947
2953
2948
let codegen_units = time ( time_passes, "codegen unit partitioning" , || {
2954
- partitioning:: partition ( scx . tcx ( ) ,
2949
+ partitioning:: partition ( ccx . tcx ( ) ,
2955
2950
items. iter ( ) . cloned ( ) ,
2956
2951
strategy,
2957
2952
& reference_map)
2958
2953
} ) ;
2959
2954
2960
- if scx . sess ( ) . opts . debugging_opts . print_trans_items . is_some ( ) {
2955
+ if ccx . sess ( ) . opts . debugging_opts . print_trans_items . is_some ( ) {
2961
2956
let mut item_to_cgus = HashMap :: new ( ) ;
2962
2957
2963
- for cgu in & codegen_units {
2964
- for ( & trans_item, & linkage) in & cgu. items {
2958
+ for cgu in codegen_units {
2959
+ for ( trans_item, linkage) in cgu. items {
2965
2960
item_to_cgus. entry ( trans_item)
2966
2961
. or_insert ( Vec :: new ( ) )
2967
2962
. push ( ( cgu. name . clone ( ) , linkage) ) ;
@@ -2971,7 +2966,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
2971
2966
let mut item_keys: Vec < _ > = items
2972
2967
. iter ( )
2973
2968
. map ( |i| {
2974
- let mut output = i. to_string ( scx . tcx ( ) ) ;
2969
+ let mut output = i. to_string ( ccx ) ;
2975
2970
output. push_str ( " @@" ) ;
2976
2971
let mut empty = Vec :: new ( ) ;
2977
2972
let mut cgus = item_to_cgus. get_mut ( i) . unwrap_or ( & mut empty) ;
@@ -3010,12 +3005,10 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
3010
3005
println ! ( "TRANS_ITEM {}" , item) ;
3011
3006
}
3012
3007
3013
- let mut ccx_map = scx . translation_items ( ) . borrow_mut ( ) ;
3008
+ let mut ccx_map = ccx . translation_items ( ) . borrow_mut ( ) ;
3014
3009
3015
3010
for cgi in items {
3016
3011
ccx_map. insert ( cgi, TransItemState :: PredictedButNotGenerated ) ;
3017
3012
}
3018
3013
}
3019
-
3020
- codegen_units
3021
3014
}
0 commit comments