Skip to content

Generate "invalidates" facts when -Znll-facts is passed #50798

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

Merged
merged 5 commits into from
May 23, 2018

Conversation

sapphire-arches
Copy link
Contributor

Most of the new code is copied directly from the heart of the MIR borrowchecker. I was expecting more fundamental structural changes, hence the copying. This appears to work as it stands, but I'd like to submit a follow-up PR to reduce code duplication. I figured that could wait though, since this is blocking a large amount of work in the borrow check repository and I'm out of time for tonight =).

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 16, 2018
@rust-highfive
Copy link
Contributor

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

[00:04:45] travis_fold:start:tidy
travis_time:start:tidy
tidy check
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/nll/invalidation.rs:78: line longer than 100 chars
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/nll/invalidation.rs:239: TODO is deprecated; use FIXME
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/nll/invalidation.rs:252: TODO is deprecated; use FIXME
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/nll/invalidation.rs:253: line longer than 100 chars
[00:04:45] tidy error: /checkout/src/librustc_mir/borrow_check/nll/invalidation.rs:829: line longer than 100 chars
[00:04:47] some tidy checks failed
[00:04:47] 
[00:04:47] 
[00:04:47] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:47] 
[00:04:47] 
[00:04:47] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:47] Build completed unsuccessfully in 0:01:54
[00:04:47] Build completed unsuccessfully in 0:01:54
[00:04:47] Makefile:79: recipe for target 'tidy' failed
[00:04:47] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0c6006b2
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@@ -38,6 +38,9 @@ crate struct AllFacts {

// `region_live_at(R, P)` when the region R appears in a live variable at P
crate region_live_at: Vec<(RegionVid, LocationIndex)>,

// `invalidates(P, B)` when the borrow B is invalidated at point P
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man I want to change from Borrow terminology to Loan. =)

mir_def_id: DefId,
borrow_set: &BorrowSet<'tcx>,
) {
if !all_facts.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd probably write:

if let Some(all_facts) = all_facts {
    .. // inner stuff
}

then you don't, I think, need the call to take() etc. But whatever.

} => {
self.consume_operand(ContextKind::Yield.new(location), value);

// ** FIXME(bob_twinkles) figure out what the equivalent of this is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the equivalent here is invalidating the loans at the point after the yield. Basically we want to invalidate all loans that are borrowing "local" content (something owned by current stack frame) at this point:

let resume_index = self.location_table.start_index(resume.start_location())

(That is taken from my branch that integrated with the new approach)

// }
}
TerminatorKind::Resume | TerminatorKind::Return | TerminatorKind::GeneratorDrop => {
// ** FIXME(bob_twinkles) figure out what the equivalent of this is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to invalidate all loans that refer to content owned by the current stack frame; I'm actually not sure why this uses with_outgoing_borrows, I think for our purposes the current location is fine (self.location_table.start_index(loc)).

That is what I did in my branch that integrates with dataflow, anyway:

https://github.com/nikomatsakis/rust/blob/5656960ea0b62624341a10c175ab9d154a5fe94c/src/librustc_mir/borrow_check/mod.rs#L606-L618

// unique or mutable borrows are invalidated by writes.
// Reservations count as writes since we need to check
// that activating the borrow will be OK
// TOOD(bob_twinkles) is this actually the right thing to do?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems right to me..why are you worried?

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 16, 2018
@sapphire-arches sapphire-arches added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 17, 2018
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented May 17, 2018

📌 Commit 965eef9 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 May 17, 2018
sapphire-arches added a commit to sapphire-arches/rust that referenced this pull request May 19, 2018
Following up my changes in rust-lang#50798, I wanted to grab at least the low-hanging
fruit for code deduplication.
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented May 22, 2018

📌 Commit 965eef9 has been approved by nikomatsakis

@bors
Copy link
Collaborator

bors commented May 23, 2018

⌛ Testing commit 965eef9 with merge 531e4ab...

bors added a commit that referenced this pull request May 23, 2018
Generate "invalidates" facts when -Znll-facts is passed

Most of the new code is copied directly from the heart of the MIR borrowchecker. I was expecting more fundamental structural changes, hence the copying. This appears to work as it stands, but I'd like to submit a follow-up PR to reduce code duplication. I figured that could wait though, since this is blocking a large amount of work in the borrow check repository and I'm out of time for tonight =).

r? @nikomatsakis
@bors
Copy link
Collaborator

bors commented May 23, 2018

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

@bors bors merged commit 965eef9 into rust-lang:master May 23, 2018
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.

4 participants