-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Buffer NLL errors #52566
Buffer NLL errors #52566
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
The code changes look reasonable. Has there been no change to the meta note With this kind of buffering of errors, I worry that when encountering ICEs a lot of context might be lost if the ICE happens before the NLL errors vector is drained. That being said I'm not opposed to the idea and ICEs are rare enough that in practice it shouldn't matter, it's just something to keep in mind. |
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.
Looks good, but what do you think about storing Diagnostic
instead of DiagnosticBuilder
?
src/librustc_mir/borrow_check/mod.rs
Outdated
moved_error_reported: FxHashSet<Place<'tcx>>, | ||
/// Errors to be reported buffer | ||
errors_buffer: Vec<DiagnosticBuilder<'cx>>, |
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.
So, I hate to mention this after y'all have been wrestling with lifetimes for so long, but it occurs to me that this PR would be much simpler if DiagnosticBuilder
did not carry a 'cx
lifetime. Indeed, if we look at the definition of DiagnosticBuilder
, we see that it is the combination of two things:
rust/src/librustc_errors/diagnostic_builder.rs
Lines 23 to 29 in bd455ef
/// Used for emitting structured error messages and other diagnostic information. | |
#[must_use] | |
#[derive(Clone)] | |
pub struct DiagnosticBuilder<'a> { | |
pub handler: &'a Handler, | |
diagnostic: Diagnostic, | |
} |
I believe that the diagnostic
field contains everything related to display the error and so forth, and the Handler
just has the links to the session, stdout, etc. I believe that @michaelwoerister introduced this precisely so that we can serialize the set of errors produced by a query then load them later and "replay" them (also cc @estebank, who can problem confirm this).
I was thinking that maybe we should add a method like
impl DiagnosticBuilder<'cx> {
fn buffer(self, buffered: &mut Vec<Diagnostic>) -> Diagnostic {
buffered.push(self.diagnostic);
}
}
and then we can replace all those calls like .emit()
with .buffer()
. Moreover, the buffer vector doesn't carry any lifetime.
In order to emit later, you can use DiagnosticBuilder::new_diagnostic(tcx.sess.diagnostic(), d)
.
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'll look into this now
☔ The latest upstream changes (presumably #52405) made this pull request unmergeable. Please resolve the merge conflicts. |
@estebank asked:
I worked pretty hard to try to ensure that the ordering is unchanged on all tests. |
@estebank noted:
Indeed, I actually wanted the buffering to be controlled (i.e. be disabled) via a debug flag, but I wasn't able to come up with enough of an argument for doing so. I think that the case you note might serve as a motivation for adding a debug flag to force an "immediate mode" on these errors. |
682eedf
to
06ce9cb
Compare
06ce9cb
to
a1d3574
Compare
or ... hmm, I wonder if there's a reasonable way to drain the errors buffer immediately in response to an ICE... |
(pnkfelix updated to address tidy, and to change the buffer from `Vec<DiagnosticBuilder<'errs>>` to a `Vec<Diagnostic>` in order to avoid painful lifetime maintenance.)
Right now its solely used for `check_local`, which ... I guess is not surprising?
a1d3574
to
1a0294b
Compare
I incorporated the Vec<Diagnostic>
idea into the PR.
@bors r+ p=1 EP2 criticial. |
📌 Commit 1a0294b has been approved by |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 1a0294b has been approved by |
…ate, r=nikomatsakis Buffer NLL errors Buffer the errors generated during MIR-borrowck (aka NLL). This is the first big step towards resolving issue #46908.
☀️ Test successful - status-appveyor, status-travis |
Buffer the errors generated during MIR-borrowck (aka NLL).
This is the first big step towards resolving issue #46908.