rust/src
bors b520af6fd5 Auto merge of #65646 - Amanieu:foreign-exceptions, r=nikomatsakis
Allow foreign exceptions to unwind through Rust code and Rust panics to unwind through FFI

This PR fixes interactions between Rust panics and foreign (mainly C++) exceptions.

C++ exceptions (and other FFI exceptions) can now safely unwind through Rust code:
- The FFI function causing the unwind must be marked with `#[unwind(allowed)]`. If this is not the case then LLVM may optimize landing pads away with the assumption that they are unreachable.
- Drop code will be executed as the exception unwinds through the stack, as with a Rust panic.
- `catch_unwind` will *not* catch the exception, instead the exception will silently continue unwinding past it.

Rust panics can now safely unwind through C++ code:
- C++ destructors will be called as the stack unwinds.
- The Rust panic can only be caught with `catch (...)`, after which it can be either rethrown or discarded.
- C++ cannot name the type of the Rust exception object used for unwinding, which means that it can't be caught explicitly or have its contents inspected.

Tests have been added to ensure all of the above works correctly.

Some notes about non-C++ exceptions:
- `pthread_cancel` and `pthread_exit` use unwinding on glibc. This has the same behavior as a C++ exception: destructors are run but it cannot be caught by `catch_unwind`.
- `longjmp` on Windows is implemented using unwinding. Destructors are run on MSVC, but not on MinGW. In both cases the unwind cannot be caught by `catch_unwind`.
- As with C++ exceptions, you need to mark the relevant FFI functions with `#[unwind(allowed)]`, otherwise LLVM will optimize out the destructors since they seem unreachable.

I haven't updated any of the documentation, so officially unwinding through FFI is still UB. However this is a step towards making it well-defined.

Fixes #65441

