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

Handle dev-dependency cycles #14475

Merged
merged 3 commits into from
Apr 25, 2023
Merged

Handle dev-dependency cycles #14475

merged 3 commits into from
Apr 25, 2023

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Apr 3, 2023

cc #14167

This should fix cycles errors mostly (it fixes the one on rome/tools at least, but not on rustc. Though there it might just be because of rustc workspace being rustc workspace). Unfortunately this will effectively duplicate all crates currently, since if we want to be completely correct we'd need to set the test cfg for all dev dependencies and the transitive dependencies of those, something I worry we should try to avoid.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 3, 2023
@Veykril Veykril changed the title Add more complex project-model test Handle dev-dependency cycles Apr 3, 2023
if cfg!(test) {
panic!("{}", err);
}
tracing::error!("{}", err);
Copy link
Contributor

Choose a reason for hiding this comment

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

i've seen a bunch of usage of format strings, but you can reduce this to:

Suggested change
tracing::error!("{}", err);
tracing::error!(?err);

@davidbarsky
Copy link
Contributor

Unfortunately this will effectively duplicate all crates currently, since if we want to be completely correct we'd need to set the test cfg for all dev dependencies and the transitive dependencies of those, something I worry we should try to avoid.

Naive question: is this for only crates that are in the immediate workspace? naively, that feels like a reasonable and fine approach.

@Veykril
Copy link
Member Author

Veykril commented Apr 4, 2023

The way its implemented right now is for all dev-dependencies (declared by workspace members, as dev-dependencies of libraries are irrelevant to the workspace) we will duplicate all their normal (non-build, non-dev) dependencies with the test flags. This would be completely correct as a dev depedency could re-export something from their normal dependencies that depends on the test cfg being set. but this also means as soon as you have a cycle (i.e a dev-dependency on a workspace member) you basically duplicate (almost) the entire crate graph.

An alternative heuristic way would be to only duplicate dependencies in dev-dependency that point to workspace members and use the "non dev-version" for the rest. This will most likely cover the majority of cases.

@bors
Copy link
Collaborator

bors commented Apr 5, 2023

☔ The latest upstream changes (presumably #14490) made this pull request unmergeable. Please resolve the merge conflicts.

@davidbarsky
Copy link
Contributor

The way its implemented right now is for all dev-dependencies (declared by workspace members, as dev-dependencies of libraries are irrelevant to the workspace) we will duplicate all their normal (non-build, non-dev) dependencies with the test flags. This would be completely correct as a dev depedency could re-export something from their normal dependencies that depends on the test cfg being set. but this also means as soon as you have a cycle (i.e a dev-dependency on a workspace member) you basically duplicate (almost) the entire crate graph.

Gotcha, thanks for explaining :)

@winksaville
Copy link

@Veykril pointed me at this issue from a post I made at users.rust-lang. I've built RA from source and have it running on vscode and I'd like to see if this change fixes the problem I'm seeing. I'll give it a try if someone would kindly fix the merge conflicts :)

@Veykril Veykril force-pushed the crate-origins branch 2 times, most recently from 1fa6d5f to 56de543 Compare April 13, 2023 14:11
@Veykril
Copy link
Member Author

Veykril commented Apr 13, 2023

Okay, I've changed it to now only duplicate workspace members. This cuts down the cyclic deps errors in the rust-lang/rust workspace from 50 to 23 (I believe the 23 come from the dependency on the rustc workspace itself which is already handled a bit incorrectly).

@Veykril
Copy link
Member Author

Veykril commented Apr 13, 2023

Unfortunately this manifests a problem now, given we have two crates for some files we will basically duplicate some things in IDE features ... (symbol search etc), I am not sure how to best deal with that

@Veykril Veykril marked this pull request as ready for review April 13, 2023 14:37
@Veykril
Copy link
Member Author

Veykril commented Apr 13, 2023

Okay, actually we fortunately ignore anything but the first module we find for a file so most things should work if we prefer the duplicated crates. (symbol search and so on will still dupe, but I guess that is the price people will have to pay for now for adding a dev-dependency like that)

Let's merge this next monday

@winksaville
Copy link

winksaville commented Apr 14, 2023

FYI, I tested my workspace and there are no longer any errors. Txs!!!!

@bors
Copy link
Collaborator

bors commented Apr 20, 2023

☔ The latest upstream changes (presumably #14599) made this pull request unmergeable. Please resolve the merge conflicts.

@chenyukang
Copy link
Member

I verified it in my local, it works!!

@Veykril
Copy link
Member Author

Veykril commented Apr 25, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 25, 2023

📌 Commit b4345e9 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Apr 25, 2023

⌛ Testing commit b4345e9 with merge 2cbed3d...

bors added a commit that referenced this pull request Apr 25, 2023
Handle dev-dependency cycles

cc #14167

This should fix cycles errors mostly (it fixes the one on rome/tools at least, but not on rustc. Though  there it might just be because of rustc workspace being rustc workspace). Unfortunately this will effectively duplicate all crates currently, since if we want to be completely correct we'd need to set the test cfg for all dev dependencies and the transitive dependencies of those, something I worry we should try to avoid.
@bors
Copy link
Collaborator

bors commented Apr 25, 2023

💔 Test failed - checks-actions

@Veykril
Copy link
Member Author

Veykril commented Apr 25, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 25, 2023

📌 Commit e205af2 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Apr 25, 2023

⌛ Testing commit e205af2 with merge a96bb45...

@bors
Copy link
Collaborator

bors commented Apr 25, 2023

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing a96bb45 to master...

@bors bors merged commit a96bb45 into rust-lang:master Apr 25, 2023
@Veykril Veykril deleted the crate-origins branch April 25, 2023 10:50
@Veykril
Copy link
Member Author

Veykril commented Apr 25, 2023

Something went terribly wrong with the rebase it seems, the metrics don't look good...

bors added a commit that referenced this pull request Apr 25, 2023
Revert "Handle dev-dependency cycles"

Reverts #14475

I managed to fix the problem that causes the metric failures, but this still severely degrades IDE features in a way that makes the user experience ***worse*** than before. I am not sure how to address this, I wonder what the jetbrains plugin is doing in these cases.
@chenyukang
Copy link
Member

Yes, this PR fixed cycle deps issues, but seems has a bug.
From my daily usage, functions from other crates are not working now, before this PR:

image

After merging this PR:
image

The hover tip for async_trait, extract_peer_id.etc also don't work.

Repo: https://github.com/nervosnetwork/ckb FYI.

@Veykril
Copy link
Member Author

Veykril commented Apr 25, 2023

Yes, this PR in general causes a bunch of issues which are inherent to the fact that we now have a bunch of items come from two different crates that are semantically the same which breaks features everywhere. The approach in this PR doesn't seem to work out so it will be reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants