Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5f14568
std: get rid of `sys_common::process`
joboet Mar 27, 2025
0f81fca
Change rustc_driver dependency on stable_mir crate
celinval Apr 30, 2025
415a73e
docs: alias `limit` to `Iterator::take`, cite `[u8]::utf8_chunks` in …
ShE3py May 2, 2025
cbdd713
Implement Iterator::last for vec::IntoIter
thaliaarchi Apr 13, 2025
6621826
Implement RFC 3503: frontmatters
fee1-dead Apr 12, 2025
b796179
Created `tests/rustdoc/reexports` subfolder to limit number of files …
GuillaumeGomez May 5, 2025
099f730
Created `tests/rustdoc/source-code-pages` subfolder to limit number o…
GuillaumeGomez May 5, 2025
b374996
Created `tests/rustdoc/anchors` subfolder to limit number of files at…
GuillaumeGomez May 5, 2025
ff971d0
Created `tests/rustdoc/auto` subfolder to limit number of files at th…
GuillaumeGomez May 5, 2025
9db7de5
Created `tests/rustdoc/jump-to-def` subfolder to limit number of file…
GuillaumeGomez May 5, 2025
a00b399
Move intra-doc tests into the expected subfolder
GuillaumeGomez May 5, 2025
eee6c97
Created `tests/rustdoc/private` subfolder to limit number of files at…
GuillaumeGomez May 5, 2025
d1f4a0b
Created `tests/rustdoc/macro` subfolder to limit number of files at t…
GuillaumeGomez May 5, 2025
be71d8b
Created `tests/rustdoc/doc-cfg` subfolder to limit number of files at…
GuillaumeGomez May 5, 2025
b84f4cc
Created `tests/rustdoc/impl` subfolder to limit number of files at th…
GuillaumeGomez May 5, 2025
fa2b922
Created `tests/rustdoc/assoc` subfolder to limit number of files at t…
GuillaumeGomez May 5, 2025
4b6bc73
Created `tests/rustdoc/enum` subfolder to limit number of files at th…
GuillaumeGomez May 5, 2025
e245c3b
Move primitive rustdoc tests into the `primitive` sub folder
GuillaumeGomez May 5, 2025
e14e19a
Created `tests/rustdoc/extern` subfolder to limit number of files at …
GuillaumeGomez May 5, 2025
27e39c3
Created `tests/rustdoc/async` subfolder to limit number of files at t…
GuillaumeGomez May 5, 2025
fa6d0d1
Use more accurate ELF flags on MIPS
smrobtzz May 4, 2025
57941af
Apply suggestions from code review
smrobtzz May 5, 2025
6a7996e
Take into-account `-Zremap-path-scope` when embedding filenames
Urgau Apr 19, 2025
c0dfa44
Be a bit more relaxed about not yet constrained infer vars in closure…
compiler-errors May 5, 2025
9c11c02
[Arm64EC] Only decorate functions with `#`
dpaoliello Apr 25, 2025
292aea5
Update mdbook to 0.4.49
ehuss May 5, 2025
a3d5562
bootstrap: Add check/test/run steps for src/tools/coverage-dump
Zalathar Apr 22, 2025
89319f2
coverage-dump: Extract some common code to an `llvm_utils` submodule
Zalathar Apr 23, 2025
bc3f0e3
coverage-dump: Extract a common parser method for maybe-compressed bytes
Zalathar Apr 23, 2025
f1b8cd4
coverage-dump: Include filenames hash in covfun line data
Zalathar Apr 22, 2025
041b2b2
coverage-dump: Make filenames available to covfun record dumping
Zalathar Apr 24, 2025
c53a767
coverage-dump: Dump filenames instead of global file IDs (and bless)
Zalathar Apr 24, 2025
51b74c9
Rollup merge of #139550 - Urgau:rmeta-remap-path-scope, r=nnethercote
Zalathar May 6, 2025
608e98a
Rollup merge of #139773 - thaliaarchi:vec-into-iter-last, r=workingju…
Zalathar May 6, 2025
b90beb5
Rollup merge of #140035 - fee1-dead-contrib:push-oszwkkvmpkks, r=jiey…
Zalathar May 6, 2025
24262b7
Rollup merge of #140176 - dpaoliello:arm64ecdec, r=wesleywiser
Zalathar May 6, 2025
c667fd9
Rollup merge of #140251 - Zalathar:coverage-dump-path, r=clubby789
Zalathar May 6, 2025
fa02cb0
Rollup merge of #140393 - joboet:sys_common_process, r=thomcc
Zalathar May 6, 2025
e650155
Rollup merge of #140532 - celinval:chores-smir-ra, r=oli-obk
Zalathar May 6, 2025
7300b97
Rollup merge of #140598 - ShE3py:iter-misc-docs, r=workingjubilee
Zalathar May 6, 2025
a7c6b50
Rollup merge of #140634 - smrobtzz:mips-elf-fixes, r=workingjubilee
Zalathar May 6, 2025
c1272ba
Rollup merge of #140673 - GuillaumeGomez:clean-rustdoc-tests, r=notri…
Zalathar May 6, 2025
8eec52e
Rollup merge of #140678 - compiler-errors:dont-ice-on-infer-in-upvar,…
Zalathar May 6, 2025
1e27a12
Rollup merge of #140687 - ehuss:update-mdbook, r=jieyouxu
Zalathar May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Take into-account -Zremap-path-scope when embedding filenames
  • Loading branch information
