Repository navigation
Avoid terminator: None in check_enums in split_block - #166243
rust-bors[bot] merged 1 commit into
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
split_blocksplit_block
| for check in finder.into_found_enums() { | ||
| debug!("Inserting enum check"); | ||
| let new_block = split_block(basic_blocks, location); | ||
| let new_block = split_block(basic_blocks, location, source_info); |
There was a problem hiding this comment.
I like the approach of taking split_block at its word. It's really neat that this leaves the MIR in a valid (merely suboptimal) state, so in some sense we don't even have to care if and how the functions called below replace the dummy goto.
But I also feel like "hiding" the current_block.terminator = ... step in the insert_* functions is an artifact of the hold-my-beer approach to CFG rewriting that you're currently improving, so it feels unsatisfactory to leave that in place. Even if the MIR is well-formed in any case, we only bother splitting because every case (except the uninhabited delay_bug one) actually ends up replacing the goto. Or from the other direction, we need to split the block because inserting the check will clobber the old terminator, so we need to do it even if we're inserting checks after the last statement (i.e., the new block is empty).
So I'm tempted to suggest that the insert_* functions could return the new terminator, and putting it into block_data[block].terminator should be done here at the top level. I think that should be fairly trivial to do, despite the different signatures of the insert_* functions. But I'm not sure if it will actually be clearer, and it's tangential to the main point of removing terminator: None.
But it seems prudent to add a comment somewhere around here that notes:
- that the Goto created by block splitting will be replaced in the
insert_*functions, and/or - that the
insert_*functions will blindly overwrite the current block's terminator.
There was a problem hiding this comment.
I've similar feelings about this, yes. I added those comments.
So I'm tempted to suggest that the insert_* functions could return the new terminator,
I was thinking about this as well, but those functions also push new statements, and I feel like it makes sense to keep these related modifications together. It'd be a bit weird if the insert_* function inserted only part of the check into the statements array, but then it delegated assigning the terminator to the parent.
Here the simplest way to avoid it just to honor the `split_block` function name and do a proper split which inserts a goto instead of taking the terminator out. This goto will then be replaced by adding later checks.
9decbb7 to
4847039
Compare
|
@bors r=hanna-kruppe |
…uwer Rollup of 4 pull requests Successful merges: - #165720 (windows: remove redundant prefix parsing in `PathBuf::_push`) - #166243 (Avoid terminator: None in check_enums in `split_block`) - #165434 (Stabilize `char::is_case_ignorable`, `char::is_cased`, and the `titlecase` feature) - #166144 (Rc/Arc::ptr_eq ignore the metadata of all wide pointers)
Rollup merge of #166243 - panstromek:no-terminator-option-in-check-enums-2, r=hanna-kruppe Avoid terminator: None in check_enums in `split_block` Another step towards changing `Option<Terminator>` to `Terminator` in `BasicBlockData`. More info in [this thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/vibe.20check.20-.20removing.20Option.20from.20Terminator/with/637588808). The problem in this place is that there's multiple different checks (decided by branching on `EnumCheckType`), and one of them needs to insert two new blocks, so there's no nice way to group them together into one `push_with` call. So I figured the simplest way to avoid the `None` here is just to honor the `split_block` function name and do a proper split which inserts a goto instead of taking the terminator out. This goto will then be replaced later when adding those checks. r? hanna-kruppe
…uwer Rollup of 4 pull requests Successful merges: - rust-lang/rust#165720 (windows: remove redundant prefix parsing in `PathBuf::_push`) - rust-lang/rust#166243 (Avoid terminator: None in check_enums in `split_block`) - rust-lang/rust#165434 (Stabilize `char::is_case_ignorable`, `char::is_cased`, and the `titlecase` feature) - rust-lang/rust#166144 (Rc/Arc::ptr_eq ignore the metadata of all wide pointers)
…uwer Rollup of 4 pull requests Successful merges: - rust-lang/rust#165720 (windows: remove redundant prefix parsing in `PathBuf::_push`) - rust-lang/rust#166243 (Avoid terminator: None in check_enums in `split_block`) - rust-lang/rust#165434 (Stabilize `char::is_case_ignorable`, `char::is_cased`, and the `titlecase` feature) - rust-lang/rust#166144 (Rc/Arc::ptr_eq ignore the metadata of all wide pointers)
Another step towards changing
Option<Terminator>toTerminatorinBasicBlockData. More info in this thread.The problem in this place is that there's multiple different checks (decided by branching on
EnumCheckType), and one of them needs to insert two new blocks, so there's no nice way to group them together into onepush_withcall.So I figured the simplest way to avoid the
Nonehere is just to honor thesplit_blockfunction name and do a proper split which inserts a goto instead of taking the terminator out. This goto will then be replaced later when adding those checks.r? hanna-kruppe