Skip to content

Avoid terminator: None in check_enums in split_block - #166243

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
panstromek:no-terminator-option-in-check-enums-2
Nov 23, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
panstromek:no-terminator-option-in-check-enums-2

Conversation

@panstromek

@panstromek panstromek commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Another step towards changing Option<Terminator> to Terminator in BasicBlockData. 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 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

@rustbot

rustbot commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2026
@panstromek panstromek changed the title ref: avoid terminator: None in check_enums in split_block Avoid terminator: None in check_enums in split_block Nov 20, 2026

@hanna-kruppe hanna-kruppe left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

r=me with some comment added

View changes since this review

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.
@panstromek
panstromek force-pushed the no-terminator-option-in-check-enums-2 branch from 9decbb7 to 4847039 Compare November 22, 2026 17:06
@panstromek

Copy link
Copy Markdown
Contributor Author

@bors r=hanna-kruppe

@rust-bors

rust-bors Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4847039 has been tentatively approved by hanna-kruppe

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot 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 Nov 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 22, 2026
…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)
@rust-bors
rust-bors Bot merged commit c45592b into rust-lang:main Nov 23, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 23, 2026
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
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Nov 23, 2026
…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)
github-merge-queue Bot pushed a commit to rust-lang/miri that referenced this pull request Nov 23, 2026
…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)
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. 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.

3 participants