Permitting "foreign" languages to dispose of Rust panics
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
It is currently undefined behavior for a "foreign" language (such as C++) to catch a Rust panic, regardless of what the "foreign" code then does with the exception. That is, either disposing of or rethrowing the panic are both unconditional undefined behavior.
Permitting other languages to rethrow the panic, and permitting them to dispose of the panic, are separate "features" Rust could provide. This issue is only for safe disposal.
Note that Rust can document a function that a different runtime must call in order to safely dispose of a Rust panic. Per @chorman0773, Itanium specifies this cross-language mechanism this way:
[the runtime catching the exception is] supposed to call the
unwind_cleanupfunction stored in the_Unwind_Exceptionstruct with_URC_FOREIGN_EXCEPTION_CAUGHT.
Currently, the main thing that the Rust runtime would need to do when notified that a panic has been disposed of by a foreign runtime is to decrement the panic count. @bjorn3, @nbdd0121, @workingjubilee, and @Amanieu may have additional context on what would be required for foreign languages to safely dispose of Rust panics.
Original discussion: https://github.com/rust-lang/reference/pull/1226#discussion_r1739926327
CC @rust-lang/libs-api ; CC @rust-lang/lang
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Rust Reference discussion and the issue's _Unwind_Exception cleanup description. Investigate how Rust tracks panic counts and what foreign runtimes must call when disposing of a panic. Done means defining and implementing safe disposal without including foreign-language rethrowing, with tests or documentation covering the supported mechanism.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100