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

MIR EndRegion Statements (was MIR dataflow for Borrows) #39409

Merged
merged 11 commits into from
Jun 19, 2017

Conversation

pnkfelix
Copy link
Member

@pnkfelix pnkfelix commented Jan 30, 2017

This PR adds an EndRegion statement to MIR (where the EndRegion statement is what terminates a borrow).

An earlier version of the PR implemented a dataflow analysis on borrow expressions, but I am now factoring that into a follow-up PR so that reviewing this one is easier. (And also because there are some revisions I want to make to that dataflow code, but I want this PR to get out of WIP status...)

This is a baby step towards MIR borrowck. I just want to get the review process going while I independently work on the remaining steps.

@rust-highfive
Copy link
Collaborator

r? @eddyb

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

@pnkfelix
Copy link
Member Author

r? @arielb1

@rust-highfive rust-highfive assigned arielb1 and unassigned eddyb Jan 30, 2017
@eddyb
Copy link
Member

eddyb commented Jan 30, 2017

So what happened to the plans for keeping this information in a side table? cc @nikomatsakis

let rv = unpack!(block = f(self));
unpack!(block = self.pop_scope(extent, block));
unpack!(block = self.pop_scope(extent.0, block));
if self.seen_borrows.contains(&extent.0) {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn’t early exit from the scope (i.e. exit_scope down below) need a similar treatment?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I had overlooked that. Will fix.

(I had been hoping to avoid attempting to write unit tests for this, but maybe I need to do so.)

@nagisa
Copy link
Member

nagisa commented Jan 30, 2017

So what happened to the plans for keeping this information in a side table?

It makes sense to me to keep these inline, even if just because we already keep StorageLiveDead inline.

@bors
Copy link
Contributor

bors commented Jan 31, 2017

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

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Feb 1, 2017

@eddyb

So what happened to the plans for keeping this information in a side table?

Well, I think I turned sour on this idea because it's hard to keep such a thing 'in sync' if the MIR is changed in any way. It's very fragile. Also, I think these instructions are temporary (once we adopt the NLL strategy, we'll be able to drop them) and there should be relatively few (you only need them for regions that appear in a loan, though I'm not sure if @pnkfelix handles that since I've not read the PR yet). But it is I suppose an option.

@bors
Copy link
Contributor

bors commented Feb 4, 2017

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

@pnkfelix
Copy link
Member Author

pnkfelix commented Feb 6, 2017

@arielb1 has convinced me that I need to add some code-gen tests, even if their initial state is based solely on eyeballing the output to confirm that it is sane.

// (In principle BorrowIdx need not be pub, but since it is associated
// type of BitDenotation impl, hand is forced by privacy rules.)

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the new_index macro?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah I forgot about that; will fix.

@pnkfelix
Copy link
Member Author

pnkfelix commented Feb 8, 2017

Bisection reports that commit 039f5f95ea6646741f9fdd7d6cb9335366d5c82b injected a bug... investigating


update: oh, I see it. This distinguished moves from overwrites. It was also meant to be a refactoring, but it started skipping some important code for the overwrite case.

@pnkfelix pnkfelix force-pushed the mir-borrowck2 branch 2 times, most recently from c8e3994 to 4928c37 Compare February 10, 2017 09:07
@pnkfelix
Copy link
Member Author

@arielb1 has suggested that I had a static check that no regions reach mir return nor resume aka a "no leak" check. This is a good idea; it remains to be implemented.

@pnkfelix
Copy link
Member Author

(Testing reveals that I missed EndRegion's on the unwind path ... fixing in tandem with adding the above suggested static check.)

@@ -540,6 +545,12 @@ impl fmt::Display for ty::Region {
ty::ReSkolemized(_, br) => {
write!(f, "{}", br)
}
ty::ReScope(code_extent) if identify_regions() => {
write!(f, "'{}ce", code_extent.index())
Copy link
Contributor

Choose a reason for hiding this comment

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

does -Zverbose not do it for you? Too verbose?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, -Zverbose is far too verbose, especially when it is embedded within a &<region> <lvalue> borrow-expression.

I don't want or care about the internal structure of the region value for these cases; it is much more convenient to look at the unique id's being generated here (by taking advantage of the fact that one cannot write a lifetime of the form '<number><alphanum>

@bors
Copy link
Contributor

bors commented Feb 18, 2017

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

@pnkfelix pnkfelix changed the title MIR Dataflow for Borrows MIR Dataflow for Borrows (totally WIP) Feb 20, 2017
@bors
Copy link
Contributor

bors commented Mar 15, 2017

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

@pnkfelix pnkfelix force-pushed the mir-borrowck2 branch 2 times, most recently from ad6c87e to 42ad606 Compare March 23, 2017 17:06
@pnkfelix
Copy link
Member Author

Narrowed problem down via opt -opt-bisect-limit. Seems like the execution problem is injected by the Tail Call Elimination pass. I still need to review the LLVM IR to try to understand whether this is an LLVM codegen bug (as I suspect) or if something I have done has caused the Tail Call Elimination pass to "legitimately" mis-optimize this code.

@nikomatsakis
Copy link
Contributor

@pnkfelix nice hunting

@arielb1
Copy link
Contributor

arielb1 commented Jun 15, 2017

Looks like the bug is fixed by llvm-mirror/llvm@f45bea4. I'll have the fix in my Grand ARM Fix Rollup, which I should really get done Real Soon.

@pnkfelix
Copy link
Member Author

pnkfelix commented Jun 16, 2017

@arielb1 helped me confirm that the LLVM bug occurs on our fork of LLVM, but not on LLVM's master copy. And I have now confirmed that the nearest common ancestor between the two also exhibits the bug.

I am bisecting against the LLVM git history to try to isolate a patch for the bug that we might be able to apply to our fork.

Update: Oops, I didn't reload the page so I missed @arielb1's comment. Okay I guess my bisection is not necessary then.

arielb1 added a commit to arielb1/rust that referenced this pull request Jun 18, 2017
So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes rust-lang#42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks rust-lang#39409
bors added a commit that referenced this pull request Jun 19, 2017
Backport fixes to LLVM 4.0 ARM codegen bugs

So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes #42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks #39409

r? @alexcrichton
beta-nominating because this fixes regressions introduced by LLVM 4.0.
@arielb1
Copy link
Contributor

arielb1 commented Jun 19, 2017

Given that the LLVM bug is fixed:
@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 19, 2017

📌 Commit 11f4968 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 19, 2017

⌛ Testing commit 11f4968 with merge 0414594...

bors added a commit that referenced this pull request Jun 19, 2017
MIR EndRegion Statements (was MIR dataflow for Borrows)

This PR adds an `EndRegion` statement to MIR (where the `EndRegion` statement is what terminates a borrow).

An earlier version of the PR implemented a dataflow analysis on borrow expressions, but I am now factoring that into a follow-up PR so that reviewing this one is easier. (And also because there are some revisions I want to make to that dataflow code, but I want this PR to get out of WIP status...)

This is a baby step towards MIR borrowck. I just want to get the review process going while I independently work on the remaining steps.
@bors
Copy link
Contributor

bors commented Jun 19, 2017

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

@bors bors merged commit 11f4968 into rust-lang:master Jun 19, 2017
brson pushed a commit to brson/rust that referenced this pull request Jun 22, 2017
So ARM had quite a few codegen bugs on LLVM 4.0 which are fixed on LLVM
trunk. This backports 5 of them:
r297871 - ARM: avoid clobbering register in v6 jump-table expansion.
    - fixes rust-lang#42248
r294949 - [Thumb-1] TBB generation: spot redefinitions of index
r295816 - [ARM] Fix constant islands pass.
r300870 - [Thumb-1] Fix corner cases for compressed jump tables
r302650 - [IfConversion] Add missing check in
IfConversion/canFallThroughTo
    - unblocks rust-lang#39409
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Aug 26, 2017
Fix destruction extent lookup during HIR -> HAIR translation

My method for finding the destruction extent, if any, from cbed41a (in rust-lang#39409), was buggy in that it sometimes failed to find an extent that was nonetheless present.

This fixes that, and is cleaner code to boot.

Fix rust-lang#43457
bors added a commit that referenced this pull request Aug 26, 2017
Fix destruction extent lookup during HIR -> HAIR translation

My method for finding the destruction extent, if any, from cbed41a (in #39409), was buggy in that it sometimes failed to find an extent that was nonetheless present.

This fixes that, and is cleaner code to boot.

Fix #43457
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants