Skip to content

Don't canonicalize crate paths #139834

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ChrisDenton
Copy link
Member

When printing paths in diagnostic we should favour printing the paths that were passed in rather than resolving all symlinks.

This PR changes the form of the crate path but it should only really affect diagnostics as filesystem functions won't care which path is used. The uncanonicalized path was already used as a fallback for when canonicalization failed.

This is a partial alternative to #139823.

@rustbot
Copy link
Collaborator

rustbot commented Apr 15, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Apr 15, 2025
@lcnr
Copy link
Contributor

lcnr commented Apr 15, 2025

r? compiler

@rustbot rustbot assigned fee1-dead and unassigned lcnr Apr 15, 2025
@fee1-dead
Copy link
Member

This PR changes the form of the crate path but it should only really affect diagnostics as filesystem functions won't care which path is used. The uncanonicalized path was already used as a fallback for when canonicalization failed.

Any test that can show us how the diagnostics get changed?

@ChrisDenton
Copy link
Member Author

ChrisDenton commented Apr 15, 2025

I can add a run-make test. I'm finding it hard to do in a UI test.

But before when running rustc main.rs -L ./ with multiple candidate crates in the current dir:

error[E0464]: multiple candidates for `rlib` dependency `resolver1` found
 --> main.rs:1:1
  |
1 | extern crate resolver1;
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: candidate #1: \\?\F:\Temp\rust\crateresolver\libresolver1-1.rlib
  = note: candidate #2: \\?\F:\Temp\rust\crateresolver\libresolver1-2.rlib

error: aborting due to 1 previous error

After:

error[E0464]: multiple candidates for `rlib` dependency `resolver1` found
 --> main.rs:1:1
  |
1 | extern crate resolver1;
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: candidate #1: ./libresolver1-1.rlib
  = note: candidate #2: ./libresolver1-2.rlib

error: aborting due to 1 previous error

I think the latter is nicer. Another alternative would be to make paths absolute without resolving symlinks but I think it worth preserving relative paths if that's what the user gave us. If nothing else it's a bit more reproducible between machines.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Apr 15, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 15, 2025

This PR modifies run-make tests.

cc @jieyouxu

@ChrisDenton ChrisDenton force-pushed the spf branch 2 times, most recently from cfb2ed1 to 2712731 Compare April 15, 2025 14:23
@fee1-dead
Copy link
Member

fee1-dead commented Apr 16, 2025

Not too familiar with the specific part of the code base to review beyond that, I think..

r? compiler

@rustbot rustbot assigned wesleywiser and unassigned fee1-dead Apr 16, 2025
@jieyouxu
Copy link
Member

r? jieyouxu

@rustbot rustbot assigned jieyouxu and unassigned wesleywiser Apr 16, 2025
@jieyouxu
Copy link
Member

Note for myself: see if with this PR we can remove the extra normalization from Waffle's PR and not have tests explode (89b4eba)

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, r=me with the comments added.

@@ -432,7 +432,8 @@ impl<'a> CrateLocator<'a> {
if seen_paths.contains(&path) {
continue;
};
seen_paths.insert(path.clone());
seen_paths.insert(path);
let path = spf.path.to_path_buf();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Can you add comments here? I envision something like this:

                        {
                            // Use canonical path to check if we already processed it.
                            // Going through different symlinks does not change the result.
                            let path =
                                try_canonicalize(&spf.path).unwrap_or_else(|_| spf.path.to_path_buf());
                            if seen_paths.contains(&path) {
                                continue;
                            };
                            seen_paths.insert(path);
                        }
                        // Use the original path (potentially with unresolved symlinks),
                        // filesystem code should not care, but this is nicer for diagnostics.
                        let path = spf.path.to_path_buf();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Does this also make the error not reproducible if case there are 2 symlinks? (i.e. you could go from either of them first, the second is ignored)

Copy link
Member Author

@ChrisDenton ChrisDenton Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's as deterministic as our Vec<SearchPath> of library paths, so it should always pick the first library path passed in that resolves to the same directory. Changing the library order passed in would change the diagnostic. Though I don't think that's too different from other diagnostics that depend on the order of things passed in?

Aside: I am slightly uncertain if we need to use canonicalise at all. If two rlibs, for example, are byte-for-byte equal then we should treat them as not conflicting, whether that's due to being a symlink, hard link, copy or a deterministic rebuild. So skipping directories is just a potential performance optimisation. Though I don't know if it has that much impact in practice or if using same-file (thus skipping potentially more expensive checks) would recover most performance loss, if any. I've not looked into it so didn't want to touch that here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

@WaffleLapkin WaffleLapkin self-assigned this Apr 16, 2025
@ChrisDenton
Copy link
Member Author

@bors r=WaffleLapkin

@bors
Copy link
Collaborator

bors commented Apr 18, 2025

📌 Commit 52f35d0 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 18, 2025
Don't canonicalize crate paths

When printing paths in diagnostic we should favour printing the paths that were passed in rather than resolving all symlinks.

This PR changes the form of the crate path but it should only really affect diagnostics as filesystem functions won't care which path is used. The uncanonicalized path was already used as a fallback for when canonicalization failed.

This is a partial alternative to rust-lang#139823.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#137454 (not lint break with label and unsafe block)
 - rust-lang#138934 (support config extensions)
 - rust-lang#139297 (Deduplicate & clean up Nix shell)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` into `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#140000 (skip llvm-config in autodiff check builds, when its unavailable)
 - rust-lang#140007 (Disable has_thread_local on i686-win7-windows-msvc)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 18, 2025
Don't canonicalize crate paths

When printing paths in diagnostic we should favour printing the paths that were passed in rather than resolving all symlinks.

This PR changes the form of the crate path but it should only really affect diagnostics as filesystem functions won't care which path is used. The uncanonicalized path was already used as a fallback for when canonicalization failed.

This is a partial alternative to rust-lang#139823.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#137454 (not lint break with label and unsafe block)
 - rust-lang#138934 (support config extensions)
 - rust-lang#139297 (Deduplicate & clean up Nix shell)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#140000 (skip llvm-config in autodiff check builds, when its unavailable)
 - rust-lang#140007 (Disable has_thread_local on i686-win7-windows-msvc)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#137454 (not lint break with label and unsafe block)
 - rust-lang#138934 (support config extensions)
 - rust-lang#139297 (Deduplicate & clean up Nix shell)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#140000 (skip llvm-config in autodiff check builds, when its unavailable)
 - rust-lang#140007 (Disable has_thread_local on i686-win7-windows-msvc)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#137454 (not lint break with label and unsafe block)
 - rust-lang#138934 (support config extensions)
 - rust-lang#139297 (Deduplicate & clean up Nix shell)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#140000 (skip llvm-config in autodiff check builds, when its unavailable)
 - rust-lang#140007 (Disable has_thread_local on i686-win7-windows-msvc)

r? `@ghost`
`@rustbot` modify labels: rollup
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 19, 2025
Don't canonicalize crate paths

When printing paths in diagnostic we should favour printing the paths that were passed in rather than resolving all symlinks.

This PR changes the form of the crate path but it should only really affect diagnostics as filesystem functions won't care which path is used. The uncanonicalized path was already used as a fallback for when canonicalization failed.

This is a partial alternative to rust-lang#139823.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants