@@ -11,6 +11,7 @@ use rustc_middle::ty::print::characteristic_def_id_of_type;
11
11
use rustc_middle:: ty:: { self , DefIdTree , InstanceDef , TyCtxt } ;
12
12
use rustc_span:: symbol:: Symbol ;
13
13
14
+ use super :: PartitioningCx ;
14
15
use crate :: monomorphize:: collector:: InliningMap ;
15
16
use crate :: monomorphize:: partitioning:: merging;
16
17
use crate :: monomorphize:: partitioning:: {
@@ -22,35 +23,36 @@ pub struct DefaultPartitioning;
22
23
impl < ' tcx > Partitioner < ' tcx > for DefaultPartitioning {
23
24
fn place_root_mono_items (
24
25
& mut self ,
25
- tcx : TyCtxt < ' tcx > ,
26
+ cx : & PartitioningCx < ' _ , ' tcx > ,
26
27
mono_items : & mut dyn Iterator < Item = MonoItem < ' tcx > > ,
27
28
) -> PreInliningPartitioning < ' tcx > {
28
29
let mut roots = FxHashSet :: default ( ) ;
29
30
let mut codegen_units = FxHashMap :: default ( ) ;
30
- let is_incremental_build = tcx. sess . opts . incremental . is_some ( ) ;
31
+ let is_incremental_build = cx . tcx . sess . opts . incremental . is_some ( ) ;
31
32
let mut internalization_candidates = FxHashSet :: default ( ) ;
32
33
33
34
// Determine if monomorphizations instantiated in this crate will be made
34
35
// available to downstream crates. This depends on whether we are in
35
36
// share-generics mode and whether the current crate can even have
36
37
// downstream crates.
37
- let export_generics = tcx. sess . opts . share_generics ( ) && tcx. local_crate_exports_generics ( ) ;
38
+ let export_generics =
39
+ cx. tcx . sess . opts . share_generics ( ) && cx. tcx . local_crate_exports_generics ( ) ;
38
40
39
- let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
41
+ let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx . tcx ) ;
40
42
let cgu_name_cache = & mut FxHashMap :: default ( ) ;
41
43
42
44
for mono_item in mono_items {
43
- match mono_item. instantiation_mode ( tcx) {
45
+ match mono_item. instantiation_mode ( cx . tcx ) {
44
46
InstantiationMode :: GloballyShared { .. } => { }
45
47
InstantiationMode :: LocalCopy => continue ,
46
48
}
47
49
48
- let characteristic_def_id = characteristic_def_id_of_mono_item ( tcx, mono_item) ;
50
+ let characteristic_def_id = characteristic_def_id_of_mono_item ( cx . tcx , mono_item) ;
49
51
let is_volatile = is_incremental_build && mono_item. is_generic_fn ( ) ;
50
52
51
53
let codegen_unit_name = match characteristic_def_id {
52
54
Some ( def_id) => compute_codegen_unit_name (
53
- tcx,
55
+ cx . tcx ,
54
56
cgu_name_builder,
55
57
def_id,
56
58
is_volatile,
@@ -65,7 +67,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
65
67
66
68
let mut can_be_internalized = true ;
67
69
let ( linkage, visibility) = mono_item_linkage_and_visibility (
68
- tcx,
70
+ cx . tcx ,
69
71
& mono_item,
70
72
& mut can_be_internalized,
71
73
export_generics,
@@ -97,17 +99,16 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
97
99
98
100
fn merge_codegen_units (
99
101
& mut self ,
100
- tcx : TyCtxt < ' tcx > ,
102
+ cx : & PartitioningCx < ' _ , ' tcx > ,
101
103
initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
102
- target_cgu_count : usize ,
103
104
) {
104
- merging:: merge_codegen_units ( tcx , initial_partitioning, target_cgu_count ) ;
105
+ merging:: merge_codegen_units ( cx , initial_partitioning) ;
105
106
}
106
107
107
108
fn place_inlined_mono_items (
108
109
& mut self ,
110
+ cx : & PartitioningCx < ' _ , ' tcx > ,
109
111
initial_partitioning : PreInliningPartitioning < ' tcx > ,
110
- inlining_map : & InliningMap < ' tcx > ,
111
112
) -> PostInliningPartitioning < ' tcx > {
112
113
let mut new_partitioning = Vec :: new ( ) ;
113
114
let mut mono_item_placements = FxHashMap :: default ( ) ;
@@ -124,7 +125,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
124
125
// Collect all items that need to be available in this codegen unit.
125
126
let mut reachable = FxHashSet :: default ( ) ;
126
127
for root in old_codegen_unit. items ( ) . keys ( ) {
127
- follow_inlining ( * root, inlining_map, & mut reachable) ;
128
+ follow_inlining ( * root, cx . inlining_map , & mut reachable) ;
128
129
}
129
130
130
131
let mut new_codegen_unit = CodegenUnit :: new ( old_codegen_unit. name ( ) ) ;
@@ -198,9 +199,8 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
198
199
199
200
fn internalize_symbols (
200
201
& mut self ,
201
- _tcx : TyCtxt < ' tcx > ,
202
+ cx : & PartitioningCx < ' _ , ' tcx > ,
202
203
partitioning : & mut PostInliningPartitioning < ' tcx > ,
203
- inlining_map : & InliningMap < ' tcx > ,
204
204
) {
205
205
if partitioning. codegen_units . len ( ) == 1 {
206
206
// Fast path for when there is only one codegen unit. In this case we
@@ -218,7 +218,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
218
218
// Build a map from every monomorphization to all the monomorphizations that
219
219
// reference it.
220
220
let mut accessor_map: FxHashMap < MonoItem < ' tcx > , Vec < MonoItem < ' tcx > > > = Default :: default ( ) ;
221
- inlining_map. iter_accesses ( |accessor, accessees| {
221
+ cx . inlining_map . iter_accesses ( |accessor, accessees| {
222
222
for accessee in accessees {
223
223
accessor_map. entry ( * accessee) . or_default ( ) . push ( accessor) ;
224
224
}
0 commit comments