@@ -15,11 +15,11 @@ pub use crate::*;
15
15
use rustc_data_structures:: fx:: FxHashMap ;
16
16
use rustc_data_structures:: stable_hasher:: StableHasher ;
17
17
use rustc_data_structures:: sync:: { AtomicU32 , Lrc , MappedReadGuard , ReadGuard , RwLock } ;
18
- use std:: cmp;
19
18
use std:: convert:: TryFrom ;
20
19
use std:: hash:: Hash ;
21
20
use std:: path:: { Path , PathBuf } ;
22
21
use std:: sync:: atomic:: Ordering ;
22
+ use std:: { clone:: Clone , cmp} ;
23
23
24
24
use std:: fs;
25
25
use std:: io;
@@ -283,45 +283,28 @@ impl SourceMap {
283
283
284
284
fn try_new_source_file (
285
285
& self ,
286
- mut filename : FileName ,
286
+ filename : FileName ,
287
287
src : String ,
288
288
) -> Result < Lrc < SourceFile > , OffsetOverflowError > {
289
- // The path is used to determine the directory for loading submodules and
290
- // include files, so it must be before remapping .
289
+ // We need to preserve the unmapped path is as it is
290
+ // used to determine the directory for loading submodules and include files .
291
291
// Note that filename may not be a valid path, eg it may be `<anon>` etc,
292
292
// but this is okay because the directory determined by `path.pop()` will
293
293
// be empty, so the working directory will be used.
294
- let unmapped_path = filename. clone ( ) ;
295
-
296
- let was_remapped;
297
- if let FileName :: Real ( real_filename) = & mut filename {
298
- match real_filename {
299
- RealFileName :: Named ( path_to_be_remapped)
300
- | RealFileName :: Devirtualized {
301
- local_path : path_to_be_remapped,
302
- virtual_name : _,
303
- } => {
304
- let mapped = self . path_mapping . map_prefix ( path_to_be_remapped. clone ( ) ) ;
305
- was_remapped = mapped. 1 ;
306
- * path_to_be_remapped = mapped. 0 ;
307
- }
308
- }
309
- } else {
310
- was_remapped = false ;
311
- }
294
+ let ( mapped_filename, was_remapped) = self . path_mapping . map_filename_prefix ( & filename) ;
312
295
313
296
let file_id =
314
- StableSourceFileId :: new_from_pieces ( & filename , was_remapped, Some ( & unmapped_path ) ) ;
297
+ StableSourceFileId :: new_from_pieces ( & mapped_filename , was_remapped, Some ( & filename ) ) ;
315
298
316
299
let lrc_sf = match self . source_file_by_stable_id ( file_id) {
317
300
Some ( lrc_sf) => lrc_sf,
318
301
None => {
319
302
let start_pos = self . allocate_address_space ( src. len ( ) ) ?;
320
303
321
304
let source_file = Lrc :: new ( SourceFile :: new (
322
- filename ,
305
+ mapped_filename ,
323
306
was_remapped,
324
- unmapped_path ,
307
+ filename ,
325
308
src,
326
309
Pos :: from_usize ( start_pos) ,
327
310
self . hash_kind ,
@@ -380,9 +363,11 @@ impl SourceMap {
380
363
nc. pos = nc. pos + start_pos;
381
364
}
382
365
366
+ let ( filename, name_is_remapped) = self . path_mapping . map_filename_prefix ( & filename) ;
367
+
383
368
let source_file = Lrc :: new ( SourceFile {
384
369
name : filename,
385
- name_was_remapped,
370
+ name_was_remapped : name_was_remapped || name_is_remapped ,
386
371
unmapped_path : None ,
387
372
src : None ,
388
373
src_hash,
@@ -1046,9 +1031,26 @@ impl FilePathMapping {
1046
1031
fn map_filename_prefix ( & self , file : & FileName ) -> ( FileName , bool ) {
1047
1032
match file {
1048
1033
FileName :: Real ( realfile) => {
1049
- let path = realfile. local_path ( ) ;
1050
- let ( path, mapped) = self . map_prefix ( path. to_path_buf ( ) ) ;
1051
- ( FileName :: Real ( RealFileName :: Named ( path) ) , mapped)
1034
+ // If the file is the Name variant with only local_path, then clearly we want to map that
1035
+ // to a virtual_name
1036
+ // If the file is already Virtualized, then we want to map virtual_name further
1037
+ // but we leave local_path alone
1038
+ let path = realfile. stable_name ( ) ;
1039
+ let ( mapped_path, mapped) = self . map_prefix ( path. to_path_buf ( ) ) ;
1040
+ if mapped {
1041
+ let mapped_realfile = match realfile {
1042
+ RealFileName :: Named ( local_path)
1043
+ | RealFileName :: Virtualized { local_path, virtual_name : _ } => {
1044
+ RealFileName :: Virtualized {
1045
+ local_path : local_path. clone ( ) ,
1046
+ virtual_name : mapped_path,
1047
+ }
1048
+ }
1049
+ } ;
1050
+ ( FileName :: Real ( mapped_realfile) , mapped)
1051
+ } else {
1052
+ ( file. clone ( ) , false )
1053
+ }
1052
1054
}
1053
1055
other => ( other. clone ( ) , false ) ,
1054
1056
}
0 commit comments