Urgau committed May 5, 2025
commit 6a7996e30325e28215b318feb7cc56bcff0e2bb5
2 changes: 0 additions & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

match source_file.name {
FileName::Real(ref original_file_name) => {
// FIXME: This should probably to conditionally remapped under
// a RemapPathScopeComponents but which one?
let adapted_file_name = source_map
.path_mapping()
.to_embeddable_absolute_path(original_file_name.clone(), working_directory);
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::edition::{DEFAULT_EDITION, EDITION_NAME_LIST, Edition, LATEST_STABLE_EDITION};
use rustc_span::source_map::FilePathMapping;
use rustc_span::{
FileName, FileNameDisplayPreference, RealFileName, SourceFileHashAlgorithm, Symbol, sym,
FileName, FileNameDisplayPreference, FileNameEmbeddablePreference, RealFileName,
SourceFileHashAlgorithm, Symbol, sym,
};
use rustc_target::spec::{
FramePointer, LinkSelfContainedComponents, LinkerFeatures, SplitDebuginfo, Target, TargetTuple,
Expand Down Expand Up @@ -1316,6 +1317,11 @@ fn file_path_mapping(
} else {
FileNameDisplayPreference::Local
},
if unstable_opts.remap_path_scope.is_all() {
FileNameEmbeddablePreference::RemappedOnly
} else {
FileNameEmbeddablePreference::LocalAndRemapped
},
)
}

Expand Down
34 changes: 11 additions & 23 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn with_metavar_spans<R>(f: impl FnOnce(&MetavarSpansMap) -> R) -> R {

// FIXME: We should use this enum or something like it to get rid of the
// use of magic `/rust/1.x/...` paths across the board.
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Decodable)]
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Decodable, Encodable)]
pub enum RealFileName {
LocalPath(PathBuf),
/// For remapped paths (namely paths into libstd that have been mapped
Expand All @@ -250,28 +250,6 @@ impl Hash for RealFileName {
}
}

// This is functionally identical to #[derive(Encodable)], with the exception of
// an added assert statement
impl<S: Encoder> Encodable<S> for RealFileName {
fn encode(&self, encoder: &mut S) {
match *self {
RealFileName::LocalPath(ref local_path) => {
encoder.emit_u8(0);
local_path.encode(encoder);
}

RealFileName::Remapped { ref local_path, ref virtual_name } => {
encoder.emit_u8(1);
// For privacy and build reproducibility, we must not embed host-dependant path
// in artifacts if they have been remapped by --remap-path-prefix
assert!(local_path.is_none());
local_path.encode(encoder);
virtual_name.encode(encoder);
}
}
}
}

impl RealFileName {
/// Returns the path suitable for reading from the file system on the local host,
/// if this information exists.
Expand Down Expand Up @@ -368,6 +346,16 @@ impl From<PathBuf> for FileName {
}
}

#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
pub enum FileNameEmbeddablePreference {
/// If a remapped path is available, only embed the `virtual_path` and omit the `local_path`.
///
/// Otherwise embed the local-path into the `virtual_path`.
RemappedOnly,
/// Embed the original path as well as its remapped `virtual_path` component if available.
LocalAndRemapped,
}

