@@ -14,13 +14,10 @@ pub use crate::*;
14
14
15
15
use rustc_data_structures:: fx:: FxHashMap ;
16
16
use 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 } ;
20
18
use std:: cmp;
21
19
use std:: hash:: Hash ;
22
20
use std:: path:: { self , Path , PathBuf } ;
23
- use std:: sync:: atomic:: Ordering ;
24
21
25
22
use std:: fs;
26
23
use std:: io;
@@ -187,9 +184,6 @@ pub(super) struct SourceMapFiles {
187
184
}
188
185
189
186
pub 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
-
193
187
files : RwLock < SourceMapFiles > ,
194
188
file_loader : IntoDynSyncSend < Box < dyn FileLoader + Sync + Send > > ,
195
189
// This is used to apply the file path remapping as specified via
@@ -215,7 +209,6 @@ impl SourceMap {
215
209
hash_kind : SourceFileHashAlgorithm ,
216
210
) -> SourceMap {
217
211
SourceMap {
218
- used_address_space : AtomicU32 :: new ( 0 ) ,
219
212
files : Default :: default ( ) ,
220
213
file_loader : IntoDynSyncSend ( file_loader) ,
221
214
path_mapping,
@@ -271,31 +264,18 @@ impl SourceMap {
271
264
& self ,
272
265
mut file : SourceFile ,
273
266
) -> 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) ;
295
267
let file_id = StableSourceFileId :: new ( & file) ;
296
268
297
269
let mut files = self . files . borrow_mut ( ) ;
298
270
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
+
299
279
let file = Lrc :: new ( file) ;
300
280
files. source_files . push ( file. clone ( ) ) ;
301
281
files. stable_id_to_source_file . insert ( file_id, file. clone ( ) ) ;
0 commit comments