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 coroutine validation for mixed panic strategy #118422

Merged
merged 1 commit into from
Nov 29, 2023
Merged

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Nov 28, 2023

Validation introduced in #113124 allows UnwindAction::Continue and TerminatorKind::Resume to occur only in functions with ABI that can unwind. The function ABI depends on the panic strategy, which can vary across crates.

Usually MIR is built and validated in the same crate. The coroutine drop glue thus far was an exception. As a result validation could fail when mixing different panic strategies.

Avoid the problem by executing AbortUnwindingCalls along with the validation.

Fixes #116953.

Validation introduced in rust-lang#113124 allows UnwindAction::Continue and
TerminatorKind::Resume to occur only in functions with ABI that can
unwind. The function ABI depends on the panic strategy, which can vary
across crates.

Usually MIR is built and validated in the same crate. The coroutine drop
glue thus far was an exception. As a result validation could fail when
mixing different panic strategies.

Avoid the problem by executing AbortUnwindingCalls along with the
validation.
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2023

r? @compiler-errors

(rustbot has picked a reviewer for you, use r? to override)

@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 28, 2023
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

pm::run_passes(
tcx,
&mut body,
&[],
&[
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that generator drop shims will inherit the panic strategy of the crate that they're being monomorphized in, rather than the crate that they're coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

One could also try to move everything in other direction. That is, move validation from shim building to state transform, but unfortunately this introduces query cycle at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

Huh. Do you know whether other shims default to definition-crate or mono-crate for their panic strategy? This inconsistency seems important to iron out, I feel? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To place this into context. While the mixed builds are allowed, the final strategy in that case is abort. The motivating use case being the standard library pre-built with unwind strategy, where the end user selects between unwind and abort.

The other shims, like the one here, are constructed using the strategy of the crate that requests the MIR. Usually, MIR would be requested at the monomorphization time, but it is an implementation detail, given that optimization like MIR inlining can request it earlier.

Any differences here should be at best quality of implementation kind.

@compiler-errors
Copy link
Member

@tmiasko: Thanks, that last comment was very illuminating. I think my worries are settled now.

@bors r+

@bors
Copy link
Contributor

bors commented Nov 29, 2023

📌 Commit 5161b22 has been approved by compiler-errors

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 Nov 29, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 29, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#116839 (Implement thread parking for xous)
 - rust-lang#118265 (remove the memcpy-on-equal-ptrs assumption)
 - rust-lang#118269 (Unify `TraitRefs` and `PolyTraitRefs` in `ValuePairs`)
 - rust-lang#118394 (Remove HIR opkinds)
 - rust-lang#118398 (Add proper cfgs in std)
 - rust-lang#118419 (Eagerly return `ExprKind::Err` on `yield`/`await` in wrong coroutine context)
 - rust-lang#118422 (Fix coroutine validation for mixed panic strategy)

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

Rollup of 7 pull requests

Successful merges:

 - rust-lang#116839 (Implement thread parking for xous)
 - rust-lang#118265 (remove the memcpy-on-equal-ptrs assumption)
 - rust-lang#118269 (Unify `TraitRefs` and `PolyTraitRefs` in `ValuePairs`)
 - rust-lang#118394 (Remove HIR opkinds)
 - rust-lang#118398 (Add proper cfgs in std)
 - rust-lang#118419 (Eagerly return `ExprKind::Err` on `yield`/`await` in wrong coroutine context)
 - rust-lang#118422 (Fix coroutine validation for mixed panic strategy)

r? `@ghost`
`@rustbot` modify labels: rollup
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 29, 2023
Rollup merge of rust-lang#118422 - tmiasko:mix, r=compiler-errors

Fix coroutine validation for mixed panic strategy

Validation introduced in rust-lang#113124 allows `UnwindAction::Continue` and `TerminatorKind::Resume` to occur only in functions with ABI that can unwind. The function ABI depends on the panic strategy, which can vary across crates.

Usually MIR is built and validated in the same crate. The coroutine drop glue thus far was an exception. As a result validation could fail when mixing different panic strategies.

Avoid the problem by executing `AbortUnwindingCalls` along with the validation.

Fixes rust-lang#116953.
@bors bors merged commit e8d0c56 into rust-lang:master Nov 29, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 29, 2023
@tmiasko tmiasko deleted the mix branch November 29, 2023 12:02
@apiraino
Copy link
Contributor

Going to nominate for stable backport since this fixes a (supposedly) P-high regression on stable. Probably this patch alone doesn't warrant a dot release but could be evaluated in a dot release scenario.

@rustbot label +stable-nominated

@rustbot rustbot added the stable-nominated Nominated for backporting to the compiler in the stable channel. label Nov 29, 2023
@wesleywiser wesleywiser added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 30, 2023
@apiraino
Copy link
Contributor

apiraino commented Nov 30, 2023

Stable backport declined as per compiler team on Zulip (the impact of code compiled with cargo rustc -- -C panic=abort doesn't seem a common case).

A beta backport was also suggested and seemed to receive more consensus.

@rustbot label -stable-nominated +beta-accepted

@rustbot rustbot added beta-accepted Accepted for backporting to the compiler in the beta channel. and removed stable-nominated Nominated for backporting to the compiler in the stable channel. labels Nov 30, 2023
@cuviper cuviper mentioned this pull request Dec 1, 2023
@cuviper cuviper modified the milestones: 1.76.0, 1.75.0 Dec 1, 2023
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Dec 1, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 1, 2023
[beta] backports

- Build pre-coroutine-transform coroutine body rust-lang#117686
- Fix coroutine validation for mixed panic strategy rust-lang#118422
- ConstProp: Remove const when rvalue check fails. rust-lang#118426
- Dispose llvm::TargetMachines prior to llvm::Context being disposed rust-lang#118464

r? ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. 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.

panic=abort with no_mangle function causes monomorphisation ICE
7 participants