Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remap paths from other crates #117836

Closed
wants to merge 3 commits into from
Closed

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Nov 12, 2023

Previously, remap-path-prefix only applied to files loaded in the current session. File names
loaded in a previous invocation were used unchanged. This is unfortunate for UI testing when some of
the crates involved are in the standard library (we don't want to recompile the standard library for
arbitrary tests).

Change it to apply to existing files as well. I believe this will eventually allow removing the
special-casing for -Z simulate-remapped-rust-src-base. I'm willing to make that change here if desired.

Fixes #66251. This might allow me to unblock #117609 without first waiting for #113611 to land (need to test).

@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 12, 2023
@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member Author

jyn514 commented Nov 12, 2023

@Nemo157 suggested that remapping should be cumulative, instead of giving precedence to the first flag. In other words, if a file is at path /foo/lib.rs, compiled with remap-path-prefix=/foo=/bar, and then used as a library in an invocation with remap-path-prefix=/bar=/baz, the final path used should be /baz/lib.rs, not /bar/lib.rs which the PR does currently. I'm willing to make that change but I'd like to hear from petrochenkov what he prefers.

Previously, `remap-path-prefix` only applied to files loaded *in the current session*. File names
loaded in a previous invocation were used unchanged. This is unfortunate for UI testing when some of
the crates involved are in the standard library (we don't want to recompile the standard library for
arbitrary tests).

Change it to apply to existing files as well. I believe this will eventually allow removing the
special-casing for `-Z simulate-remapped-rust-src-base`.
It was never used, and it's ambiguous what the answer should be for paths that were remapped in a previous session.
@Urgau
Copy link
Member

Urgau commented Nov 12, 2023

How do this interact with -Zremap-path-scope? Could you also add a test with -Zremap-path-scope=diagnostics.

@jyn514
Copy link
Member Author

jyn514 commented Nov 12, 2023

@Urgau it should work fine, remap-path-scope works by taking an existing RealFileName::Remapped and choosing whether to use FileNameDisplayPreference::Remapped or FileNameDisplayPreference::Local, it has to handle it by its nature. I'll add a test.

@petrochenkov
Copy link
Contributor

Is there anybody familiar with this topic besides michaelwoerister, who is unavailable?
cc @cbeuw maybe

I only remember that path remapping has seen numerous changes and fixes in rustc and multiple RFCs, and it was never enough.

@petrochenkov
Copy link
Contributor

The changes look reasonable to me, but I'm not sure what are the full implications.

I'm going to ping @rust-lang/compiler, then wait for a week, then r+.
@rustbot team

@petrochenkov petrochenkov added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2023
@cbeuw
Copy link
Contributor

cbeuw commented Nov 24, 2023

@Nemo157 suggested that remapping should be cumulative

This has been brought up before:

Currently it does not look to me like we need remapping of imported paths (i.e. "double remapping") to fix #73167. The compiler has the stable name of upstream file names available. I would opt for trying to fix the existing bugs without introducing new functionality (which would probably need a major change proposal).
#83813 (comment)

I don't have an opinion either way, but if we were to introduce it, it should be a deliberate change through MCP. It shouldn't be introduced in this PR.

@michaelwoerister
Copy link
Member

I think this came up a few times before and I vaguely remember it being more complicated than one would think. I'll add myself as a reviewer and will try to remember what the complications were.

@michaelwoerister michaelwoerister self-assigned this Dec 7, 2023
@petrochenkov petrochenkov removed their assignment Dec 7, 2023
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Dec 7, 2023
@michaelwoerister
Copy link
Member

As far as I can tell, the main reason the remapping is only applied to the current crate is that remapped paths are emitted into compiled artifacts (e.g. panic messages in object files, debuginfo, etc) and subsequent compilation sessions cannot modify those anymore. The effect being that one gets an unpredictable mix of paths in the final output.

For example, if there's a crate A containing an #[inline] function foo() that is called inside A, but also in crates B and C, each of which has a different path remapping, then a panicking call to foo() would point to different file paths, depending on which of the crates foo() was called in.

From my point of view that is a blocker for recursive remapping. Making Cargo do the heavy lifting as described in the trim paths RFC seems like the better approach to me.

@michaelwoerister michaelwoerister added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 12, 2023
@Dylan-DPC
Copy link
Member

@jyn514 any updates on this? thanks

@jyn514
Copy link
Member Author

jyn514 commented Feb 17, 2024

nope

@jyn514 jyn514 closed this Feb 17, 2024
@jyn514 jyn514 deleted the remap-foreign-paths branch February 17, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--remap-path-prefix does not apply to secondary files in diagnostics
8 participants