Skip to content

Commit ca30ad1

Browse files
committed
Remove unmapped_path from SourceFile as information can be obtained from virtualized name
1 parent b1a74bd commit ca30ad1

File tree

7 files changed

+12
-48
lines changed

7 files changed

+12
-48
lines changed

compiler/rustc_expand/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ impl<'a> ExtCtxt<'a> {
11141114
// after macro expansion (that is, they are unhygienic).
11151115
if !path.is_absolute() {
11161116
let callsite = span.source_callsite();
1117-
let mut result = match self.source_map().span_to_unmapped_path(callsite) {
1117+
let mut result = match self.source_map().span_to_filename(callsite) {
11181118
FileName::Real(name) => name.into_local_path(),
11191119
FileName::DocTest(path, _) => path,
11201120
other => {

compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
361361
// FIXME: Avoid visiting the crate as a `Mod` item,
362362
// make crate a first class expansion target instead.
363363
pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
364-
let file_path = match self.cx.source_map().span_to_unmapped_path(krate.span) {
364+
let file_path = match self.cx.source_map().span_to_filename(krate.span) {
365365
FileName::Real(name) => name.into_local_path(),
366366
other => PathBuf::from(other.to_string()),
367367
};

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ fn write_out_deps(
575575
.iter()
576576
.filter(|fmap| fmap.is_real_file())
577577
.filter(|fmap| !fmap.is_imported())
578-
.map(|fmap| escape_dep_filename(&fmap.unmapped_path.as_ref().unwrap_or(&fmap.name)))
578+
.map(|fmap| escape_dep_filename(&fmap.name))
579579
.collect();
580580

581581
if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {

compiler/rustc_middle/src/ich/impls_syntax.rs

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
6262
name: _, // We hash the smaller name_hash instead of this
6363
name_hash,
6464
name_was_remapped,
65-
unmapped_path: _,
6665
cnum,
6766
// Do not hash the source as it is not encoded
6867
src: _,

compiler/rustc_span/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1120,10 +1120,6 @@ pub struct SourceFile {
11201120
pub name: FileName,
11211121
/// `true` if the `name` field above has been modified by `--remap-path-prefix`.
11221122
pub name_was_remapped: bool,
1123-
/// The unmapped path of the file that the source came from.
1124-
/// Set to `None` if the `SourceFile` was imported from an external crate.
1125-
/// as it is not encoded.
1126-
pub unmapped_path: Option<FileName>,
11271123
/// The complete source code.
11281124
pub src: Option<Lrc<String>>,
11291125
/// The source code's hash.
@@ -1274,7 +1270,6 @@ impl<D: Decoder> Decodable<D> for SourceFile {
12741270
Ok(SourceFile {
12751271
name,
12761272
name_was_remapped,
1277-
unmapped_path: None,
12781273
start_pos,
12791274
end_pos,
12801275
src: None,
@@ -1303,7 +1298,6 @@ impl SourceFile {
13031298
pub fn new(
13041299
name: FileName,
13051300
name_was_remapped: bool,
1306-
unmapped_path: FileName,
13071301
mut src: String,
13081302
start_pos: BytePos,
13091303
hash_kind: SourceFileHashAlgorithm,
@@ -1326,7 +1320,6 @@ impl SourceFile {
13261320
SourceFile {
13271321
name,
13281322
name_was_remapped,
1329-
unmapped_path: Some(unmapped_path),
13301323
src: Some(Lrc::new(src)),
13311324
src_hash,
13321325
external_src: Lock::new(ExternalSource::Unneeded),

compiler/rustc_span/src/source_map.rs

+9-35
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,17 @@ pub struct StableSourceFileId(u128);
127127
// StableSourceFileId, perhaps built atop source_file.name_hash.
128128
impl StableSourceFileId {
129129
pub fn new(source_file: &SourceFile) -> StableSourceFileId {
130-
StableSourceFileId::new_from_pieces(
131-
&source_file.name,
132-
source_file.name_was_remapped,
133-
source_file.unmapped_path.as_ref(),
134-
)
130+
StableSourceFileId::new_from_pieces(&source_file.name, source_file.name_was_remapped)
135131
}
136132

137-
fn new_from_pieces(
138-
name: &FileName,
139-
name_was_remapped: bool,
140-
unmapped_path: Option<&FileName>,
141-
) -> StableSourceFileId {
133+
fn new_from_pieces(name: &FileName, name_was_remapped: bool) -> StableSourceFileId {
142134
let mut hasher = StableHasher::new();
143135

144-
if let FileName::Real(real_name) = name {
145-
// rust-lang/rust#70924: Use the stable (virtualized) name when
146-
// available. (We do not want artifacts from transient file system
147-
// paths for libstd to leak into our build artifacts.)
148-
real_name.stable_name().hash(&mut hasher)
149-
} else {
150-
name.hash(&mut hasher);
151-
}
136+
// If name was virtualized, we need to take both the local path
137+
// and stablised path into account, in case two different paths were
138+
// mapped to the same
139+
name.hash(&mut hasher);
152140
name_was_remapped.hash(&mut hasher);
153-
unmapped_path.hash(&mut hasher);
154141

155142
StableSourceFileId(hasher.finish())
156143
}
@@ -286,25 +273,21 @@ impl SourceMap {
286273
filename: FileName,
287274
src: String,
288275
) -> Result<Lrc<SourceFile>, OffsetOverflowError> {
289-
// We need to preserve the unmapped path is as it is
290-
// used to determine the directory for loading submodules and include files.
291276
// Note that filename may not be a valid path, eg it may be `<anon>` etc,
292277
// but this is okay because the directory determined by `path.pop()` will
293278
// be empty, so the working directory will be used.
294-
let (mapped_filename, was_remapped) = self.path_mapping.map_filename_prefix(&filename);
279+
let (filename, was_remapped) = self.path_mapping.map_filename_prefix(&filename);
295280

296-
let file_id =
297-
StableSourceFileId::new_from_pieces(&mapped_filename, was_remapped, Some(&filename));
281+
let file_id = StableSourceFileId::new_from_pieces(&filename, was_remapped);
298282

299283
let lrc_sf = match self.source_file_by_stable_id(file_id) {
300284
Some(lrc_sf) => lrc_sf,
301285
None => {
302286
let start_pos = self.allocate_address_space(src.len())?;
303287

304288
let source_file = Lrc::new(SourceFile::new(
305-
mapped_filename,
306-
was_remapped,
307289
filename,
290+
was_remapped,
308291
src,
309292
Pos::from_usize(start_pos),
310293
self.hash_kind,
@@ -368,7 +351,6 @@ impl SourceMap {
368351
let source_file = Lrc::new(SourceFile {
369352
name: filename,
370353
name_was_remapped: name_was_remapped || name_is_remapped,
371-
unmapped_path: None,
372354
src: None,
373355
src_hash,
374356
external_src: Lock::new(ExternalSource::Foreign {
@@ -459,14 +441,6 @@ impl SourceMap {
459441
self.lookup_char_pos(sp.lo()).file.name.clone()
460442
}
461443

462-
pub fn span_to_unmapped_path(&self, sp: Span) -> FileName {
463-
self.lookup_char_pos(sp.lo())
464-
.file
465-
.unmapped_path
466-
.clone()
467-
.expect("`SourceMap::span_to_unmapped_path` called for imported `SourceFile`?")
468-
}
469-
470444
pub fn is_multiline(&self, sp: Span) -> bool {
471445
let lo = self.lookup_char_pos(sp.lo());
472446
let hi = self.lookup_char_pos(sp.hi());

src/librustdoc/doctest.rs

-2
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,6 @@ impl Tester for Collector {
792792
let target = self.options.target.clone();
793793
let target_str = target.to_string();
794794

795-
// FIXME(#44940): if doctests ever support path remapping, then this filename
796-
// needs to be the result of `SourceMap::span_to_unmapped_path`.
797795
let path = match &filename {
798796
FileName::Real(path) => path.local_path().to_path_buf(),
799797
_ => PathBuf::from(r"doctest.rs"),

0 commit comments

Comments
 (0)