-
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
Unify "input" and "no input" paths in run_compiler
#118002
Conversation
@@ -293,7 +293,7 @@ fn run_compiler( | |||
>, | |||
using_internal_features: Arc<std::sync::atomic::AtomicBool>, | |||
) -> interface::Result<()> { | |||
let mut early_error_handler = EarlyErrorHandler::new(ErrorOutputType::default()); | |||
let mut default_handler = EarlyErrorHandler::new(ErrorOutputType::default()); |
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 think the new name is any better. It is only supposed to be used for error handling very early on. After the Session is created it should't be used anymore.
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.
Well, there is EarlyErrorHandler used after the session is created. Within the
interface::run_compiler` call there is this:
let handler = EarlyErrorHandler::new(sess.opts.error_format);
The idea is that default_handler
as a name contrasts more clearly with handler
than early_error_handler
does. Because they both have type EarlyErrorHandler
.
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.
All uses of let handler = EarlyErrorHandler::new(sess.opts.error_format);
have Session
passed in as argument and thus should work with sess.fatal("...");
just fine. I think it would make sense to remove all EarlyErrorHandler
usage when sess
is in scope and remove the error_format
argument from EarlyErrorHandler
.
23e1b0e
to
0645a6d
Compare
I addressed two of the comments. I left |
If the |
Do you mean a diff like this?
That changes the output on error slightly, e.g with
to this:
Is that expected/ok? |
Yes
I see.
On one hand it is more consistent with almost all other errors, on the other hand it is a bit noisier. I think it is fine, but maybe ask on zulip what others think? |
I asked on Zulip; not much response so far. One possible way to look at this: the current PR preserves the existing behaviour. We could declare the conversion of the post-session |
Sure, r=me I don't know if this PR will conflict with your #117993. |
It will conflict. I'll let that one merge first then fix this up. |
☔ The latest upstream changes (presumably #117993) made this pull request unmergeable. Please resolve the merge conflicts. |
Yes, its type is `EarlyErrorHandler`, but there is another value of that type later on in the function called `handler` that is initialized with `sopts.error_format`. So `default_handler` is a better name because it clarifies that it is initialized with `ErrorOutputType::default()`.
`rustc_driver_impl::run_compiler` currently has two `interface::run_compiler` calls: one for the "no input" case, and one for the normal case. This commit merges the former into the latter, which makes the control flow easier to read and avoids some duplication. It also makes it clearer that the "no input" case will describe lints before printing crate info, while the normal case does it in the reverse order. Possibly a bug?
Currently we have an inconsistency between the "input" and "no input" cases: - no input: `rustc --print=sysroot -Whelp` prints the lint help. - input: `rustc --print=sysroot -Whelp a.rs` prints the sysroot. It makes sense to print the lint help in both cases, because that's what happens with `--help`/`-Zhelp`/`-Chelp`. In fact, the `describe_lints` in the "input" case happens amazingly late, after *parsing*. This is because, with plugins, lints used to be registered much later, when the global context was created. But rust-lang#117649 moved lint registration much earlier, during session construction. So this commit moves the `describe_lints` call to a single spot for both for both the "input" and "no input" cases, as early as possible. This is still not as early as `--help`/`-Zhelp`/`-Chelp`, because `-Whelp` must wait until the session is constructed.
I find `Compilation::and_then` hard to read. This commit removes it, simplifying the control flow in `run_compiler`, and reducing the number of lines of code. In particular, `list_metadata` and `process_try_link` (renamed `rlink`) are now only called if the relevant condition is true, rather than that condition being checked within the function.
0645a6d
to
472f7c9
Compare
I rebased. @bors r=bjorn3 |
☀️ Test successful - checks-actions |
Finished benchmarking commit (28345f0): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 675.969s -> 675.681s (-0.04%) |
A follow-up to #117649.
r? @bjorn3