Skip to content
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

Merged

Conversation

pnkfelix
Copy link
Member

Buffer the errors generated during MIR-borrowck (aka NLL).

This is the first big step towards resolving issue #46908.

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 20, 2018
@pnkfelix
Copy link
Member Author

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Jul 20, 2018
@estebank
Copy link
Contributor

The code changes look reasonable. Has there been no change to the stderr output of any test? I would have expected some switches in the ordering of at least some existing tests.

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.

Copy link
Contributor

@nikomatsakis nikomatsakis left a 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?

moved_error_reported: FxHashSet<Place<'tcx>>,
/// Errors to be reported buffer
errors_buffer: Vec<DiagnosticBuilder<'cx>>,
Copy link
Contributor

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:

/// 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) .

Copy link
Member Author

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

@bors
Copy link
Contributor

bors commented Jul 21, 2018

☔ The latest upstream changes (presumably #52405) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix
Copy link
Member Author

@estebank asked:

Has there been no change to the stderr output of any test? I would have expected some switches in the ordering of at least some existing tests.

I worked pretty hard to try to ensure that the ordering is unchanged on all tests.

@pnkfelix
Copy link
Member Author

@estebank noted:

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.

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.

@pnkfelix pnkfelix force-pushed the buffer-nll-errors-for-z-borrowck-migrate branch from 682eedf to 06ce9cb Compare July 23, 2018 11:26
@pnkfelix pnkfelix force-pushed the buffer-nll-errors-for-z-borrowck-migrate branch from 06ce9cb to a1d3574 Compare July 23, 2018 12:08
@pnkfelix
Copy link
Member Author

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.

or ... hmm, I wonder if there's a reasonable way to drain the errors buffer immediately in response to an ICE...

spastorino and others added 4 commits July 23, 2018 14:20
(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?
@pnkfelix pnkfelix force-pushed the buffer-nll-errors-for-z-borrowck-migrate branch from a1d3574 to 1a0294b Compare July 23, 2018 12:20
@pnkfelix pnkfelix dismissed nikomatsakis’s stale review July 23, 2018 12:21

I incorporated the Vec<Diagnostic> idea into the PR.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 23, 2018

@bors r+ p=1

EP2 criticial.

@bors
Copy link
Contributor

bors commented Jul 23, 2018

📌 Commit 1a0294b has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 23, 2018
@bors
Copy link
Contributor

bors commented Jul 23, 2018

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Jul 23, 2018

📌 Commit 1a0294b has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jul 23, 2018

⌛ Testing commit 1a0294b with merge 8dbbd81...

bors added a commit that referenced this pull request Jul 23, 2018
…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.
@bors
Copy link
Contributor

bors commented Jul 23, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 8dbbd81 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants