@@ -35,12 +35,11 @@ use rustc_session::Session;
35
35
use rustc_span:: symbol:: sym;
36
36
use rustc_span:: { Span , Symbol } ;
37
37
use std:: borrow:: Cow ;
38
- use std:: fmt:: { self } ;
39
- use std:: sync:: { Arc , Mutex } ;
38
+ use std:: fmt;
40
39
use thin_vec:: ThinVec ;
41
40
42
41
#[ allow( missing_docs) ]
43
- pub fn assert_module_sources ( tcx : TyCtxt < ' _ > , set_reuse : & dyn Fn ( & CguReuseTracker ) ) {
42
+ pub fn assert_module_sources ( tcx : TyCtxt < ' _ > , set_reuse : & dyn Fn ( & mut CguReuseTracker ) ) {
44
43
tcx. dep_graph . with_ignore ( || {
45
44
if tcx. sess . opts . incremental . is_none ( ) {
46
45
return ;
@@ -49,7 +48,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>, set_reuse: &dyn Fn(&CguReuseTracke
49
48
let available_cgus =
50
49
tcx. collect_and_partition_mono_items ( ( ) ) . 1 . iter ( ) . map ( |cgu| cgu. name ( ) ) . collect ( ) ;
51
50
52
- let ams = AssertModuleSource {
51
+ let mut ams = AssertModuleSource {
53
52
tcx,
54
53
available_cgus,
55
54
cgu_reuse_tracker : if tcx. sess . opts . unstable_opts . query_dep_graph {
@@ -63,7 +62,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>, set_reuse: &dyn Fn(&CguReuseTracke
63
62
ams. check_attr ( attr) ;
64
63
}
65
64
66
- set_reuse ( & ams. cgu_reuse_tracker ) ;
65
+ set_reuse ( & mut ams. cgu_reuse_tracker ) ;
67
66
68
67
ams. cgu_reuse_tracker . check_expected_reuse ( tcx. sess ) ;
69
68
} ) ;
@@ -76,7 +75,7 @@ struct AssertModuleSource<'tcx> {
76
75
}
77
76
78
77
impl < ' tcx > AssertModuleSource < ' tcx > {
79
- fn check_attr ( & self , attr : & ast:: Attribute ) {
78
+ fn check_attr ( & mut self , attr : & ast:: Attribute ) {
80
79
let ( expected_reuse, comp_kind) = if attr. has_name ( sym:: rustc_partition_reused) {
81
80
( CguReuse :: PreLto , ComparisonKind :: AtLeast )
82
81
} else if attr. has_name ( sym:: rustc_partition_codegened) {
@@ -220,66 +219,54 @@ pub enum ComparisonKind {
220
219
221
220
struct TrackerData {
222
221
actual_reuse : FxHashMap < String , CguReuse > ,
223
- expected_reuse : FxHashMap < String , ( String , SendSpan , CguReuse , ComparisonKind ) > ,
222
+ expected_reuse : FxHashMap < String , ( String , Span , CguReuse , ComparisonKind ) > ,
224
223
}
225
224
226
- // Span does not implement `Send`, so we can't just store it in the shared
227
- // `TrackerData` object. Instead of splitting up `TrackerData` into shared and
228
- // non-shared parts (which would be complicated), we just mark the `Span` here
229
- // explicitly as `Send`. That's safe because the span data here is only ever
230
- // accessed from the main thread.
231
- struct SendSpan ( Span ) ;
232
- unsafe impl Send for SendSpan { }
233
-
234
- #[ derive( Clone ) ]
235
225
pub struct CguReuseTracker {
236
- data : Option < Arc < Mutex < TrackerData > > > ,
226
+ data : Option < TrackerData > ,
237
227
}
238
228
239
229
impl CguReuseTracker {
240
230
pub fn new ( ) -> CguReuseTracker {
241
231
let data =
242
232
TrackerData { actual_reuse : Default :: default ( ) , expected_reuse : Default :: default ( ) } ;
243
233
244
- CguReuseTracker { data : Some ( Arc :: new ( Mutex :: new ( data) ) ) }
234
+ CguReuseTracker { data : Some ( data) }
245
235
}
246
236
247
237
pub fn new_disabled ( ) -> CguReuseTracker {
248
238
CguReuseTracker { data : None }
249
239
}
250
240
251
- pub fn set_actual_reuse ( & self , cgu_name : & str , kind : CguReuse ) {
252
- if let Some ( ref data) = self . data {
241
+ pub fn set_actual_reuse ( & mut self , cgu_name : & str , kind : CguReuse ) {
242
+ if let Some ( data) = & mut self . data {
253
243
debug ! ( "set_actual_reuse({cgu_name:?}, {kind:?})" ) ;
254
244
255
- let prev_reuse = data. lock ( ) . unwrap ( ) . actual_reuse . insert ( cgu_name. to_string ( ) , kind) ;
245
+ let prev_reuse = data. actual_reuse . insert ( cgu_name. to_string ( ) , kind) ;
256
246
assert ! ( prev_reuse. is_none( ) ) ;
257
247
}
258
248
}
259
249
260
250
pub fn set_expectation (
261
- & self ,
251
+ & mut self ,
262
252
cgu_name : Symbol ,
263
253
cgu_user_name : & str ,
264
254
error_span : Span ,
265
255
expected_reuse : CguReuse ,
266
256
comparison_kind : ComparisonKind ,
267
257
) {
268
- if let Some ( ref data) = self . data {
258
+ if let Some ( data) = & mut self . data {
269
259
debug ! ( "set_expectation({cgu_name:?}, {expected_reuse:?}, {comparison_kind:?})" ) ;
270
- let mut data = data. lock ( ) . unwrap ( ) ;
271
260
272
261
data. expected_reuse . insert (
273
262
cgu_name. to_string ( ) ,
274
- ( cgu_user_name. to_string ( ) , SendSpan ( error_span) , expected_reuse, comparison_kind) ,
263
+ ( cgu_user_name. to_string ( ) , error_span, expected_reuse, comparison_kind) ,
275
264
) ;
276
265
}
277
266
}
278
267
279
268
pub fn check_expected_reuse ( & self , sess : & Session ) {
280
269
if let Some ( ref data) = self . data {
281
- let data = data. lock ( ) . unwrap ( ) ;
282
-
283
270
for ( cgu_name, & ( ref cgu_user_name, ref error_span, expected_reuse, comparison_kind) ) in
284
271
& data. expected_reuse
285
272
{
@@ -292,7 +279,7 @@ impl CguReuseTracker {
292
279
if error {
293
280
let at_least = if at_least { 1 } else { 0 } ;
294
281
errors:: IncorrectCguReuseType {
295
- span : error_span. 0 ,
282
+ span : * error_span,
296
283
cgu_user_name,
297
284
actual_reuse,
298
285
expected_reuse,
0 commit comments