Skip to content

Commit 6720a37

Browse files
committed
Rename RealFileName::Named to LocalPath and Devirtualized to Remapped
1 parent d66506d commit 6720a37

File tree

13 files changed

+82
-132
lines changed

13 files changed

+82
-132
lines changed

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ impl<'a> ExtCtxt<'a> {
10721072
// after macro expansion (that is, they are unhygienic).
10731073
if !path.is_absolute() {
10741074
let callsite = span.source_callsite();
1075-
let mut result = match self.source_map().span_to_unmapped_path(callsite) {
1075+
let mut result = match self.source_map().span_to_filename(callsite) {
10761076
FileName::Real(name) => name.into_local_path(),
10771077
FileName::DocTest(path, _) => path,
10781078
other => {

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
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_expand/src/proc_macro_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ fn ident_name_compatibility_hack(
725725
if let ExpnKind::Macro(_, macro_name) = orig_span.ctxt().outer_expn_data().kind {
726726
let source_map = rustc.sess.source_map();
727727
let filename = source_map.span_to_filename(orig_span);
728-
if let FileName::Real(RealFileName::Named(path)) = filename {
728+
if let FileName::Real(RealFileName::LocalPath(path)) = filename {
729729
let matches_prefix = |prefix, filename| {
730730
// Check for a path that ends with 'prefix*/src/<filename>'
731731
let mut iter = path.components().rev();
@@ -788,7 +788,7 @@ fn ident_name_compatibility_hack(
788788
if macro_name == sym::tuple_from_req && matches_prefix("actix-web", "extract.rs") {
789789
let snippet = source_map.span_to_snippet(orig_span);
790790
if snippet.as_deref() == Ok("$T") {
791-
if let FileName::Real(RealFileName::Named(macro_path)) =
791+
if let FileName::Real(RealFileName::LocalPath(macro_path)) =
792792
source_map.span_to_filename(rustc.def_site)
793793
{
794794
if macro_path.to_string_lossy().contains("pin-project-internal-0.") {

compiler/rustc_interface/src/passes.rs

Lines changed: 4 additions & 4 deletions
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 {
@@ -587,15 +587,15 @@ fn write_out_deps(
587587
for cnum in resolver.cstore().crates_untracked() {
588588
let source = resolver.cstore().crate_source_untracked(cnum);
589589
if let Some((path, _)) = source.dylib {
590-
let file_name = FileName::Real(RealFileName::Named(path));
590+
let file_name = FileName::Real(RealFileName::LocalPath(path));
591591
files.push(escape_dep_filename(&file_name));
592592
}
593593
if let Some((path, _)) = source.rlib {
594-
let file_name = FileName::Real(RealFileName::Named(path));
594+
let file_name = FileName::Real(RealFileName::LocalPath(path));
595595
files.push(escape_dep_filename(&file_name));
596596
}
597597
if let Some((path, _)) = source.rmeta {
598-
let file_name = FileName::Real(RealFileName::Named(path));
598+
let file_name = FileName::Real(RealFileName::LocalPath(path));
599599
files.push(escape_dep_filename(&file_name));
600600
}
601601
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,9 +1635,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16351635
if let Some(virtual_dir) = virtual_rust_source_base_dir {
16361636
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
16371637
if let rustc_span::FileName::Real(old_name) = name {
1638-
if let rustc_span::RealFileName::Named(one_path) = old_name {
1639-
if let Ok(rest) = one_path.strip_prefix(virtual_dir) {
1640-
let virtual_name = one_path.clone();
1638+
if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =
1639+
old_name
1640+
{
1641+
if let Ok(rest) = virtual_name.strip_prefix(virtual_dir) {
1642+
let virtual_name = virtual_name.clone();
16411643

16421644
// The std library crates are in
16431645
// `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
@@ -1673,7 +1675,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16731675
virtual_name.display(),
16741676
new_path.display(),
16751677
);
1676-
let new_name = rustc_span::RealFileName::Devirtualized {
1678+
let new_name = rustc_span::RealFileName::Remapped {
16771679
local_path: new_path,
16781680
virtual_name,
16791681
};
@@ -1694,7 +1696,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16941696
// containing the information we need.
16951697
let rustc_span::SourceFile {
16961698
mut name,
1697-
name_was_remapped,
16981699
src_hash,
16991700
start_pos,
17001701
end_pos,
@@ -1709,8 +1710,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17091710
// If this file's path has been remapped to `/rustc/$hash`,
17101711
// we might be able to reverse that (also see comments above,
17111712
// on `try_to_translate_virtual_to_real`).
1712-
// FIXME(eddyb) we could check `name_was_remapped` here,
1713-
// but in practice it seems to be always `false`.
17141713
try_to_translate_virtual_to_real(&mut name);
17151714

17161715
let source_length = (end_pos - start_pos).to_usize();
@@ -1735,7 +1734,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17351734

17361735
let local_version = sess.source_map().new_imported_source_file(
17371736
name,
1738-
name_was_remapped,
17391737
src_hash,
17401738
name_hash,
17411739
source_length,

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 18 additions & 11 deletions
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::LocalPath(local_path) => {
498+
Path::new(&working_dir).join(local_path).into()
499+
}
500+
RealFileName::Remapped { local_path, virtual_name } => {
501+
FileName::Real(RealFileName::Remapped {
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);

compiler/rustc_middle/src/ich/impls_syntax.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +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,
65-
unmapped_path: _,
6664
cnum,
6765
// Do not hash the source as it is not encoded
6866
src: _,
@@ -77,7 +75,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
7775
} = *self;
7876

7977
(name_hash as u64).hash_stable(hcx, hasher);
80-
name_was_remapped.hash_stable(hcx, hasher);
8178

8279
src_hash.hash_stable(hcx, hasher);
8380

compiler/rustc_save_analysis/src/span_utils.rs

Lines changed: 5 additions & 3 deletions
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::LocalPath(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::Remapped { local_path: _, virtual_name }) => {
35+
virtual_name.display().to_string()
36+
}
3537
filename => filename.to_string(),
3638
}
3739
}

compiler/rustc_span/src/lib.rs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,16 @@ pub fn with_default_session_globals<R>(f: impl FnOnce() -> R) -> R {
113113
// deserialization.
114114
scoped_tls::scoped_thread_local!(pub static SESSION_GLOBALS: SessionGlobals);
115115

116-
// FIXME: Perhaps this should not implement Rustc{Decodable, Encodable}
117-
//
118116
// FIXME: We should use this enum or something like it to get rid of the
119117
// use of magic `/rust/1.x/...` paths across the board.
120118
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
121119
#[derive(HashStable_Generic, Decodable, Encodable)]
122120
pub enum RealFileName {
123-
Named(PathBuf),
124-
/// For de-virtualized paths (namely paths into libstd that have been mapped
125-
/// to the appropriate spot on the local host's file system),
126-
Devirtualized {
121+
LocalPath(PathBuf),
122+
/// For remapped paths (namely paths into libstd that have been mapped
123+
/// to the appropriate spot on the local host's file system, and local file
124+
/// system paths that have been remapped with `FilePathMapping`),
125+
Remapped {
127126
/// `local_path` is the (host-dependent) local path to the file.
128127
local_path: PathBuf,
129128
/// `virtual_name` is the stable path rustc will store internally within
@@ -137,28 +136,28 @@ impl RealFileName {
137136
/// Avoid embedding this in build artifacts; see `stable_name()` for that.
138137
pub fn local_path(&self) -> &Path {
139138
match self {
140-
RealFileName::Named(p)
141-
| RealFileName::Devirtualized { local_path: p, virtual_name: _ } => &p,
139+
RealFileName::LocalPath(p)
140+
| RealFileName::Remapped { local_path: p, virtual_name: _ } => &p,
142141
}
143142
}
144143

145144
/// Returns the path suitable for reading from the file system on the local host.
146145
/// Avoid embedding this in build artifacts; see `stable_name()` for that.
147146
pub fn into_local_path(self) -> PathBuf {
148147
match self {
149-
RealFileName::Named(p)
150-
| RealFileName::Devirtualized { local_path: p, virtual_name: _ } => p,
148+
RealFileName::LocalPath(p)
149+
| RealFileName::Remapped { local_path: p, virtual_name: _ } => p,
151150
}
152151
}
153152

154153
/// Returns the path suitable for embedding into build artifacts. Note that
155-
/// a virtualized path will not correspond to a valid file system path; see
154+
/// a remapped path will not correspond to a valid file system path; see
156155
/// `local_path()` for something that is more likely to return paths into the
157156
/// local host file system.
158157
pub fn stable_name(&self) -> &Path {
159158
match self {
160-
RealFileName::Named(p)
161-
| RealFileName::Devirtualized { local_path: _, virtual_name: p } => &p,
159+
RealFileName::LocalPath(p)
160+
| RealFileName::Remapped { local_path: _, virtual_name: p } => &p,
162161
}
163162
}
164163
}
@@ -214,7 +213,7 @@ impl std::fmt::Display for FileName {
214213
impl From<PathBuf> for FileName {
215214
fn from(p: PathBuf) -> Self {
216215
assert!(!p.to_string_lossy().ends_with('>'));
217-
FileName::Real(RealFileName::Named(p))
216+
FileName::Real(RealFileName::LocalPath(p))
218217
}
219218
}
220219

@@ -1124,11 +1123,6 @@ pub struct SourceFile {
11241123
/// originate from files has names between angle brackets by convention
11251124
/// (e.g., `<anon>`).
11261125
pub name: FileName,
1127-
/// `true` if the `name` field above has been modified by `--remap-path-prefix`.
1128-
pub name_was_remapped: bool,
1129-
/// The unmapped path of the file that the source came from.
1130-
/// Set to `None` if the `SourceFile` was imported from an external crate.
1131-
pub unmapped_path: Option<FileName>,
11321126
/// The complete source code.
11331127
pub src: Option<Lrc<String>>,
11341128
/// The source code's hash.
@@ -1158,7 +1152,6 @@ impl<S: Encoder> Encodable<S> for SourceFile {
11581152
fn encode(&self, s: &mut S) -> Result<(), S::Error> {
11591153
s.emit_struct("SourceFile", 8, |s| {
11601154
s.emit_struct_field("name", 0, |s| self.name.encode(s))?;
1161-
s.emit_struct_field("name_was_remapped", 1, |s| self.name_was_remapped.encode(s))?;
11621155
s.emit_struct_field("src_hash", 2, |s| self.src_hash.encode(s))?;
11631156
s.emit_struct_field("start_pos", 3, |s| self.start_pos.encode(s))?;
11641157
s.emit_struct_field("end_pos", 4, |s| self.end_pos.encode(s))?;
@@ -1233,8 +1226,6 @@ impl<D: Decoder> Decodable<D> for SourceFile {
12331226
fn decode(d: &mut D) -> Result<SourceFile, D::Error> {
12341227
d.read_struct("SourceFile", 8, |d| {
12351228
let name: FileName = d.read_struct_field("name", 0, |d| Decodable::decode(d))?;
1236-
let name_was_remapped: bool =
1237-
d.read_struct_field("name_was_remapped", 1, |d| Decodable::decode(d))?;
12381229
let src_hash: SourceFileHash =
12391230
d.read_struct_field("src_hash", 2, |d| Decodable::decode(d))?;
12401231
let start_pos: BytePos =
@@ -1278,8 +1269,6 @@ impl<D: Decoder> Decodable<D> for SourceFile {
12781269
let cnum: CrateNum = d.read_struct_field("cnum", 10, |d| Decodable::decode(d))?;
12791270
Ok(SourceFile {
12801271
name,
1281-
name_was_remapped,
1282-
unmapped_path: None,
12831272
start_pos,
12841273
end_pos,
12851274
src: None,
@@ -1307,8 +1296,6 @@ impl fmt::Debug for SourceFile {
13071296
impl SourceFile {
13081297
pub fn new(
13091298
name: FileName,
1310-
name_was_remapped: bool,
1311-
unmapped_path: FileName,
13121299
mut src: String,
13131300
start_pos: BytePos,
13141301
hash_kind: SourceFileHashAlgorithm,
@@ -1330,8 +1317,6 @@ impl SourceFile {
13301317

13311318
SourceFile {
13321319
name,
1333-
name_was_remapped,
1334-
unmapped_path: Some(unmapped_path),
13351320
src: Some(Lrc::new(src)),
13361321
src_hash,
13371322
external_src: Lock::new(ExternalSource::Unneeded),

0 commit comments

Comments
 (0)