-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Treat dependencies of proc-macro crates like normal dependencies #69976
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
// instead of relying on this check. | ||
if !is_build_script { | ||
deps.push((filename.to_path_buf(), false)); | ||
} |
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 does this need a different check from the above crate_types.iter().any(|t| t == "proc-macro")
?
Generally it also feels wrong or at least odd that we're putting proc macros seemingly twice, once into the host and once into the target directory. That feels reminiscent of a flag @Zoxc, IIRC, added (-Zdual-macros, or so, I don't recall exactly).
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 crate_types.iter().any(|t| t == "proc-macro")
check is looking for proc macro crates. This check is looking for dependencies of proc-macros, which may not be proc-macros themselves.
For example, suppose we have the dependency graph normal_crate_one
-> proc_macro_crate
-> normal_crate_two
. The crate normal_crate_two
is not a proc macro crate - but since it's a dependency of proc_macro_crate
, it will end up in the host dir.
Had to kill the PR build to get CI back up and running, sorry for the trouble. |
|
||
// Note that we need to resolve deps for proc-macro crates (just like normal crates) | ||
// since we may need to decode `Span`s that reference the `CrateNums` | ||
// of transitive dependencies |
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.
Nit: this comment looks unnecessary, like "look, nothing unusual is happening here, move along". It's the removed special case that required a comment, but didn't have it.
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 still special-case proc macros is some places, so I thought it was worthwhile to explain why we do this (in case someone ever thinks of re-adding this an an optimization).
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.
There's nothing here about proc macros anymore though? I would agree with @petrochenkov that this comment seems more confusing than helpful. We should have a test that ensures this doesn't get re-added?
Why do we need to do this? Can their |
It turns out that this bootstrap change causes us to include build-dependencies of std ( This makes it impossible to write On one hand, there's no reason to be using On the other hand, this will give a confusing error message for anyone who writes At the moment, we have no way of filtering out build dependencies from the sysroot when inspecting Cargo's JSON output - they cannot be distinguished from non-build dependencies, which we do want to include. We have two options:
The long-term fix is for Cargo to provide more information in its json output, so that we can distinguish between build-dependencies and normal dependencies. |
@Zoxc: This issue is unrelated to proc-macro output. It has to do with the actual identifiers of proc-macro functions (e.g. the I opened this because we were hitting this case in #68941 when compiling See also #68941 (comment) |
I don't think it is useful to show ever show the span of a proc-macro function. The user of the proc-macro probably doesn't want to modify or inspect the proc-macro. |
This comment has been minimized.
This comment has been minimized.
@bjorn3: I disagree. While it might be unusual for an error to do so, I think we should treat proc macros as just another kind of definition - just as we might show " defined here" or " defined here", we could potentially show "<proc_macro> defined here". To be clear, whether or not to show the definition of a proc macro would be determined on a per-diagnostic basis. However, unless loading proc-macro dependency metadata has a negative performance impact, I think we should make this change. It will allow any future use of proc-macro |
@Aaron1011 if you can fix the failing tests we can proceed with this |
Previously, we were excluding them since we didn't need to load their metadata. This will no longer work - we now include everything from the 'host' directory except for build-scripts.
862e381
to
9dc999e
Compare
@Dylan-DPC: Fixed |
@Mark-Simulacrum this is ready for review |
I would prefer that we not give users any errors about sysroot crates if possible, and though these two particular crates are probably quite rare to hit on accident I would prefer to add them to a hardcoded list in bootstrap. It's also a bit unclear to me -- the PR description says this was necessary for #68941 but that has since landed. I suspect what you meant is that #68941 won't really be useful if we're not loading dependency spans? Can you update the PR description? @bors try @rust-timer queue Also would like to gather performance diff of this change. I would also like to make sure that @petrochenkov is okay with this, as I'm not really all that familiar with the details of our resolution/crate loading implementation. |
Awaiting bors try build completion |
⌛ Trying commit 9dc999e with merge 3bee93ff74bbd046a67c3acfa691de1399929ee2... |
☀️ Try build successful - checks-azure |
Queued 3bee93ff74bbd046a67c3acfa691de1399929ee2 with parent de6060b, future comparison URL. |
Loading spans from proc macro crates is suboptimal and long term it would be good to inline actually used spans from all build-time dependencies into crates built with their help somehow, but that may be a nontrivial optimization. |
Finished benchmarking try commit 3bee93ff74bbd046a67c3acfa691de1399929ee2, comparison URL. |
On average there seems to be a <1% regression. |
The perf run had a bunch of crates fail to build (see the log at the bottom); e.g. hyper-2 failed with:
Other have similar link failures. We can rerun perf if you think it was spurious, but it feels like errors like that are plausibly caused by this PR somehow? |
Closing in favor of #73706, which is much less invasive. |
Split out from #68941
Previously, we special-cased dependencies of proc-macro crates: we didn't load metadata for them, and we excluded them from the sysroot.
With #68941, this will no longer work - we may need to deserialize
Span
s from proc-macro crates and their dependencies, which requires having metadata available.This PR removes the special handling of proc-macro crates in
resolve_crate_deps
, and adjusts the sysroot generation in bootstrap to only exclude build scripts, not proc-macro dependencies.I don't know of a way to write a test for this. However, the
ui-fulldeps
testsuite implicitly tests this, since it has several tests containingextern crate rustc
(which ends up loading proc-macro dependencies from the sysroot).