-
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
Streamline Compiler
#64016
Streamline Compiler
#64016
Conversation
☔ The latest upstream changes (presumably #63827) made this pull request unmergeable. Please resolve the merge conflicts. |
Some of the changes here seems questionable (the shuffling of code and the removal of |
This is where I express some frustration.
|
Here is an updated picture showing things after my changes. The graph is neater partly because I did a better job drawing it, but also partly because it's simpler: it has three fewer boxes ( |
It's a false dependency. The result isn't used and there are no relevant side-effects.
c1c386e
to
392b91f
Compare
#63827 landed over the weekend, which removed one of the |
392b91f
to
92a0cbd
Compare
The |
This comment has been minimized.
This comment has been minimized.
src/librustc_driver/lib.rs
Outdated
|
||
// Drop GlobalCtxt after starting codegen to free memory | ||
mem::drop(compiler.global_ctxt()?.take()); | ||
compiler.codegen_and_link()?; |
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.
having reviewed @Zoxc's PRs it seems to me like only this commit is actually problematic for the querification PRs (like those PRs would have to revert this commit to be doable). As far as I can tell (both from the code and your graphs) it's not that much additional complexity to keep around either.
What do you think?
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.
Thank you for the feedback. Are you referring to #59404? If so:
- If there's a good reason to keep the
ongoing_codegen
/link
split then I am fine to remove this commit. - Is there a good reason? Does Make ongoing_codegen a query #59404 and its predecessors use the existing passes because they are there, rather than because they are necessary?
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.
- If there's a good reason to keep the
ongoing_codegen
/link
split then I am fine to remove this commit.
The main reason to keep this separate because ongoing_codegen
needs the GlobalCtxt
to be around, while we want to free GlobalCtxt
before linking. When we remove queries from rustc_interface
this mean this cannot be a combined operation.
Another reason is that it's reasonable for front-ends to do only code generation, but no linking, although that is not yet possible.
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 don't understand the point about GlobalCtxt
. My patch preserves the "free GlobalCtxt
before linking" behaviour.
As for the second point, I would argue that YAGNI applies.
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 problem isn't that your PR doesn't keep the early drop, it's the way the query PR works, where the GlobalCtxt
lives as long as a closure and is automatically dropped at the end of it. So you can't call the combined function inside the closure and you can't call it outside the closure, thus needing to split it up again.
@@ -261,9 +260,6 @@ pub fn register_plugins<'a>( | |||
}); | |||
} | |||
|
|||
// If necessary, compute the dependency graph (in the background). | |||
compiler.dep_graph_future().ok(); | |||
|
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.
Moving the dep graph loading to a later point is a performance regression. This is currently done as early as possible, although I'd like for it be done immediately when creating the compiler context, but that requires some changes as currently we need to do this after parsing to pick up the crate name.
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 performance run shows that these five commits provide a slightly performance improvement.
).map_err(|_| ErrorReported)?; | ||
|
||
Ok(()) | ||
}) | ||
} | ||
|
||
pub fn compile(&self) -> Result<()> { |
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 meant as an simple utility function and an example for users of rustc_interface
of something that mirrors a regular compilation session without all the complexities of the full rustc driver (in rustc_driver
).
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.
If an example is needed, why not provide it in documentation? Don't leave unnecessary code in the product.
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 have CI testable example code snippets in the rustc-guide?
- Or maybe we could put such a snippet into the rustdoc comments that we process for
rustc
's generated documentation?
If either of the above is true, then I could go along with @nnethercote 's reasoning here, though then I would want that migration to happen either before this PR, or as part of this PR.
(Otherwise, I'm with @Zoxc; Its hard enough for people to get started using the compilier as a library or hacking on rustc
itself; simple examples of how to use things like rustc_interface
are in their own way part of our product...)
@bors try |
Streamline `Compiler` A few commits to clean up `Compiler`. r? @Zoxc
☀️ Try build successful - checks-azure |
@rust-timer build 468729d |
Success: Queued 468729d with parent ef54f57, comparison URL. |
Finished benchmarking try commit 468729d, comparison URL. |
`Compiler::register_plugins()` calls `passes::register_plugins()`, which calls `Compiler::dep_graph_future()`. This is the only way in which a `passes` function calls a `Compiler` function. This commit moves the `dep_graph_future()` call out of `passes::register_plugins()` and into `Compiler::register_plugins()`, which is a more sensible spot for it. This will delay the loading of the dep graph slightly -- from the middle of plugin registration to the end of plugin registration -- but plugin registration is fast enough (especially compared to expansion) that the impact should be neglible.
92a0cbd
to
443e6d2
Compare
I removed the commit that merges |
443e6d2
to
bdf5b54
Compare
bdf5b54
to
8e53227
Compare
`Compiler::compile()` is different to all the other `Compiler` methods because it lacks a `Queries` entry. It only has one call site, which is in a test that doesn't need its specific characteristics. This patch replaces that call with a call to `Compile::link()`, which is similar enough for the test's purposes. It also notes that the method is an illustrative example of how `Compiler` can be used.
8e53227
to
2521189
Compare
I have changed the fourth commit to retain The four commits as they now stand.
@oli-obk: can you re-review? Thanks. |
@bors r+ |
📌 Commit 2521189 has been approved by |
…i-obk Streamline `Compiler` A few commits to clean up `Compiler`. r? @Zoxc
Rollup of 16 pull requests Successful merges: - #63356 (Issue#63183: Add fs::read_dir() and ReadDir warning about iterator order + example) - #63934 (Fix coherence checking for impl trait in type aliases) - #64016 (Streamline `Compiler`) - #64296 (Document the unstable iter_order_by library feature) - #64443 (rustdoc: general cleanup) - #64622 (Add a cycle detector for generic `Graph`s and `mir::Body`s) - #64689 (Refactor macro by example) - #64698 (Recover on `const X = 42;` and infer type + Error Stash API) - #64702 (Remove unused dependencies) - #64717 (update mem::discriminant test to use assert_eq and assert_ne over comparison operators) - #64720 ( remove rtp.rs, and move rtpSpawn and RTP_ID_ERROR to libc) - #64721 (Fixed issue from #64447) - #64725 (fix one typo) - #64737 (fix several issues in String docs) - #64742 (relnotes: make compatibility section more sterile and fix rustc version) - #64748 (Fix #64744. Account for the Zero sub-pattern case.) Failed merges: r? @ghost
A few commits to clean up
Compiler
.r? @Zoxc