@@ -111,6 +111,67 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning {
111
111
// and deterministic.
112
112
codegen_units. sort_by ( |a, b| a. name ( ) . as_str ( ) . cmp ( b. name ( ) . as_str ( ) ) ) ;
113
113
114
+ //---------------------------------------------------------------------------
115
+ // njn: split big CGUs if necessary
116
+ if false && codegen_units. len ( ) > cx. target_cgu_count {
117
+ // njn: type ann?
118
+ let total_size: usize = codegen_units. iter ( ) . map ( |cgu| cgu. size_estimate ( ) ) . sum ( ) ;
119
+ let target_size = total_size / cx. target_cgu_count ;
120
+ eprintln ! ( "----" ) ;
121
+ eprintln ! ( "SPLIT0: total:{} target:{}" , total_size, target_size) ;
122
+ // njn: need a while loop because we're modifying codegen_units as we go
123
+ // njn: make it a for loop?
124
+ // njn: explain all this
125
+ let mut i = 0 ;
126
+ let n = codegen_units. len ( ) ;
127
+ while i < n {
128
+ let old_cgu = & mut codegen_units[ i] ;
129
+ if old_cgu. size_estimate ( ) > target_size && old_cgu. items ( ) . len ( ) > 1 {
130
+ eprintln ! ( "SPLIT1: old:{} old:{}" , old_cgu. size_estimate( ) , old_cgu. name( ) ) ;
131
+
132
+ // njn: too big; split
133
+ // njn: explain how a very big CGU will be split multiple
134
+ // times
135
+
136
+ let mut new_name = old_cgu. name ( ) . to_string ( ) ;
137
+ new_name += "-split" ;
138
+ let mut new_cgu = CodegenUnit :: new ( Symbol :: intern ( & new_name) ) ;
139
+ new_cgu. create_size_estimate ( cx. tcx ) ; // initially zero
140
+
141
+ // njn: size stuff is a bit clumsy
142
+ let mut moved_size = 0 ;
143
+
144
+ // njn: what if this empties old_cgu?
145
+
146
+ // njn: nicer way to do this?
147
+ // njn: don't move if it's the last item
148
+ old_cgu. items_mut ( ) . drain_filter ( |item, rest| {
149
+ // njn: true->remove
150
+ if moved_size < target_size {
151
+ let item_size = item. size_estimate ( cx. tcx ) ;
152
+ eprintln ! ( "MOVE: {}" , item_size) ;
153
+ moved_size += item_size;
154
+ new_cgu. items_mut ( ) . insert ( * item, * rest) ;
155
+ true
156
+ } else {
157
+ false
158
+ }
159
+ } ) ;
160
+ new_cgu. increase_size_estimate ( moved_size) ;
161
+ old_cgu. decrease_size_estimate ( moved_size) ;
162
+
163
+ eprintln ! ( "SPLIT2: old:{} -> new:{} new:{}" , old_cgu. size_estimate( ) , new_cgu. size_estimate( ) , new_cgu. name( ) ) ;
164
+
165
+ codegen_units. push ( new_cgu) ;
166
+ // njn: explain lack of `i += 1`;
167
+ } else {
168
+ // njn: explain this
169
+ i += 1 ;
170
+ }
171
+ }
172
+ }
173
+ //---------------------------------------------------------------------------
174
+
114
175
// This map keeps track of what got merged into what.
115
176
let mut cgu_contents: FxHashMap < Symbol , Vec < Symbol > > =
116
177
codegen_units. iter ( ) . map ( |cgu| ( cgu. name ( ) , vec ! [ cgu. name( ) ] ) ) . collect ( ) ;
@@ -124,7 +185,7 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning {
124
185
let second_smallest = codegen_units. last_mut ( ) . unwrap ( ) ;
125
186
126
187
// Move the mono-items from `smallest` to `second_smallest`
127
- second_smallest. modify_size_estimate ( smallest. size_estimate ( ) ) ;
188
+ second_smallest. increase_size_estimate ( smallest. size_estimate ( ) ) ;
128
189
for ( k, v) in smallest. items_mut ( ) . drain ( ) {
129
190
second_smallest. items_mut ( ) . insert ( k, v) ;
130
191
}
0 commit comments