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 when there is a continue in a labeled block #121682

Closed
wants to merge 4 commits into from

Conversation

SarthakSingh31
Copy link
Contributor

@SarthakSingh31 SarthakSingh31 commented Feb 27, 2024

Fixes #113379
Fixes #121623

r? @matthiaskrgr

@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 Feb 27, 2024
@compiler-errors
Copy link
Member

r? compiler

This needs an explanation for why it's correct. I'm also somewhat concerned that this could affect good-path code.

I'd prefer if we did something else, like lower continue to hir::ExprKind::Error when it's in a scope that doesn't allow breaks.

@rustbot rustbot assigned cjgillot and unassigned matthiaskrgr Feb 27, 2024
@SarthakSingh31 SarthakSingh31 changed the title Add continue livenodes in liveness check for blocks Fix ICE when there is a continue in a labeled block Mar 1, 2024
@SarthakSingh31
Copy link
Contributor Author

@compiler-errors I updated the pr, now when the ast is being lowered it checks if the label belongs to a loop and if it does not it will lower to an error.
Should I remove this now redundant check:

if let Node::Block(block) = self.tcx.hir_node(loop_id) {
self.sess.dcx().emit_err(ContinueLabeledBlock {
span: e.span,
block_span: block.span,
});
}

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 5, 2024

☔ The latest upstream changes (presumably #121780) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

I'm surprised we weren't emitting such an error anywhere before. What about break on non-loop blocks?

@@ -279,7 +280,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ExprKind::Break(self.lower_jump_destination(e.id, *opt_label), opt_expr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do the same thing with break?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait, maybe we are not doing it. This just assumes that the label is a loop https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast_lowering/src/expr.rs#L1446-L1448

compiler/rustc_ast_lowering/src/expr.rs Outdated Show resolved Hide resolved
@cjgillot cjgillot 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 Mar 10, 2024
@SarthakSingh31
Copy link
Contributor Author

SarthakSingh31 commented Mar 11, 2024

I'm surprised we weren't emitting such an error anywhere before.

@cjgillot We were emitting this error but just much later. #121682 (comment)

As asked #121682 (comment) I moved the error to when the ast is lowered.

I would also like your opinion on if it would be better to lower it to a hir::ExprKind::Continue but the destination has a hir::LoopIdError of something like label does not refer to a loop.

@SarthakSingh31
Copy link
Contributor Author

@rustbot label -S-waiting-on-author +S-waiting-on-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 Mar 11, 2024
@cjgillot
Copy link
Contributor

cjgillot commented Apr 7, 2024

I would also like your opinion on if it would be better to lower it to a hir::ExprKind::Continue but the destination has a hir::LoopIdError of something like label does not refer to a loop.

Using ExprKind::Err is fine, that's what it's meant to be.

For break, I think some uniformity would be better. If is allows us to remove some error handling code somewhere else, that's all the better.

@bors
Copy link
Contributor

bors commented Apr 16, 2024

☔ The latest upstream changes (presumably #123468) made this pull request unmergeable. Please resolve the merge conflicts.

@cjgillot cjgillot 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 Apr 20, 2024
@oskgo
Copy link
Contributor

oskgo commented Jul 11, 2024

@SarthakSingh31 any updates on this? thanks

@SarthakSingh31
Copy link
Contributor Author

@oskgo I had forgotten about this PR, going to try to fix it up in the next few days.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@SarthakSingh31
Copy link
Contributor Author

@cjgillot I have removed the redundant error. This should be ready to merge.

This does not change the break code as the changes made here check if a label points to a block or a loop. This is important for continue but for break it does not matter in this case.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jul 29, 2024

☔ The latest upstream changes (presumably #125443) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Aug 4, 2024

☔ The latest upstream changes (presumably #128614) made this pull request unmergeable. Please resolve the merge conflicts.

@cjgillot
Copy link
Contributor

r=me after rebase

@alex-semenyuk
Copy link
Member

@SarthakSingh31
From wg-triage. Could you please do rebase? it seems no unhandled comments here, right?

@alex-semenyuk
Copy link
Member

@SarthakSingh31
From wg-triage. Closed this PR due to inactivity. Feel free to reopen or raised new one. Thanks for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
9 participants