-
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
MIR EndRegion Statements (was MIR dataflow for Borrows) #39409
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
r? @arielb1 |
So what happened to the plans for keeping this information in a side table? cc @nikomatsakis |
src/librustc_mir/build/scope.rs
Outdated
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) { |
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.
Doesn’t early exit from the scope (i.e. exit_scope
down below) need a similar treatment?
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.
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.)
It makes sense to me to keep these inline, even if just because we already keep StorageLiveDead inline. |
☔ The latest upstream changes (presumably #39230) made this pull request unmergeable. Please resolve the merge conflicts. |
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. |
73080e6
to
46771dc
Compare
☔ The latest upstream changes (presumably #39463) made this pull request unmergeable. Please resolve the merge conflicts. |
3418d21
to
8603d92
Compare
@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)] |
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.
Use the new_index
macro?
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.
ah I forgot about that; will fix.
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. |
c8e3994
to
4928c37
Compare
@arielb1 has suggested that I had a static check that no regions reach mir |
4928c37
to
6193740
Compare
(Testing reveals that I missed EndRegion's on the unwind path ... fixing in tandem with adding the above suggested static check.) |
src/librustc/util/ppaux.rs
Outdated
@@ -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()) |
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.
does -Zverbose
not do it for you? Too verbose?
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.
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>
☔ The latest upstream changes (presumably #39854) made this pull request unmergeable. Please resolve the merge conflicts. |
6193740
to
1293feb
Compare
☔ The latest upstream changes (presumably #40383) made this pull request unmergeable. Please resolve the merge conflicts. |
ad6c87e
to
42ad606
Compare
Narrowed problem down via |
@pnkfelix nice hunting |
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. |
@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. |
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
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.
Given that the LLVM bug is fixed: |
📌 Commit 11f4968 has been approved by |
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.
☀️ Test successful - status-appveyor, status-travis |
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
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
This PR adds an
EndRegion
statement to MIR (where theEndRegion
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.