-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Turn crate store into a resolver output #65625
Conversation
pub struct CStore { | ||
metas: RwLock<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>, | ||
crate metadata_loader: Box<dyn MetadataLoader + Sync>, | ||
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we cannot remove this Lrc
because CStore
has to be cloneable.
EDIT: The reason - #65625 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I didn't even realize that was a thing. Do you know where the clones are coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could get rid of it by having the expansion
query produce the CStore
structure and redirect later uses to that instead. That would make the structure more like before this PR. It doesn't seem like a huge win right now though. It might be worth waiting on moving things into TyCtxt. Maybe we'd replace it by a crate_metadata(CrateNum) -> &'tcx CrateMetadata
query or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this certainly can be done later if "later" is a better time due to other changes (like TyCtxt
).
The clone itself (the primary effect) is cheap - only a vector of Lrc
s is cloned.
The locks around CrateMetadata::{dependencies,dep_kind,extern_crate}
(the secondary effect) are also unlikely to be accessed often and cause performance issues.
Regarding locks in
|
src/librustc_interface/passes.rs
Outdated
@@ -211,7 +171,7 @@ impl BoxedResolver { | |||
Err(resolver) => { | |||
let resolver = &*resolver; | |||
resolver.borrow_mut().access(|resolver| { | |||
ExpansionResult::from_resolver_ref(resolver) | |||
ExpansionResult::from_resolver_outputs(resolver.clone_outputs()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why we can't have nice things.
This case puts the cloneability requirement on resolver outputs (https://github.com/rust-lang/rust/pull/65625/files#r336780545), but it actually never happens in rustc
, only in rustdoc
and perhaps other tools using rustc_interface
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would cloning be needed? Is this that support for resolving things after rustc_resolve
finishes?
In that case I'm not sure why we need to clone the outputs - is it to be able to keep the original resolver around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, rustc_interface
is very hard to reason about. ¯_(ツ)_/¯
It needs some investigation, but I'm not sure I'll get to it until the next weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clone only happens with rustdoc since it needs the resolver available at a later stage. It would be nicer if we could extract the information rustdoc needs instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we split the resolver up so that we can pass a &CStore
later to the parts of it that we need to keep around? (i.e. the local module tree)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make expansion
query produce the final CStore
structure and I said in my other comment. That won't help to get rid of the clone here though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if rustdoc didn't cause that clone to happen but instead did its resolving in some other way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really feels like the new code is not worse, right? So we can definitely leave this for a future PR (filing an issue wouldn't hurt). I'd rather not block this PR on that cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clone was there before this PR.
cc @rust-lang/compiler @Mark-Simulacrum |
r? @Mark-Simulacrum or @Zoxc probably |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great, excellent cleanup!
I agree with @eddyb that the cloning is unfortunate but ultimately seems 'fine' for now, we can clean it up in a future PR.
@@ -191,6 +191,8 @@ pub trait MetadataLoader { | |||
-> Result<MetadataRef, String>; | |||
} | |||
|
|||
pub type MetadataLoaderDyn = dyn MetadataLoader + Sync; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this to be Sync even in the non-parallel compiler case? Maybe we want sync::Sync
here which is either the proper marker trait from core or the data structures one which is just auto for everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metadata loaders have no fields, so it doesn't matter which Sync
trait is used.
src/librustc_interface/passes.rs
Outdated
@@ -159,13 +156,12 @@ pub fn configure_and_expand( | |||
} | |||
|
|||
pub struct ExpansionResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to re-wrap the resolve outputs here? I guess we do get Steal...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExpansionResult
is removed.
r=me unless you want to investigate my comments in this PR |
This PR looks good to me too. |
Let's run perf on this. |
Awaiting bors try build completion |
⌛ Trying commit 2a329d24c0f81e3485ab3148ea4be60e3beea33b with merge fb82105b083af835f36cba113878eabd97ab8573... |
☀️ Try build successful - checks-azure |
Queued fb82105b083af835f36cba113878eabd97ab8573 with parent 10f12fe, future comparison URL. |
Not sure why I did that, there should be ~no changes for the non-parallel case. |
📌 Commit 2a329d24c0f81e3485ab3148ea4be60e3beea33b has been approved by |
Finished benchmarking try commit fb82105b083af835f36cba113878eabd97ab8573, comparison URL. |
☔ The latest upstream changes (presumably #65733) made this pull request unmergeable. Please resolve the merge conflicts. |
Plugin search doesn't need a crate loader, only crate locator
Crate metadatas are still stored as `Lrc<CrateMetadata>` in `CStore` because crate store has to be cloneable due to `Resolver::clone_outputs`.
@bors r=Mark-Simulacrum,Zoxc |
📌 Commit 94216ce has been approved by |
🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened |
…rum,Zoxc Turn crate store into a resolver output Crate store (`CStore`) is a vector of data (`CrateMetadata`) associated with extern crates loaded during the current compilation session. All crates are loaded in the resolver when resolving either paths pointing to extern prelude or `extern crate` items. (There are also a couple of crates like panic runtime that are loaded kind of like implicit `extern crate`s, but that also happens in resolve.) The use of `CStore` from `rustc_plugin` (which is outside of the resolver) was unnecessary because legacy plugins are not added to the crate store and don't use `CrateNum`s. So, `CStore` can be produced by the resolver instead of being kept in some really global data (`rustc_interface::Compiler`) like now. As a result of crate store being more "local" we can now remove some locks and `Lrc`s.
Rollup of 8 pull requests Successful merges: - #65625 (Turn crate store into a resolver output) - #65627 (Forbid non-`structural_match` types in const generics) - #65710 (Update cargo) - #65729 (Update test cases for vxWorks) - #65746 (Tweak format string error to point at arguments always) - #65753 (Don't assert for different instance on impl trait alias) - #65755 (Avoid ICE when adjusting bad self ty) - #65766 (Update hashbrown to 0.6.2) Failed merges: r? @ghost
☔ The latest upstream changes (presumably #65771) made this pull request unmergeable. Please resolve the merge conflicts. |
Crate store (
CStore
) is a vector of data (CrateMetadata
) associated with extern crates loaded during the current compilation session.All crates are loaded in the resolver when resolving either paths pointing to extern prelude or
extern crate
items. (There are also a couple of crates like panic runtime that are loaded kind of like implicitextern crate
s, but that also happens in resolve.)The use of
CStore
fromrustc_plugin
(which is outside of the resolver) was unnecessary because legacy plugins are not added to the crate store and don't useCrateNum
s.So,
CStore
can be produced by the resolver instead of being kept in some really global data (rustc_interface::Compiler
) like now.As a result of crate store being more "local" we can now remove some locks and
Lrc
s.