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

Fix ICE-133117: multiple never-pattern arm doesn't have false_edge_start_block #135409

Merged

Conversation

Shunpoco
Copy link
Contributor

@Shunpoco Shunpoco commented Jan 12, 2025

Fixes #133117 , and close fixes #133063 , fixes #130779

In order to fix ICE-133117, at first I needed to tackle to ICE-133063 (this fixed 130779 as well).

ICE-133063 and ICE-130779

This ICE is caused by those steps:

  1. An arm has or-pattern, and all of the sub-candidates are never-pattern
  2. In that case, all sub-candidates are removed in remove_never_subcandidates(). So the arm (candidate) has no sub-candidate.
  3. In the current implementation, if there is no sub-candidate, the function assigns pre_binding_block into the candidate (here). However, otherwise_block should be assigned to the candidate as well, because the otherwise_block is unwrapped in multiple place (like in lower_match_tree()). As a result, it causes the panic.

I simply added the same block as pre_binding_block into otherwise_block, but I'm wondering if there is a better block to assign to otherwise_block (is it ok to assign the same block into pre_binding and otherwise?)

ICE-133117

This is caused by those steps:

  1. There are two arms, both are or-pattern and each has one match-pair (in the test code, both are (!|!)), and the second arm has a guard.
  2. In match_candidate() for the first arm, it expands the second arm’s sub-candidates as well (here). As a result, the root candidate of the second arm is not evaluated/modified in match_candidate(). So a false_edge_start_block is not assigned to the candidate.
  3. merge_trivial_subcandidates() is called against the candidate for the second arm. It just returns immediately because the candidate has a guard. So a flase_edge_start_block is not assigned to the candidate also in this function.
  4. remove_never_subcandidates() is called against the candidate. Since all sub-candidates are never-pattern. they are removed.
  5. In lower_match_tree(), since there is no sub-candidate for the candidate, the candidate itself is evaluated in visit_leave_rev (here). Because the candidate has no false_edge_start_block, it causes the panic.

So I modified the order of if blocks in merge_trivial_subcandidates() to assign a false_edge_start_block if the candidate doesn't have.

If all subcandidates have never-pattern, the parent candidate should have otherwise_block
because some methods expect the candidate has the block.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
If all subcandidates have never-pattern, we should assign false_edge_start_block to the parent candidate
if it doesn't have. merge_trivial_subcandidates does so, but if the candidate has guard it returns before the assignment.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
@rustbot
Copy link
Collaborator

rustbot commented Jan 12, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Jan 12, 2025
@rust-log-analyzer

This comment has been minimized.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
@Shunpoco Shunpoco marked this pull request as ready for review January 12, 2025 16:22
@compiler-errors
Copy link
Member

cc @Nadrieril

@Nadrieril
Copy link
Member

r? Nadrieril, thanks for doing this I'll have a look when I get a moment

@rustbot rustbot assigned Nadrieril and unassigned oli-obk Jan 13, 2025
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2025
Use enum Void to avoid mistmatched types error

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
- Use enum Void to avoid mismatched types error
- We don't need to use if let to check the ICE

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
The candidate shouldn't have false_edge_start_block if it has sub candidates.
In remove_never_subcandidates(), the false_edge_start_block from the first sub candidte is assigned to a value and the value is later used if all sub candidates are removed and candidate doesn't have false_edge_start_block.
In merge_trivial_subcandidates, I leave the if block which assign a false_edge_start_block into the candidate as before I put this commit since compile panics.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
@Shunpoco
Copy link
Contributor Author

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 22, 2025
@Nadrieril
Copy link
Member

Looks good, thank you for investigating and fixing this :)

@bors r+

@bors
Copy link
Contributor

bors commented Jan 22, 2025

📌 Commit 7275bdf has been approved by Nadrieril

It is now in the queue for this repository.

@bors bors 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 Jan 22, 2025
@Nadrieril
Copy link
Member

@bors rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 22, 2025
…lse-edge-start-block, r=Nadrieril

Fix ICE-133117: multiple never-pattern arm doesn't have false_edge_start_block

Fixes rust-lang#133117 , and close fixes rust-lang#133063 , fixes rust-lang#130779

In order to fix ICE-133117, at first I needed to tackle to ICE-133063 (this fixed 130779 as well).

### ICE-133063 and ICE-130779
This ICE is caused by those steps:
1. An arm has or-pattern, and all of the sub-candidates are never-pattern
2. In that case, all sub-candidates are removed in remove_never_subcandidates(). So the arm (candidate) has no sub-candidate.
3. In the current implementation, if there is no sub-candidate, the function assigns `pre_binding_block` into the candidate ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L2002-L2004)). However, otherwise_block should be assigned to the candidate as well, because the otherwise_block is unwrapped in multiple place (like in lower_match_tree()). As a result, it causes the panic.

I simply added the same block as pre_binding_block into otherwise_block, but I'm wondering if there is a better block to assign to otherwise_block (is it ok to assign the same block into pre_binding and otherwise?)

### ICE-133117
This is caused by those steps:
1. There are two arms, both are or-pattern and each has one match-pair (in the test code, both are `(!|!)`), and the second arm has a guard.
2. In match_candidate() for the first arm, it expands the second arm’s sub-candidates as well ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L1800-L1805)). As a result, the root candidate of the second arm is not evaluated/modified in match_candidate(). So a false_edge_start_block is not assigned to the candidate.
3. merge_trivial_subcandidates() is called against the candidate for the second arm. It just returns immediately because the candidate has a guard. So a flase_edge_start_block is not assigned to the candidate also in this function.
4. remove_never_subcandidates() is called against the candidate. Since all sub-candidates are never-pattern. they are removed.
5. In lower_match_tree(), since there is no sub-candidate for the candidate, the candidate itself is evaluated in visit_leave_rev ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L1532)). Because the candidate has no false_edge_start_block, it causes the panic.

So I modified the order of if blocks in merge_trivial_subcandidates() to assign a false_edge_start_block if the candidate doesn't have.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 22, 2025
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#132983 (Edit dangling pointers )
 - rust-lang#133154 (Reword resolve errors caused by likely missing crate in dep tree)
 - rust-lang#135409 (Fix ICE-133117: multiple never-pattern arm doesn't have false_edge_start_block)
 - rust-lang#135557 (Point at invalid utf-8 span on user's source code)
 - rust-lang#135596 (Properly note when query stack is being cut off)
 - rust-lang#135794 (Detect missing fields with default values and suggest `..`)
 - rust-lang#135814 (ci: use ghcr buildkit image)
 - rust-lang#135826 (Misc. `rustc_resolve` cleanups)
 - rust-lang#135837 (Remove test panic from File::open)
 - rust-lang#135856 (Library: Finalize dyn compatibility renaming)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 22, 2025
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#132983 (Edit dangling pointers )
 - rust-lang#135409 (Fix ICE-133117: multiple never-pattern arm doesn't have false_edge_start_block)
 - rust-lang#135557 (Point at invalid utf-8 span on user's source code)
 - rust-lang#135596 (Properly note when query stack is being cut off)
 - rust-lang#135794 (Detect missing fields with default values and suggest `..`)
 - rust-lang#135814 (ci: use ghcr buildkit image)
 - rust-lang#135826 (Misc. `rustc_resolve` cleanups)
 - rust-lang#135837 (Remove test panic from File::open)
 - rust-lang#135856 (Library: Finalize dyn compatibility renaming)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f875983 into rust-lang:master Jan 23, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 23, 2025
@Shunpoco Shunpoco deleted the issue-133117-ICE-never-false-edge-start-block branch January 23, 2025 01:07
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
7 participants