@@ -35,12 +35,11 @@ use rustc_session::Session;
3535use rustc_span:: symbol:: sym;
3636use rustc_span:: { Span , Symbol } ;
3737use std:: borrow:: Cow ;
38- use std:: fmt:: { self } ;
39- use std:: sync:: { Arc , Mutex } ;
38+ use std:: fmt;
4039use thin_vec:: ThinVec ;
4140
4241#[ 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 ) ) {
4443 tcx. dep_graph . with_ignore ( || {
4544 if tcx. sess . opts . incremental . is_none ( ) {
4645 return ;
@@ -49,7 +48,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>, set_reuse: &dyn Fn(&CguReuseTracke
4948 let available_cgus =
5049 tcx. collect_and_partition_mono_items ( ( ) ) . 1 . iter ( ) . map ( |cgu| cgu. name ( ) ) . collect ( ) ;
5150
52- let ams = AssertModuleSource {
51+ let mut ams = AssertModuleSource {
5352 tcx,
5453 available_cgus,
5554 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
6362 ams. check_attr ( attr) ;
6463 }
6564
66- set_reuse ( & ams. cgu_reuse_tracker ) ;
65+ set_reuse ( & mut ams. cgu_reuse_tracker ) ;
6766
6867 ams. cgu_reuse_tracker . check_expected_reuse ( tcx. sess ) ;
6968 } ) ;
@@ -76,7 +75,7 @@ struct AssertModuleSource<'tcx> {
7675}
7776
7877impl < ' tcx > AssertModuleSource < ' tcx > {
79- fn check_attr ( & self , attr : & ast:: Attribute ) {
78+ fn check_attr ( & mut self , attr : & ast:: Attribute ) {
8079 let ( expected_reuse, comp_kind) = if attr. has_name ( sym:: rustc_partition_reused) {
8180 ( CguReuse :: PreLto , ComparisonKind :: AtLeast )
8281 } else if attr. has_name ( sym:: rustc_partition_codegened) {
@@ -220,66 +219,54 @@ pub enum ComparisonKind {
220219
221220struct TrackerData {
222221 actual_reuse : FxHashMap < String , CguReuse > ,
223- expected_reuse : FxHashMap < String , ( String , SendSpan , CguReuse , ComparisonKind ) > ,
222+ expected_reuse : FxHashMap < String , ( String , Span , CguReuse , ComparisonKind ) > ,
224223}
225224
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 ) ]
235225pub struct CguReuseTracker {
236- data : Option < Arc < Mutex < TrackerData > > > ,
226+ data : Option < TrackerData > ,
237227}
238228
239229impl CguReuseTracker {
240230 pub fn new ( ) -> CguReuseTracker {
241231 let data =
242232 TrackerData { actual_reuse : Default :: default ( ) , expected_reuse : Default :: default ( ) } ;
243233
244- CguReuseTracker { data : Some ( Arc :: new ( Mutex :: new ( data) ) ) }
234+ CguReuseTracker { data : Some ( data) }
245235 }
246236
247237 pub fn new_disabled ( ) -> CguReuseTracker {
248238 CguReuseTracker { data : None }
249239 }
250240
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 {
253243 debug ! ( "set_actual_reuse({cgu_name:?}, {kind:?})" ) ;
254244
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) ;
256246 assert ! ( prev_reuse. is_none( ) ) ;
257247 }
258248 }
259249
260250 pub fn set_expectation (
261- & self ,
251+ & mut self ,
262252 cgu_name : Symbol ,
263253 cgu_user_name : & str ,
264254 error_span : Span ,
265255 expected_reuse : CguReuse ,
266256 comparison_kind : ComparisonKind ,
267257 ) {
268- if let Some ( ref data) = self . data {
258+ if let Some ( data) = & mut self . data {
269259 debug ! ( "set_expectation({cgu_name:?}, {expected_reuse:?}, {comparison_kind:?})" ) ;
270- let mut data = data. lock ( ) . unwrap ( ) ;
271260
272261 data. expected_reuse . insert (
273262 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) ,
275264 ) ;
276265 }
277266 }
278267
279268 pub fn check_expected_reuse ( & self , sess : & Session ) {
280269 if let Some ( ref data) = self . data {
281- let data = data. lock ( ) . unwrap ( ) ;
282-
283270 for ( cgu_name, & ( ref cgu_user_name, ref error_span, expected_reuse, comparison_kind) ) in
284271 & data. expected_reuse
285272 {
@@ -292,7 +279,7 @@ impl CguReuseTracker {
292279 if error {
293280 let at_least = if at_least { 1 } else { 0 } ;
294281 errors:: IncorrectCguReuseType {
295- span : error_span. 0 ,
282+ span : * error_span,
296283 cgu_user_name,
297284 actual_reuse,
298285 expected_reuse,
0 commit comments