#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
pub enum FileNameDisplayPreference {
/// Display the path after the application of rewrite rules provided via `--remap-path-prefix`.
Expand Down
80 changes: 44 additions & 36 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,18 +1108,28 @@ pub fn get_source_map() -> Option<Arc<SourceMap>> {
pub struct FilePathMapping {
mapping: Vec<(PathBuf, PathBuf)>,
filename_display_for_diagnostics: FileNameDisplayPreference,
filename_embeddable_preference: FileNameEmbeddablePreference,
}

impl FilePathMapping {
pub fn empty() -> FilePathMapping {
FilePathMapping::new(Vec::new(), FileNameDisplayPreference::Local)
FilePathMapping::new(
Vec::new(),
FileNameDisplayPreference::Local,
FileNameEmbeddablePreference::RemappedOnly,
)
}

pub fn new(
mapping: Vec<(PathBuf, PathBuf)>,
filename_display_for_diagnostics: FileNameDisplayPreference,
filename_embeddable_preference: FileNameEmbeddablePreference,
) -> FilePathMapping {
FilePathMapping { mapping, filename_display_for_diagnostics }
FilePathMapping {
mapping,
filename_display_for_diagnostics,
filename_embeddable_preference,
}
}

/// Applies any path prefix substitution as defined by the mapping.
Expand Down Expand Up @@ -1217,11 +1227,13 @@ impl FilePathMapping {
) -> RealFileName {
match file_path {
// Anything that's already remapped we don't modify, except for erasing
// the `local_path` portion.
RealFileName::Remapped { local_path: _, virtual_name } => {
// the `local_path` portion (if desired).
RealFileName::Remapped { local_path, virtual_name } => {
RealFileName::Remapped {
// We do not want any local path to be exported into metadata
local_path: None,
local_path: match self.filename_embeddable_preference {
FileNameEmbeddablePreference::RemappedOnly => None,
FileNameEmbeddablePreference::LocalAndRemapped => local_path,
},
// We use the remapped name verbatim, even if it looks like a relative
// path. The assumption is that the user doesn't want us to further
// process paths that have gone through remapping.
Expand All @@ -1231,12 +1243,18 @@ impl FilePathMapping {

RealFileName::LocalPath(unmapped_file_path) => {
// If no remapping has been applied yet, try to do so
let (new_path, was_remapped) = self.map_prefix(unmapped_file_path);
let (new_path, was_remapped) = self.map_prefix(&unmapped_file_path);
if was_remapped {
// It was remapped, so don't modify further
return RealFileName::Remapped {
local_path: None,
virtual_name: new_path.into_owned(),
// But still provide the local path if desired
local_path: match self.filename_embeddable_preference {
FileNameEmbeddablePreference::RemappedOnly => None,
FileNameEmbeddablePreference::LocalAndRemapped => {
Some(unmapped_file_path)
}
},
};
}

Expand All @@ -1252,17 +1270,23 @@ impl FilePathMapping {

match working_directory {
RealFileName::LocalPath(unmapped_working_dir_abs) => {
let file_path_abs = unmapped_working_dir_abs.join(unmapped_file_path_rel);
let unmapped_file_path_abs =
unmapped_working_dir_abs.join(unmapped_file_path_rel);

// Although neither `working_directory` nor the file name were subject
// to path remapping, the concatenation between the two may be. Hence
// we need to do a remapping here.
let (file_path_abs, was_remapped) = self.map_prefix(file_path_abs);
let (file_path_abs, was_remapped) =
self.map_prefix(&unmapped_file_path_abs);
if was_remapped {
RealFileName::Remapped {
// Erase the actual path
local_path: None,
virtual_name: file_path_abs.into_owned(),
local_path: match self.filename_embeddable_preference {
FileNameEmbeddablePreference::RemappedOnly => None,
FileNameEmbeddablePreference::LocalAndRemapped => {
Some(unmapped_file_path_abs)
}
},
}
} else {
// No kind of remapping applied to this path, so
Expand All @@ -1271,43 +1295,27 @@ impl FilePathMapping {
}
}
RealFileName::Remapped {
local_path: _,
local_path,
virtual_name: remapped_working_dir_abs,
} => {
// If working_directory has been remapped, then we emit
// Remapped variant as the expanded path won't be valid
RealFileName::Remapped {
local_path: None,
virtual_name: Path::new(remapped_working_dir_abs)
.join(unmapped_file_path_rel),
.join(&unmapped_file_path_rel),
local_path: match self.filename_embeddable_preference {
FileNameEmbeddablePreference::RemappedOnly => None,
FileNameEmbeddablePreference::LocalAndRemapped => local_path
.as_ref()
.map(|local_path| local_path.join(unmapped_file_path_rel)),
},
}
}
}
}
}
}

/// Expand a relative path to an absolute path **without** remapping taken into account.
///
/// The resulting `RealFileName` will have its `virtual_path` portion erased if
/// possible (i.e. if there's also a remapped path).
pub fn to_local_embeddable_absolute_path(
&self,
file_path: RealFileName,
working_directory: &RealFileName,
) -> RealFileName {
let file_path = file_path.local_path_if_available();
if file_path.is_absolute() {
// No remapping has applied to this path and it is absolute,
// so the working directory cannot influence it either, so
// we are done.
return RealFileName::LocalPath(file_path.to_path_buf());
}
debug_assert!(file_path.is_relative());
let working_directory = working_directory.local_path_if_available();
RealFileName::LocalPath(Path::new(working_directory).join(file_path))
}

/// Attempts to (heuristically) reverse a prefix mapping.
///
/// Returns [`Some`] if there is exactly one mapping where the "to" part is
Expand Down
73 changes: 73 additions & 0 deletions compiler/rustc_span/src/source_map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ fn path_prefix_remapping() {
let mapping = &FilePathMapping::new(
vec![(path("abc/def"), path("foo"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);

assert_eq!(map_path_prefix(mapping, "abc/def/src/main.rs"), path_str("foo/src/main.rs"));
Expand All @@ -316,6 +317,7 @@ fn path_prefix_remapping() {
let mapping = &FilePathMapping::new(
vec![(path("abc/def"), path("/foo"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);

assert_eq!(map_path_prefix(mapping, "abc/def/src/main.rs"), path_str("/foo/src/main.rs"));
Expand All @@ -327,6 +329,7 @@ fn path_prefix_remapping() {
let mapping = &FilePathMapping::new(
vec![(path("/abc/def"), path("foo"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);

assert_eq!(map_path_prefix(mapping, "/abc/def/src/main.rs"), path_str("foo/src/main.rs"));
Expand All @@ -338,6 +341,7 @@ fn path_prefix_remapping() {
let mapping = &FilePathMapping::new(
vec![(path("/abc/def"), path("/foo"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);

assert_eq!(map_path_prefix(mapping, "/abc/def/src/main.rs"), path_str("/foo/src/main.rs"));
Expand All @@ -351,6 +355,7 @@ fn path_prefix_remapping_expand_to_absolute() {
let mapping = &FilePathMapping::new(
vec![(path("/foo"), path("FOO")), (path("/bar"), path("BAR"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);
let working_directory = path("/foo");
let working_directory = RealFileName::Remapped {
Expand Down Expand Up @@ -448,13 +453,79 @@ fn path_prefix_remapping_expand_to_absolute() {
);
}

#[test]
fn path_prefix_remapping_expand_to_absolute_and_local() {
// "virtual" working directory is relative path
let mapping = &FilePathMapping::new(
vec![(path("/foo"), path("FOO")), (path("/bar"), path("BAR"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::LocalAndRemapped,
);
let working_directory = path("/foo");
let working_directory = RealFileName::Remapped {
local_path: Some(working_directory.clone()),
virtual_name: mapping.map_prefix(working_directory).0.into_owned(),
};

assert_eq!(working_directory.remapped_path_if_available(), path("FOO"));

// Unmapped absolute path
assert_eq!(
mapping.to_embeddable_absolute_path(
RealFileName::LocalPath(path("/foo/src/main.rs")),
&working_directory
),
RealFileName::Remapped {
local_path: Some(path("/foo/src/main.rs")),
virtual_name: path("FOO/src/main.rs")
}
);

// Unmapped absolute path with unrelated working directory
assert_eq!(
mapping.to_embeddable_absolute_path(
RealFileName::LocalPath(path("/bar/src/main.rs")),
&working_directory
),
RealFileName::Remapped {
local_path: Some(path("/bar/src/main.rs")),
virtual_name: path("BAR/src/main.rs")
}
);

// Already remapped absolute path, with unrelated working directory
assert_eq!(
mapping.to_embeddable_absolute_path(
RealFileName::Remapped {
local_path: Some(path("/bar/src/main.rs")),
virtual_name: path("BAR/src/main.rs"),
},
&working_directory
),
RealFileName::Remapped {
local_path: Some(path("/bar/src/main.rs")),
virtual_name: path("BAR/src/main.rs")
}
);

// Already remapped relative path
assert_eq!(
mapping.to_embeddable_absolute_path(
RealFileName::Remapped { local_path: None, virtual_name: path("XYZ/src/main.rs") },
&working_directory
),
RealFileName::Remapped { local_path: None, virtual_name: path("XYZ/src/main.rs") }
);
}

#[test]
fn path_prefix_remapping_reverse() {
// Ignores options without alphanumeric chars.
{
let mapping = &FilePathMapping::new(
vec![(path("abc"), path("/")), (path("def"), path("."))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);

assert_eq!(reverse_map_prefix(mapping, "/hello.rs"), None);
Expand All @@ -466,6 +537,7 @@ fn path_prefix_remapping_reverse() {
let mapping = &FilePathMapping::new(
vec![(path("abc"), path("/redacted")), (path("def"), path("/redacted"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);

assert_eq!(reverse_map_prefix(mapping, "/redacted/hello.rs"), None);
Expand All @@ -476,6 +548,7 @@ fn path_prefix_remapping_reverse() {
let mapping = &FilePathMapping::new(
vec![(path("abc"), path("/redacted")), (path("def/ghi"), path("/fake/dir"))],
FileNameDisplayPreference::Remapped,
FileNameEmbeddablePreference::RemappedOnly,
);

assert_eq!(
Expand Down
Loading
Loading