cc @gnzlbg
r? @alexcrichton
2019-11-03 18:36:59 +00:00
..
bootstrap Rollup merge of #65274 - pietroalbini:ci-upload-toolstate, r=alexcrichton 2019-10-31 02:54:04 +01:00
build_helper show up some extra info when t!() fails 2019-10-17 17:01:49 +08:00
ci Rollup merge of #65955 - pietroalbini:master-revert-msys2-hack, r=Mark-Simulacrum 2019-10-31 02:54:08 +01:00
doc Make Emscripten unwinding use a valid type_info 2019-11-03 14:04:15 +00:00
etc
liballoc Auto merge of #65091 - sekineh:into-iter-sorted, r=KodrAus 2019-10-31 15:15:53 +00:00
libarena
libcore Auto merge of #63810 - oli-obk:const_offset_from, r=RalfJung,nikic 2019-11-02 22:26:54 +00:00
libfmt_macros
libgraphviz
libpanic_abort redesign of the interface to the unikernel HermitCore 2019-10-06 15:26:14 +00:00
libpanic_unwind Make Emscripten unwinding use a valid type_info 2019-11-03 14:04:15 +00:00
libproc_macro proc_macro: don't use Rust ABI fn pointers in a C ABI fn signature. 2019-10-28 20:34:59 +02:00
libprofiler_builtins
librustc Make Emscripten unwinding use a valid type_info 2019-11-03 14:04:15 +00:00
librustc_apfloat Update bitflags 2019-10-25 23:26:27 +01:00
librustc_asan
librustc_codegen_llvm Make Emscripten unwinding use a valid type_info 2019-11-03 14:04:15 +00:00
librustc_codegen_ssa Rollup merge of #66018 - pnkfelix:issue-64872-revert-64324, r=alexcrichton 2019-11-01 11:20:29 -07:00
librustc_codegen_utils rustc: Add a convenience alias for dyn MetadataLoader + Sync 2019-10-24 20:51:33 +03:00
librustc_data_structures Rollup merge of #65997 - spastorino:fix-init_locking-rustdoc, r=Mark-Simulacrum 2019-11-01 11:20:25 -07:00
librustc_driver Remove lint callback from driver 2019-10-25 19:27:57 -04:00
librustc_errors Auto merge of #65827 - AnthonyMikh:out_of_the_loop, r=estebank 2019-11-03 11:51:44 +00:00
librustc_fs_util
librustc_incremental Rollup merge of #65470 - traxys:fix_65401, r=michaelwoerister 2019-11-01 11:20:09 -07:00
librustc_index doc: make BitSet intro more short 2019-10-18 01:16:30 +02:00
librustc_interface rustc, rustc_passes: don't depend on syntax_expand. 2019-10-27 17:05:57 +01:00
librustc_lexer librustc_lexer: Enhance documentation 2019-10-27 20:08:08 +03:00
librustc_lint Rollup merge of #65914 - estebank:type-alias-bounds-sugg, r=davidtwco 2019-11-01 11:20:15 -07:00
librustc_llvm
librustc_lsan
librustc_macros Rollup merge of #65176 - nnethercote:rm-query-macros, r=michaelwoerister 2019-10-08 15:45:32 +02:00
librustc_metadata Rollup merge of #66018 - pnkfelix:issue-64872-revert-64324, r=alexcrichton 2019-11-01 11:20:29 -07:00
librustc_mir Auto merge of #63810 - oli-obk:const_offset_from, r=RalfJung,nikic 2019-11-02 22:26:54 +00:00
librustc_msan
librustc_passes Rollup merge of #65792 - Centril:split-syntax-2, r=petrochenkov 2019-10-28 04:53:07 +01:00
librustc_plugin rustc_metadata: Move some code around 2019-10-24 20:51:33 +03:00
librustc_privacy Rollup merge of #65252 - petrochenkov:deriveholders2, r=matthewjasper 2019-10-19 07:10:04 +02:00
librustc_resolve Add long error explanation for E0578 2019-10-31 14:27:16 +01:00
librustc_save_analysis save-analysis: Account for async desugaring in async fn return types 2019-10-29 16:25:37 +01:00
librustc_target Rollup merge of #65832 - tlively:emscripten-exception-handling, r=alexcrichton 2019-10-29 12:01:38 -07:00
librustc_traits Rename ConstValue::Infer(InferConst::Canonical(..)) to ConstValue::Bound(..) 2019-10-21 20:50:41 +01:00
librustc_tsan
librustc_typeck Auto merge of #63810 - oli-obk:const_offset_from, r=RalfJung,nikic 2019-11-02 22:26:54 +00:00
librustdoc rustdoc: Resolve module-level doc references more locally 2019-10-31 07:49:54 +00:00
libserialize Remove unnecessary Hash bounds from various types. 2019-10-21 13:48:20 +11:00
libstd Auto merge of #65429 - Timmmm:withoptions, r=Mark-Simulacrum 2019-11-02 18:22:32 +00:00
libsyntax Auto merge of #66004 - eddyb:revert-early-gate, r=petrochenkov 2019-11-02 10:48:59 +00:00
libsyntax_expand rustc, rustc_passes: don't depend on syntax_expand. 2019-10-27 17:05:57 +01:00
libsyntax_ext rustc, rustc_passes: don't depend on syntax_expand. 2019-10-27 17:05:57 +01:00
libsyntax_pos Rollup merge of #65902 - gilescope:issue62570, r=estebank 2019-11-01 11:20:14 -07:00
libterm
libtest Rollup merge of #65898 - hermitcore:rusty-hermit, r=kennytm 2019-10-29 12:01:41 -07:00
libunwind Allow foreign exceptions to unwind through Rust code 2019-11-03 14:03:21 +00:00
llvm-project@14a3b12307 Update LLVM for Emscripten exception handling support 2019-10-08 13:07:27 -07:00
rtstartup
rustc
rustllvm
stdarch@e0ab2c165a
test Auto merge of #65646 - Amanieu:foreign-exceptions, r=nikomatsakis 2019-11-03 18:36:59 +00:00
tools Validate error patterns and error annotation in ui tests when present 2019-11-03 10:20:11 +01:00
README.md remove the last remaining READMEs 2019-10-24 13:32:54 -05:00
stage0.txt

This directory contains the source code of the rust project, including:

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc guide.