@@ -14,13 +14,10 @@ pub use crate::*;
1414
1515use rustc_data_structures:: fx:: FxHashMap ;
1616use rustc_data_structures:: stable_hasher:: { Hash128 , Hash64 , StableHasher } ;
17- use rustc_data_structures:: sync:: {
18- AtomicU32 , IntoDynSyncSend , Lrc , MappedReadGuard , ReadGuard , RwLock ,
19- } ;
17+ use rustc_data_structures:: sync:: { IntoDynSyncSend , Lrc , MappedReadGuard , ReadGuard , RwLock } ;
2018use std:: cmp;
2119use std:: hash:: Hash ;
2220use std:: path:: { self , Path , PathBuf } ;
23- use std:: sync:: atomic:: Ordering ;
2421
2522use std:: fs;
2623use std:: io;
@@ -187,9 +184,6 @@ pub(super) struct SourceMapFiles {
187184}
188185
189186pub struct SourceMap {
190- /// The address space below this value is currently used by the files in the source map.
191- used_address_space : AtomicU32 ,
192-
193187 files : RwLock < SourceMapFiles > ,
194188 file_loader : IntoDynSyncSend < Box < dyn FileLoader + Sync + Send > > ,
195189 // This is used to apply the file path remapping as specified via
@@ -215,7 +209,6 @@ impl SourceMap {
215209 hash_kind : SourceFileHashAlgorithm ,
216210 ) -> SourceMap {
217211 SourceMap {
218- used_address_space : AtomicU32 :: new ( 0 ) ,
219212 files : Default :: default ( ) ,
220213 file_loader : IntoDynSyncSend ( file_loader) ,
221214 path_mapping,
@@ -271,31 +264,18 @@ impl SourceMap {
271264 & self ,
272265 mut file : SourceFile ,
273266 ) -> Result < Lrc < SourceFile > , OffsetOverflowError > {
274- let size = file. source_len . to_u32 ( ) ;
275-
276- let start_pos = loop {
277- let current = self . used_address_space . load ( Ordering :: Relaxed ) ;
278- let next = current
279- . checked_add ( size)
280- // Add one so there is some space between files. This lets us distinguish
281- // positions in the `SourceMap`, even in the presence of zero-length files.
282- . and_then ( |next| next. checked_add ( 1 ) )
283- . ok_or ( OffsetOverflowError ) ?;
284-
285- if self
286- . used_address_space
287- . compare_exchange ( current, next, Ordering :: Relaxed , Ordering :: Relaxed )
288- . is_ok ( )
289- {
290- break usize:: try_from ( current) . unwrap ( ) ;
291- }
292- } ;
293-
294- file. start_pos = BytePos :: from_usize ( start_pos) ;
295267 let file_id = StableSourceFileId :: new ( & file) ;
296268
297269 let mut files = self . files . borrow_mut ( ) ;
298270
271+ file. start_pos = BytePos ( if let Some ( last_file) = files. source_files . last ( ) {
272+ // Add one so there is some space between files. This lets us distinguish
273+ // positions in the `SourceMap`, even in the presence of zero-length files.
274+ last_file. end_position ( ) . 0 . checked_add ( 1 ) . ok_or ( OffsetOverflowError ) ?
275+ } else {
276+ 0
277+ } ) ;
278+
299279 let file = Lrc :: new ( file) ;
300280 files. source_files . push ( file. clone ( ) ) ;
301281 files. stable_id_to_source_file . insert ( file_id, file. clone ( ) ) ;
0 commit comments