@@ -301,11 +301,12 @@ Our reasons for preferring the current proposal are:
301
301
Rust to have undefined behavior under ` panic=abort ` , whereas the current
302
302
proposal does not permit the ` panic=abort ` runtime to introduce undefined
303
303
behavior to a program that is well-defined under ` panic=unwind ` .
304
- * This optimization could be made available with a single ABI by means of an
305
- annotation indicating that a function cannot unwind (similar to C++'s
306
- ` noexcept ` ). However, Rust does not yet support annotations for function
307
- pointers, so until that feature is added, such an annotation could not be
308
- applied to function pointers.
304
+ * This optimization could be made available with a single ABI by means of a
305
+ function attribute indicating that a function cannot unwind (similar to C++'s
306
+ ` noexcept ` ). Such attributes [ are already available in nightly
307
+ Rust] [ nightly-attributes ] . However, Rust does not yet support attributes
308
+ for function pointers, so until that feature is added, there would be no
309
+ way to indicate whether function pointers unwind using an attribute.
309
310
* This design has simpler forward compatibility with alternate ` panic! `
310
311
implementations. Any well-defined cross-language unwinding will require shims
311
312
to translate between the Rust unwinding mechanism and the natively provided
@@ -388,18 +389,37 @@ foreign exceptions as well. In the current proposal, though, such foreign
388
389
exception support is not enabled by default with ` panic=unwind ` but requires
389
390
the new ` "C unwind" ` ABI.
390
391
391
- ## Attributes on nightly Rust
392
+ ## Attributes on nightly Rust and prior RFCs
393
+ [ nightly-attributes ] : #attributes-on-nightly-rust-and-prior-rfcs
392
394
393
395
Currently, nightly Rust provides attributes, ` #[unwind(allowed)] ` and
394
396
` #[unwind(abort)] ` , for making the behavior of ` panic ` crossing a ` "C" ` ABI
395
- boundary well defined.
396
- <!-- TODO explain why new ABI string is preferable to attributes -->
397
+ boundary well defined. Two previous RFCs, [ #2699 ] [ rfc-2699 ] and
398
+ [ #2753 ] [ rfc-2753 ] , attempted to stabilize these or similar attributes.
399
+
400
+ The attribute approach was deemed insufficient:
401
+
402
+ * Currently, Rust does not support attributes on function pointers. This may
403
+ change in the future, but until then, attributes cannot provide any way to
404
+ differentiate function pointers that may unwind from those that are
405
+ guaranteed not to. Assuming that no function pointers may unwind is not
406
+ viable, because that severly limits the utility of cross-FFI unwinding.
407
+ Conversely, assuming that all ` extern "C" ` function pointers may unwind is
408
+ inconsistent with the no-unwind default for ` extern "C" ` functions.
409
+ * The existence of a compatible unwind mechanism on both sides of a function
410
+ invocation boundary is part of the binary interface for that invocation, so
411
+ the ABI string is a more appropriate part of the language syntax than
412
+ function attributes to indicate that unwinding may occur.
413
+ * The ability of a function to unwind must be part of the type system to ensure
414
+ that callers that cannot unwind don't invoke functions that can unwind.
415
+ Although attributes are sometimes part of a function's type, a function's ABI
416
+ string is always part of its type, so we are not introducing anything new to
417
+ the type system.
397
418
398
- ## Prior RFCs and other discussions
399
-
400
- There were two previous RFCs, [ #2699 ] [ rfc-2699 ] and [ #2753 ] [ rfc-2753 ] , that
401
- attempted to introduce a well-defined way for uwnding to cross FFI boundaries.
419
+ [ rfc-2699 ] : https://github.com/rust-lang/rfcs/pull/2699
420
+ [ rfc-2753 ] : https://github.com/rust-lang/rfcs/pull/2753
402
421
422
+ ## Other discussions
403
423
<!-- TODO other discussions:
404
424
Tickets:
405
425
* https://github.com/rust-lang/rust/issues/58794
@@ -411,9 +431,6 @@ Discourse:
411
431
https://internals.rust-lang.org/t/unwinding-through-ffi-after-rust-1-33/9521?u=batmanaod
412
432
-->
413
433
414
- [ rfc-2699 ] : https://github.com/rust-lang/rfcs/pull/2699
415
- [ rfc-2753 ] : https://github.com/rust-lang/rfcs/pull/2573
416
-
417
434
# Unresolved questions
418
435
[ unresolved-questions ] : #unresolved-questions
419
436
0 commit comments