Uh oh!
There was an error while loading. Please reload this page.
Add #[cfg(panic = '...')] - #74754
Conversation
rust-highfive
commented
Jul 25, 2020
(rust_highfive has picked a reviewer for you, use r? to override) |
I'd like to see a test verifying that |
There was a problem hiding this comment.
Please use sym::panic and modify PanicStrategy to also provide a pre-interned symbol (code is here:
rust/src/librustc_target/spec/mod.rs
Lines 171 to 176 in 584e83d
sym::abort and sym::unwind are already available.Edit: You probably want a desc_symbol method or so.
Uh oh!
There was an error while loading. Please reload this page.
nikomatsakis
commented
Jul 30, 2020
Nominating for discussion in a @rust-lang/lang meeting regarding the amount of process required, but I tend to agree this is one of those "no RFC required" sort of changes. |
davidhewitt
commented
Jul 31, 2020
Thanks for all the reviews - I plan to find time to update this PR over the weekend 👍 |
joshtriplett
commented
Jul 31, 2020
This looks great! I know that some crates depend on the panic strategy, and will appreciate being able to use this with |
bcfb423 to
5c11e6bComparedavidhewitt
commented
Aug 2, 2020
I had a go at writing a ui test with This speedbump is why I ended up with the ui test I did. Maybe there's a way to work around it? In lieu of adding such a test I've also sprinkled this |
joshtriplett
commented
Aug 3, 2020
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Mark-Simulacrum
commented
Aug 3, 2020
One question I have -- should we be documenting this as an extensible set, i.e., I can't think of other panic implementation strategies that would be reasonable for code to gate on, but I'm not very familiar with the possibilities here. One option, if we're concerned about this, is to designate aborting as "special" (since it is the immediate termination option) and only add that (or just leave unwind unstable indefinitely). |
joshtriplett
commented
Aug 4, 2020
That's an excellent point. I do think this is an extensible set. We should discourage the assumption that there are only two panic strategies. @davidhewitt Could you please use |
Mark-Simulacrum
commented
Aug 4, 2020
I personally suspect that no matter what we do, adding this basically stabilizes that there's only two panic strategies -- there is all but guaranteed to be downstream breakage in the wild no matter how we go about stabilizing. This also increases the chances of crates saying "I only work with panic = abort" or so, whereas today the lack of this cfg means that it is pretty hard to make that call as a crate author (unless in some very specialized domain, where unwinding is never permitted, but those seem like major exceptions). Looking at the use cases given so far (though I recall @joshtriplett mentioning others, maybe you can elaborate?): #74301 notes #73670 (comment) discusses a limitation of our compiletest infrastructure, rather than a language limitation. It does seem true that some tests / programs require panic=abort to be sound (or panic=unwind to work), but this cfg seems like the wrong way to go about that. Like mentioned around the |
@rfcbot concern breakage-if-we-add-more-unwind-strategies I'm registering this concern to represent @Mark-Simulacrum's excellent point that this likely means that we would "de facto" break code when/if we add new unwind strategies in the future. |
nikomatsakis
commented
Aug 4, 2020
I guess a reasonable question then is whether we can address known use cases another way and/or how much we care about that. Another question: One could imagine exposing the "panic strategy" as something that can be dynamically tested (perhaps with a |
davidhewitt
commented
Aug 4, 2020
I take this point though am not convinced it matches precedent. We already have extensible If the concern is that stabilizing this flag allows crates to build "bad habits" regarding panic compatibility, I'm willing to withdraw this PR and work towards other solutions. So far the only motivations that I've seen personally are when trying to write tests. As such we could solve this differently with patches to the test frameworks (as noted e.g. in #74301). Though others may have legitimate non-test uses. As well as Josh above, @tmandry spoke of Fuschia adding this cfg in via cmdline. Perhaps they are also willing to elaborate? |
I do feel like this has the feel of "people can misuse the feature", which is sometimes a valid concern, but often just an unavoidable fact of life. I'm not sure what a better solution is really. |
ecstatic-morse
commented
Aug 5, 2020
@davidhewitt BTW, have you tried a |
tmandry
commented
Aug 6, 2020
Custom test frameworks are a major use of the feature. As it stands, libtest running in the process-per-test mode that @Mark-Simulacrum mentioned relies on the compiler activating a different part of its interface when panic=abort. (This would be the case even if we stabilized it and made it the default for panic=abort, which has been discussed.) Other test frameworks cannot rely on this level of integration with the compiler. Another use I've had on Fuchsia is making a scoped task abstraction that always killed subprocesses when a guard is dropped or your process panics or exits. This was also for tests, incidentally. When
The most important information you'd want to know is
You may also want to know "Is any other code in other threads going to run?", but the answer is almost always "in general yes" and this makes writing teardown hooks tricky. I don't know what other panic strategies are on the table exactly, but if making
I do feel that this belongs in the realm of compile-time knowledge, especially given how pervasive the panic strategy is and the potential impact on code speed and size. One could argue that optimizations can fix that, but then you'd have compile time concerns. It is tempting to think of a new conditional compilation mechanism that allows for things like |
We discussed this in the @rust-lang/lang meeting today. (Note: @nikomatsakis, who raised the concern, was not present, but @Mark-Simulacrum, who the concern was raised on behalf of, was.) We agreed that while it ispossible for code that uses @nikomatsakis, @Mark-Simulacrum, thoughts? |
nikomatsakis
commented
Aug 17, 2020
@rfcbot resolve breakage-if-we-add-more-unwind-strategies I'm persuaded by the above logic. =) |
davidhewitt
commented
Oct 13, 2020
CI all green. @ecstatic-morse this is now ready for another round of review (and hopefully to merge)! Thanks again for the reviews and advice. |
bors
commented
Oct 17, 2020
☔ The latest upstream changes (presumably #77124) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels: |
ecstatic-morse
commented
Oct 18, 2020
Sorry for the delay @davidhewitt. I wasn't able to do any Rust stuff this week. r=me after a rebase ( @bors delegate+ rollup |
bors
commented
Oct 18, 2020
✌️ @davidhewitt can now approve this pull request |
davidhewitt
commented
Oct 24, 2020
@bors r=ecstatic-morse |
bors
commented
Oct 24, 2020
📌 Commit 3e6acd8 has been approved by |
jonas-schievink
commented
Oct 24, 2020
@bors r- failed in #78328 (comment) |
davidhewitt
commented
Oct 26, 2020
Sorry about that; I've pushed a commit which I've verified fixes the build on the wasm target which failed in the merge pipeline. @ecstatic-morse can I squash and r+ again? |
bors
commented
Oct 28, 2020
☔ The latest upstream changes (presumably #78458) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels: |
davidhewitt
commented
Nov 9, 2020
I've rebased and squashed; I'm going to assume it's okay for me to r+ again. @bors r=ecstatic-morse |
bors
commented
Nov 9, 2020
📌 Commit 8d43b3c has been approved by |
Rollup of 12 pull requests Successful merges: - rust-lang#74754 (Add `#[cfg(panic = '...')]`) - rust-lang#76468 (Improve lifetime name annotations for closures & async functions) - rust-lang#77016 (Test clippy on PR CI on changes) - rust-lang#78480 (BTreeMap: fix pointer provenance rules) - rust-lang#78502 (Update Chalk to 0.36.0) - rust-lang#78513 (Infer the default host target from the host toolchain if possible) - rust-lang#78566 (Enable LLVM Polly via llvm-args.) - rust-lang#78580 (inliner: Break inlining cycles) - rust-lang#78710 (rustc_ast: Do not panic by default when visiting macro calls) - rust-lang#78746 (Demote i686-unknown-freebsd to tier 2 compiler target) - rust-lang#78830 (fix `super_visit_with` for `Terminator`) - rust-lang#78844 (Monomorphize a type argument of size-of operation during codegen) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This PR adds conditional compilation according to the panic strategy.
I've come across a need for a flag like this a couple of times while writing tests: #74301 , #73670 (comment)
I'm not sure if I need to add a feature gate for this flag?