Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[MIR] Refine representation and translation of calls #30481
Conversation
rust-highfive
assigned
nikomatsakis
Dec 19, 2015
nagisa
reviewed
Dec 19, 2015
| match self.unreachable_block { | ||
| Some(b) => b, | ||
| None => { | ||
| let bl = self.bcx(mir::START_BLOCK).fcx.new_block(false, "unreachable", None); |
This comment has been minimized.
This comment has been minimized.
nagisa
reviewed
Dec 19, 2015
| @@ -92,7 +92,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { | |||
| // not entirely precise | |||
| if !otherwise.is_empty() { | |||
| let join_block = self.join_otherwise_blocks(otherwise); | |||
| self.panic(join_block); | |||
| self.panic(join_block, "something about matches algorithm not being precise", span); | |||
This comment has been minimized.
This comment has been minimized.
nagisa
force-pushed the
nagisa:mir-calls-2
branch
from
ffebbf1
to
acc49ad
Dec 19, 2015
nagisa
changed the title
Refine representation and translation of MIR calls
[MIR] Refine representation and translation of calls
Dec 19, 2015
nagisa
force-pushed the
nagisa:mir-calls-2
branch
3 times, most recently
from
0f066dc
to
fdaa56a
Dec 21, 2015
This comment has been minimized.
This comment has been minimized.
|
All in all, I think it is in a good enough spot now to begin reviewing it @nikomatsakis. |
nagisa
force-pushed the
nagisa:mir-calls-2
branch
from
b245183
to
fdaa56a
Dec 21, 2015
luqmana
reviewed
Dec 22, 2015
| Some(attrs), | ||
| debugloc); | ||
| if must_copy_dest { | ||
| // FIXME: What do we do here? |
This comment has been minimized.
This comment has been minimized.
luqmana
Dec 22, 2015
Member
AFAIK should just do the same as below: store_ty the result from Invoke to the destination.
This comment has been minimized.
This comment has been minimized.
nagisa
Dec 22, 2015
Author
Contributor
The problem here (is much harder than it looks at the first look!) is that invoke is a basic block terminator and thus we cannot add anything else to the current block. We would have to add, or rather, prepend a store instruction to a success branch, but… that’s tricky, because:
- That’s hacky (duh);
- I can’t seem to see anyway to do it;
- It would make some already-generated blocks invalid (e.g. we would have to assert that success branch has higher basic-block number and has not been translated yet).
Basically, to me it seems like we should change the MIR some more and figure out if destination must be copied (or rather, avoid copying destination altogether as well as encoding the copy, if necessary) during the MIR build phase.
EDIT: we could also generate a temporary block with a store and branch to success block in it (still doesn’t avoid 3rd issue). Sounds like a most correct hack to do, but I’ll see if anybody has better ideas.
This comment has been minimized.
This comment has been minimized.
|
As I mentioned on IRC, I'm not sure if I think that splitting out "diverging call" into its own terminator is a good idea. My concerns are:
Basically, I'm not sure if the code for handling calls vs diverging calls will wind up being so very different in other passes. But it's a bit hard to know just now. A compromise might just be to introduce an enum into the call that is either In any case, let me read further before reaching final judgement. |
This comment has been minimized.
This comment has been minimized.
The last commit contains conversion to inner-enum, like you proposed on IRC. Feel free to compare. |
nagisa
force-pushed the
nagisa:mir-calls-2
branch
from
6227ccc
to
b0832b8
Dec 22, 2015
This comment has been minimized.
This comment has been minimized.
|
Comments on nagisa@0c7d57d are yet to be fixed. EDIT: changed/fixed in nagisa@1c2f0d8. @nikomatsakis the code still looks equally ugly to me, but not sure if it could be made any better. |
nagisa
force-pushed the
nagisa:mir-calls-2
branch
from
1c2f0d8
to
3c05a45
Jan 1, 2016
This comment has been minimized.
This comment has been minimized.
|
|
nagisa
force-pushed the
nagisa:mir-calls-2
branch
from
3c05a45
to
f6d2faf
Jan 4, 2016
This comment has been minimized.
This comment has been minimized.
|
In all those cases where I gave nits about exhaustive matches, we were just trying to handle converging cases -- might be that a helper function for extracting the converging cases would be good. OTOH, I guess this is why you split those cases into two to start with. |
This comment has been minimized.
This comment has been minimized.
|
OK, so, as you say, this is a big PR, and I feel like I could go on pointing out nits forever. But I'd rather we land it and just hack and try to clean things up. Some of these commits get pretty involved, but that may just be unavoidable if we want to generate less naive IR. Calls are just complicated. :) Anyway, so I'm leaning now towards landing this PR and then trying to keep improving things. One thing which would be nice are some more test cases for calls that generate |
This comment has been minimized.
This comment has been minimized.
|
|
nagisa
force-pushed the
nagisa:mir-calls-2
branch
3 times, most recently
from
e482e81
to
d468ec9
Jan 4, 2016
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis rebased and comments addressed (I hope I didn’t miss any). I added a few more tests as well. |
nagisa
force-pushed the
nagisa:mir-calls-2
branch
2 times, most recently
from
2e9e015
to
9e7ffb6
Jan 5, 2016
This comment has been minimized.
This comment has been minimized.
|
r=me modulo final nits (in particular, the test with graphviz attribute should really be fixed) |
nagisa
force-pushed the
nagisa:mir-calls-2
branch
from
9e7ffb6
to
559c9c5
Jan 5, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
nagisa
added some commits
Dec 14, 2015
nagisa
force-pushed the
nagisa:mir-calls-2
branch
from
559c9c5
to
36b3951
Jan 6, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jan 6, 2016
This comment has been minimized.
This comment has been minimized.
bors
merged commit 36b3951
into
rust-lang:master
Jan 6, 2016
This was referenced Jan 6, 2016
solson
reviewed
Jan 7, 2016
| pub fn destination(&self) -> Option<Lvalue<'tcx>> { | ||
| match *self { | ||
| CallKind::Converging { ref destination, .. } | | ||
| CallKind::ConvergingCleanup { ref destination, .. } => Some(destination.clone()), |
This comment has been minimized.
This comment has been minimized.
solson
Jan 7, 2016
Member
Why clone here instead of returning Option<&Lvalue<'tcx>> and letting the caller decide if it needs to clone?
This comment has been minimized.
This comment has been minimized.
nagisa
Jan 7, 2016
Author
Contributor
There’s two reasons, mostly, I had in mind:
- Cloning
Lvalueis very cheap most of the time (i.e. whenLvalueis not aProjection); - There’s users who want
&mut lvalueand there’s users who want&lvalue. Returning a value allows to make either one easier when pattern matching (refvsref mut).
On the hindsight, I think this might actually be a bug to return destination by value in some cases which I didn’t think about before, thus I’ll submit a patch in a moment making these return a mutable reference instead.
nagisa commentedDec 19, 2015
r? @nikomatsakis
This is a pretty big PR conflating changes to a few different block terminators (Call, DivergingCall, Panic, Resume, Diverge), because they are somewhat closely related.
Each commit has a pretty good description on what is being changed in each commit. The end result is greatly simplified CFG and translation for calls (no success branch if the function is diverging, no cleanup branch if there’s nothing to cleanup etc).
Fixes #30480
Fixes #29767
Partialy solves #29575
Fixes #29573