Skip to content

Commit 00700e5

Browse files
committed
Remove name_was_remapped field from SourceFile as this can now be inferred by RealFileName variants
1 parent ca30ad1 commit 00700e5

File tree

7 files changed

+28
-39
lines changed

7 files changed

+28
-39
lines changed

Diff for: compiler/rustc_metadata/src/rmeta/decoder.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16921692
// containing the information we need.
16931693
let rustc_span::SourceFile {
16941694
mut name,
1695-
name_was_remapped,
16961695
src_hash,
16971696
start_pos,
16981697
end_pos,
@@ -1707,8 +1706,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17071706
// If this file's path has been remapped to `/rustc/$hash`,
17081707
// we might be able to reverse that (also see comments above,
17091708
// on `try_to_translate_virtual_to_real`).
1710-
// FIXME(eddyb) we could check `name_was_remapped` here,
1711-
// but in practice it seems to be always `false`.
17121709
try_to_translate_virtual_to_real(&mut name);
17131710

17141711
let source_length = (end_pos - start_pos).to_usize();
@@ -1733,7 +1730,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17331730

17341731
let local_version = sess.source_map().new_imported_source_file(
17351732
name,
1736-
name_was_remapped,
17371733
src_hash,
17381734
name_hash,
17391735
source_length,

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ use rustc_middle::ty::codec::TyEncoder;
2828
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
2929
use rustc_serialize::{opaque, Encodable, Encoder};
3030
use rustc_session::config::CrateType;
31-
use rustc_span::hygiene::{ExpnDataEncodeMode, HygieneEncodeContext, MacroKind};
3231
use rustc_span::symbol::{sym, Ident, Symbol};
3332
use rustc_span::{self, ExternalSource, FileName, SourceFile, Span, SyntaxContext};
33+
use rustc_span::{
34+
hygiene::{ExpnDataEncodeMode, HygieneEncodeContext, MacroKind},
35+
RealFileName,
36+
};
3437
use rustc_target::abi::VariantIdx;
3538
use std::hash::Hash;
3639
use std::num::NonZeroUsize;
@@ -485,18 +488,22 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
485488
})
486489
.map(|(_, source_file)| {
487490
let mut adapted = match source_file.name {
488-
// This path of this SourceFile has been modified by
489-
// path-remapping, so we use it verbatim (and avoid
490-
// cloning the whole map in the process).
491-
_ if source_file.name_was_remapped => source_file.clone(),
492-
493-
// Otherwise expand all paths to absolute paths because
494-
// any relative paths are potentially relative to a
495-
// wrong directory.
496491
FileName::Real(ref name) => {
497-
let name = name.stable_name();
492+
// Expand all local paths to absolute paths because
493+
// any relative paths are potentially relative to a
494+
// wrong directory.
498495
let mut adapted = (**source_file).clone();
499-
adapted.name = Path::new(&working_dir).join(name).into();
496+
adapted.name = match name {
497+
RealFileName::Named(local_path) => {
498+
Path::new(&working_dir).join(local_path).into()
499+
}
500+
RealFileName::Virtualized { local_path, virtual_name } => {
501+
FileName::Real(RealFileName::Virtualized {
502+
local_path: Path::new(&working_dir).join(local_path),
503+
virtual_name: virtual_name.clone(),
504+
})
505+
}
506+
};
500507
adapted.name_hash = {
501508
let mut hasher: StableHasher = StableHasher::new();
502509
adapted.name.hash(&mut hasher);

Diff for: compiler/rustc_middle/src/ich/impls_syntax.rs

-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
6161
let SourceFile {
6262
name: _, // We hash the smaller name_hash instead of this
6363
name_hash,
64-
name_was_remapped,
6564
cnum,
6665
// Do not hash the source as it is not encoded
6766
src: _,
@@ -76,7 +75,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
7675
} = *self;
7776

7877
(name_hash as u64).hash_stable(hcx, hasher);
79-
name_was_remapped.hash_stable(hcx, hasher);
8078

8179
src_hash.hash_stable(hcx, hasher);
8280

Diff for: compiler/rustc_save_analysis/src/span_utils.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ impl<'a> SpanUtils<'a> {
1616

1717
pub fn make_filename_string(&self, file: &SourceFile) -> String {
1818
match &file.name {
19-
FileName::Real(name) if !file.name_was_remapped => {
20-
let path = name.local_path();
19+
FileName::Real(RealFileName::Named(path)) => {
2120
if path.is_absolute() {
2221
self.sess
2322
.source_map()
@@ -30,8 +29,11 @@ impl<'a> SpanUtils<'a> {
3029
self.sess.working_dir.0.join(&path).display().to_string()
3130
}
3231
}
33-
// If the file name is already remapped, we assume the user
32+
// If the file name was remapped, we assume the user
3433
// configured it the way they wanted to, so use that directly
34+
FileName::Real(RealFileName::Virtualized { local_path: _, virtual_name }) => {
35+
virtual_name.display().to_string()
36+
}
3537
filename => filename.to_string(),
3638
}
3739
}

Diff for: compiler/rustc_span/src/lib.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,6 @@ pub struct SourceFile {
11181118
/// originate from files has names between angle brackets by convention
11191119
/// (e.g., `<anon>`).
11201120
pub name: FileName,
1121-
/// `true` if the `name` field above has been modified by `--remap-path-prefix`.
1122-
pub name_was_remapped: bool,
11231121
/// The complete source code.
11241122
pub src: Option<Lrc<String>>,
11251123
/// The source code's hash.
@@ -1149,7 +1147,6 @@ impl<S: Encoder> Encodable<S> for SourceFile {
11491147
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
11501148
s.emit_struct("SourceFile", 8, |s| {
11511149
s.emit_struct_field("name", 0, |s| self.name.encode(s))?;
1152-
s.emit_struct_field("name_was_remapped", 1, |s| self.name_was_remapped.encode(s))?;
11531150
s.emit_struct_field("src_hash", 2, |s| self.src_hash.encode(s))?;
11541151
s.emit_struct_field("start_pos", 3, |s| self.start_pos.encode(s))?;
11551152
s.emit_struct_field("end_pos", 4, |s| self.end_pos.encode(s))?;
@@ -1224,8 +1221,6 @@ impl<D: Decoder> Decodable<D> for SourceFile {
12241221
fn decode(d: &mut D) -> Result<SourceFile, D::Error> {
12251222
d.read_struct("SourceFile", 8, |d| {
12261223
let name: FileName = d.read_struct_field("name", 0, |d| Decodable::decode(d))?;
1227-
let name_was_remapped: bool =
1228-
d.read_struct_field("name_was_remapped", 1, |d| Decodable::decode(d))?;
12291224
let src_hash: SourceFileHash =
12301225
d.read_struct_field("src_hash", 2, |d| Decodable::decode(d))?;
12311226
let start_pos: BytePos =
@@ -1269,7 +1264,6 @@ impl<D: Decoder> Decodable<D> for SourceFile {
12691264
let cnum: CrateNum = d.read_struct_field("cnum", 10, |d| Decodable::decode(d))?;
12701265
Ok(SourceFile {
12711266
name,
1272-
name_was_remapped,
12731267
start_pos,
12741268
end_pos,
12751269
src: None,
@@ -1297,7 +1291,6 @@ impl fmt::Debug for SourceFile {
12971291
impl SourceFile {
12981292
pub fn new(
12991293
name: FileName,
1300-
name_was_remapped: bool,
13011294
mut src: String,
13021295
start_pos: BytePos,
13031296
hash_kind: SourceFileHashAlgorithm,
@@ -1319,7 +1312,6 @@ impl SourceFile {
13191312

13201313
SourceFile {
13211314
name,
1322-
name_was_remapped,
13231315
src: Some(Lrc::new(src)),
13241316
src_hash,
13251317
external_src: Lock::new(ExternalSource::Unneeded),

Diff for: compiler/rustc_span/src/source_map.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,16 @@ 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(&source_file.name, source_file.name_was_remapped)
130+
StableSourceFileId::new_from_name(&source_file.name)
131131
}
132132

133-
fn new_from_pieces(name: &FileName, name_was_remapped: bool) -> StableSourceFileId {
133+
fn new_from_name(name: &FileName) -> StableSourceFileId {
134134
let mut hasher = StableHasher::new();
135135

136136
// If name was virtualized, we need to take both the local path
137137
// and stablised path into account, in case two different paths were
138138
// mapped to the same
139139
name.hash(&mut hasher);
140-
name_was_remapped.hash(&mut hasher);
141140

142141
StableSourceFileId(hasher.finish())
143142
}
@@ -276,9 +275,9 @@ impl SourceMap {
276275
// Note that filename may not be a valid path, eg it may be `<anon>` etc,
277276
// but this is okay because the directory determined by `path.pop()` will
278277
// be empty, so the working directory will be used.
279-
let (filename, was_remapped) = self.path_mapping.map_filename_prefix(&filename);
278+
let (filename, _) = self.path_mapping.map_filename_prefix(&filename);
280279

281-
let file_id = StableSourceFileId::new_from_pieces(&filename, was_remapped);
280+
let file_id = StableSourceFileId::new_from_name(&filename);
282281

283282
let lrc_sf = match self.source_file_by_stable_id(file_id) {
284283
Some(lrc_sf) => lrc_sf,
@@ -287,7 +286,6 @@ impl SourceMap {
287286

288287
let source_file = Lrc::new(SourceFile::new(
289288
filename,
290-
was_remapped,
291289
src,
292290
Pos::from_usize(start_pos),
293291
self.hash_kind,
@@ -311,7 +309,6 @@ impl SourceMap {
311309
pub fn new_imported_source_file(
312310
&self,
313311
filename: FileName,
314-
name_was_remapped: bool,
315312
src_hash: SourceFileHash,
316313
name_hash: u128,
317314
source_len: usize,
@@ -346,11 +343,10 @@ impl SourceMap {
346343
nc.pos = nc.pos + start_pos;
347344
}
348345

349-
let (filename, name_is_remapped) = self.path_mapping.map_filename_prefix(&filename);
346+
let (filename, _) = self.path_mapping.map_filename_prefix(&filename);
350347

351348
let source_file = Lrc::new(SourceFile {
352349
name: filename,
353-
name_was_remapped: name_was_remapped || name_is_remapped,
354350
src: None,
355351
src_hash,
356352
external_src: Lock::new(ExternalSource::Foreign {

Diff for: compiler/rustc_span/src/source_map/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ fn t10() {
229229

230230
let SourceFile {
231231
name,
232-
name_was_remapped,
233232
src_hash,
234233
start_pos,
235234
end_pos,
@@ -243,7 +242,6 @@ fn t10() {
243242

244243
let imported_src_file = sm.new_imported_source_file(
245244
name,
246-
name_was_remapped,
247245
src_hash,
248246
name_hash,
249247
(end_pos - start_pos).to_usize(),

0 commit comments

Comments
 (0)