-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Support for native WASM exceptions #111322
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @b-naber (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
r? rust-lang/compiler |
@bjorn3 Is your review complete? There are some conflicts now and I have to rebase, so I hope this does not interfere? |
My review is done. Rebasing is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay in reviewing, this looks good to me.
Is it possible to add a test for this? Something simple with It's fine if it isn't, then r=me. |
It's worth mentioning that the Exception Handling proposal is only at Phase 3, so it is not standardized yet. It's useful to experiment with it, but the semantics and binary encoding are not officially considered stable yet, so users should ideally be made aware that programs they build using this feature now may not work in the future. |
Hi @davidtwco , I have some tests locally, but they require a more recent nodejs version than we use in our test system. I'd like to add tests in a follow-up PR, or is this a bad idea? |
@sunfishcode What do you propose? Currently, it is only possible to use wasm-exception-handling if you add some command line flags, so users have to know what they are doing. (It is not documented, outside of this PR) When this PR is merged I would work on support in std and maybe add some documentation. That would be a good place for this warning. Or do you have something else in mind? |
@mirkootter Yes, the documentation would be a good place to mention this. |
A follow-up is fine. |
@bors r+ |
Support for native WASM exceptions ### Motivation Currently, rustc does not support native WASM exceptions. It does support JavaScript based exceptions for the wasm32-emscripten-target, but this requires back&forth with javascript for many calls, which is very slow. Native wasm support for exceptions is quite common: Clang+LLVM implemented them years ago, and all major browsers support them by now. They enable zero-cost exceptions, at least with regard to runtime-performance-cost. They may increase startup-time and code size, though. ### Important: This PR does not change default behaviour Exceptions usually add a lot of code in form of unwinding blocks, increasing the binary size. Most users probably do not want that, especially which regard to web development. Therefore, wasm exceptions play a similar role as WASM-threads: rustc should support them, like clang does, but users who want to use it have to use some command-line magic like rustflags to opt in. ### What does this PR do? As stated above, the default behaviour is not changed. It is already possible to opt-in into wasm exceptions using the command line. Unfortunately, the LLVM IR is invalid and the LLVM backend crashes. ``` rustc <sourcefile> --target wasm32-unknown-unknown -C panic=unwind -C llvm-args=-wasm-enable-eh -C target-feature=+exception-handling ``` As it turns out, LLVM is quite picky when it comes to IR for exception handling. If the IR does not look exactly like it should, some LLVM-assertions fail and the code generation crashes. This PR adds the necessary modifications to the code generator to make it work. It also adds `exception-handling` as a wasm target feature. ### What this PR does not / what is missing This PR is not a full fledges solution. It is the first step. A few parts are still missing; however, it is already useable (see next section). Currently missing: * The std library has to be adapted. Currently, only [no_std] crates work * Usually, nested exceptions abort the program (i.e. a panic during the cleanup of another panic). This is currently not done yet. - Currently, code inside cleanup handlers does not unwind - To fix this requires a little more work: The code generator currently maintains a single terminate block per function for this. Unfortunately, WASM requires funclet based exception handling. Therefore, we need to create a terminate block per funclet. This is probably not a big problem, but I want to keep this PR simple. ### How to use the compiler given this PR? This PR does not add any command line flags or features. It uses those which are already there. To compile with exceptions enabled, you need * to set the panic strategy to unwind, i.e. `-C panic=unwind` * to enable the exception-handling target feature, i.e. `-C target-feature=+exception-handling` * to tell LLVM about the exception handling, i.e. `-C llvm-args=-wasm-enable-eh` Since the standard library has not been adapted, you can only use it in [no_std] crates as of now. The intrinsic `core::intrinsics::r#try` works. To throw exceptions, you need the ````@llvm.wasm.throw```` intrinsic. I created a sample application which works for me: https://github.com/mirkootter/rust-wasm-demos This example can be run at https://webassembly.sh
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#111322 (Support for native WASM exceptions) - rust-lang#112086 (resolve: Remove artificial import ambiguity errors) - rust-lang#112234 (refactor `tool_doc!`) - rust-lang#112300 (Convert `run-make/coverage-reports` tests to use a custom compiletest mode) - rust-lang#112795 (Migrate some rustc_builtin_macros to SessionDiagnostic) - rust-lang#113144 (Make the `Elaboratable` trait take clauses) - rust-lang#113161 (Fix type privacy lints error message) r? `@ghost` `@rustbot` modify labels: rollup
Cc #58874. |
…std, r=Mark-Simulacrum Add Tests for native wasm exceptions ### Motivation In PR rust-lang#111322, I added support for native WASM exceptions. I was asked by `@davidtwco` to add some tests for it in a follow up PR, which seems like a very good idea. This PR adds three tests for this feature: * codegen: ensure the correct LLVM instructions are used * assembly: ensure the correct WASM instructions are used * run-make: ensure the exception handling works; the WASM code is run using a small nodejs script which demonstrates the exception handling ### Complications There are a few changes beside adding the tests, which were necessary * Tests for the wasm32-unknown-unknown target are (as far as I know) only run on `test-various`. Its docker image uses nodejs-15, which is very old. Experimental support for wasm-exceptions was added in nodejs16. In nodejs 18.12 (LTS), they are stable. - --> increase nodejs to 18.12 in `test-various` * codegen/assembly tests are not performed for the wasm32-unknown-unknown target yet - --> add those to `test-various` as well Due to the last point, some tests are run which have not run before (assembly+codegen tests for wasm32-unknown-unknown). I added `// ignore wasm32-bare` for those which failed ### Local testing I run all tests locally using both `test-various` and `wasm32`. As far as I know, none of the other systems run any test for wasm32 targets.
…std, r=Mark-Simulacrum Add Tests for native wasm exceptions ### Motivation In PR rust-lang#111322, I added support for native WASM exceptions. I was asked by ``@davidtwco`` to add some tests for it in a follow up PR, which seems like a very good idea. This PR adds three tests for this feature: * codegen: ensure the correct LLVM instructions are used * assembly: ensure the correct WASM instructions are used * run-make: ensure the exception handling works; the WASM code is run using a small nodejs script which demonstrates the exception handling ### Complications There are a few changes beside adding the tests, which were necessary * Tests for the wasm32-unknown-unknown target are (as far as I know) only run on `test-various`. Its docker image uses nodejs-15, which is very old. Experimental support for wasm-exceptions was added in nodejs16. In nodejs 18.12 (LTS), they are stable. - --> increase nodejs to 18.12 in `test-various` * codegen/assembly tests are not performed for the wasm32-unknown-unknown target yet - --> add those to `test-various` as well Due to the last point, some tests are run which have not run before (assembly+codegen tests for wasm32-unknown-unknown). I added `// ignore wasm32-bare` for those which failed ### Local testing I run all tests locally using both `test-various` and `wasm32`. As far as I know, none of the other systems run any test for wasm32 targets.
Version 1.72.0 (2023-08-24) ========================== Language -------- - [Replace const eval limit by a lint and add an exponential backoff warning](rust-lang/rust#103877) - [expand: Change how `#![cfg(FALSE)]` behaves on crate root](rust-lang/rust#110141) - [Stabilize inline asm for LoongArch64](rust-lang/rust#111235) - [Uplift `clippy::undropped_manually_drops` lint](rust-lang/rust#111530) - [Uplift `clippy::invalid_utf8_in_unchecked` lint](rust-lang/rust#111543) - [Uplift `clippy::cast_ref_to_mut` lint](rust-lang/rust#111567) - [Uplift `clippy::cmp_nan` lint](rust-lang/rust#111818) - [resolve: Remove artificial import ambiguity errors](rust-lang/rust#112086) - [Don't require associated types with Self: Sized bounds in `dyn Trait` objects](rust-lang/rust#112319) Compiler -------- - [Remember names of `cfg`-ed out items to mention them in diagnostics](rust-lang/rust#109005) - [Support for native WASM exceptions](rust-lang/rust#111322) - [Add support for NetBSD/aarch64-be (big-endian arm64).](rust-lang/rust#111326) - [Write to stdout if `-` is given as output file](rust-lang/rust#111626) - [Force all native libraries to be statically linked when linking a static binary](rust-lang/rust#111698) - [Add Tier 3 support for `loongarch64-unknown-none*`](rust-lang/rust#112310) - [Prevent `.eh_frame` from being emitted for `-C panic=abort`](rust-lang/rust#112403) - [Support 128-bit enum variant in debuginfo codegen](rust-lang/rust#112474) - [compiler: update solaris/illumos to enable tsan support.](rust-lang/rust#112039) Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document memory orderings of `thread::{park, unpark}`](rust-lang/rust#99587) - [io: soften ‘at most one write attempt’ requirement in io::Write::write](rust-lang/rust#107200) - [Specify behavior of HashSet::insert](rust-lang/rust#107619) - [Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>`](rust-lang/rust#111074) - [Update runtime guarantee for `select_nth_unstable`](rust-lang/rust#111974) - [Return `Ok` on kill if process has already exited](rust-lang/rust#112594) - [Implement PartialOrd for `Vec`s over different allocators](rust-lang/rust#112632) - [Use 128 bits for TypeId hash](rust-lang/rust#109953) - [Don't drain-on-drop in DrainFilter impls of various collections.](rust-lang/rust#104455) - [Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata](rust-lang/rust#106450) Rustdoc ------- - [Allow whitespace as path separator like double colon](rust-lang/rust#108537) - [Add search result item types after their name](rust-lang/rust#110688) - [Search for slices and arrays by type with `[]`](rust-lang/rust#111958) - [Clean up type unification and "unboxing"](rust-lang/rust#112233) Stabilized APIs --------------- - [`impl<T: Send> Sync for mpsc::Sender<T>`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E) - [`impl TryFrom<&OsStr> for &str`](https://doc.rust-lang.org/nightly/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str) - [`String::leak`](https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.leak) These APIs are now stable in const contexts: - [`CStr::from_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_str`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) Cargo ----- - Enable `-Zdoctest-in-workspace` by default. When running each documentation test, the working directory is set to the root directory of the package the test belongs to. [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-test.html#working-directory-of-tests) [openwrt#12221](rust-lang/cargo#12221) [openwrt#12288](rust-lang/cargo#12288) - Add support of the "default" keyword to reset previously set `build.jobs` parallelism back to the default. [openwrt#12222](rust-lang/cargo#12222) Compatibility Notes ------------------- - [Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses](rust-lang/rust#112606) - Cargo changed feature name validation check to a hard error. The warning was added in Rust 1.49. These extended characters aren't allowed on crates.io, so this should only impact users of other registries, or people who don't publish to a registry. [openwrt#12291](rust-lang/cargo#12291) Refreshed patches. Signed-off-by: Tianling Shen <[email protected]>
Version 1.72.0 (2023-08-24) ========================== Language -------- - [Replace const eval limit by a lint and add an exponential backoff warning](rust-lang/rust#103877) - [expand: Change how `#![cfg(FALSE)]` behaves on crate root](rust-lang/rust#110141) - [Stabilize inline asm for LoongArch64](rust-lang/rust#111235) - [Uplift `clippy::undropped_manually_drops` lint](rust-lang/rust#111530) - [Uplift `clippy::invalid_utf8_in_unchecked` lint](rust-lang/rust#111543) - [Uplift `clippy::cast_ref_to_mut` lint](rust-lang/rust#111567) - [Uplift `clippy::cmp_nan` lint](rust-lang/rust#111818) - [resolve: Remove artificial import ambiguity errors](rust-lang/rust#112086) - [Don't require associated types with Self: Sized bounds in `dyn Trait` objects](rust-lang/rust#112319) Compiler -------- - [Remember names of `cfg`-ed out items to mention them in diagnostics](rust-lang/rust#109005) - [Support for native WASM exceptions](rust-lang/rust#111322) - [Add support for NetBSD/aarch64-be (big-endian arm64).](rust-lang/rust#111326) - [Write to stdout if `-` is given as output file](rust-lang/rust#111626) - [Force all native libraries to be statically linked when linking a static binary](rust-lang/rust#111698) - [Add Tier 3 support for `loongarch64-unknown-none*`](rust-lang/rust#112310) - [Prevent `.eh_frame` from being emitted for `-C panic=abort`](rust-lang/rust#112403) - [Support 128-bit enum variant in debuginfo codegen](rust-lang/rust#112474) - [compiler: update solaris/illumos to enable tsan support.](rust-lang/rust#112039) Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document memory orderings of `thread::{park, unpark}`](rust-lang/rust#99587) - [io: soften ‘at most one write attempt’ requirement in io::Write::write](rust-lang/rust#107200) - [Specify behavior of HashSet::insert](rust-lang/rust#107619) - [Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>`](rust-lang/rust#111074) - [Update runtime guarantee for `select_nth_unstable`](rust-lang/rust#111974) - [Return `Ok` on kill if process has already exited](rust-lang/rust#112594) - [Implement PartialOrd for `Vec`s over different allocators](rust-lang/rust#112632) - [Use 128 bits for TypeId hash](rust-lang/rust#109953) - [Don't drain-on-drop in DrainFilter impls of various collections.](rust-lang/rust#104455) - [Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata](rust-lang/rust#106450) Rustdoc ------- - [Allow whitespace as path separator like double colon](rust-lang/rust#108537) - [Add search result item types after their name](rust-lang/rust#110688) - [Search for slices and arrays by type with `[]`](rust-lang/rust#111958) - [Clean up type unification and "unboxing"](rust-lang/rust#112233) Stabilized APIs --------------- - [`impl<T: Send> Sync for mpsc::Sender<T>`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E) - [`impl TryFrom<&OsStr> for &str`](https://doc.rust-lang.org/nightly/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str) - [`String::leak`](https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.leak) These APIs are now stable in const contexts: - [`CStr::from_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_str`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) Cargo ----- - Enable `-Zdoctest-in-workspace` by default. When running each documentation test, the working directory is set to the root directory of the package the test belongs to. [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-test.html#working-directory-of-tests) [openwrt#12221](rust-lang/cargo#12221) [openwrt#12288](rust-lang/cargo#12288) - Add support of the "default" keyword to reset previously set `build.jobs` parallelism back to the default. [openwrt#12222](rust-lang/cargo#12222) Compatibility Notes ------------------- - [Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses](rust-lang/rust#112606) - Cargo changed feature name validation check to a hard error. The warning was added in Rust 1.49. These extended characters aren't allowed on crates.io, so this should only impact users of other registries, or people who don't publish to a registry. [openwrt#12291](rust-lang/cargo#12291) Refreshed patches. Signed-off-by: Tianling Shen <[email protected]>
Is there an issue tracking adding support for libstd? |
Version 1.72.0 (2023-08-24) ========================== Language -------- - [Replace const eval limit by a lint and add an exponential backoff warning](rust-lang/rust#103877) - [expand: Change how `#![cfg(FALSE)]` behaves on crate root](rust-lang/rust#110141) - [Stabilize inline asm for LoongArch64](rust-lang/rust#111235) - [Uplift `clippy::undropped_manually_drops` lint](rust-lang/rust#111530) - [Uplift `clippy::invalid_utf8_in_unchecked` lint](rust-lang/rust#111543) - [Uplift `clippy::cast_ref_to_mut` lint](rust-lang/rust#111567) - [Uplift `clippy::cmp_nan` lint](rust-lang/rust#111818) - [resolve: Remove artificial import ambiguity errors](rust-lang/rust#112086) - [Don't require associated types with Self: Sized bounds in `dyn Trait` objects](rust-lang/rust#112319) Compiler -------- - [Remember names of `cfg`-ed out items to mention them in diagnostics](rust-lang/rust#109005) - [Support for native WASM exceptions](rust-lang/rust#111322) - [Add support for NetBSD/aarch64-be (big-endian arm64).](rust-lang/rust#111326) - [Write to stdout if `-` is given as output file](rust-lang/rust#111626) - [Force all native libraries to be statically linked when linking a static binary](rust-lang/rust#111698) - [Add Tier 3 support for `loongarch64-unknown-none*`](rust-lang/rust#112310) - [Prevent `.eh_frame` from being emitted for `-C panic=abort`](rust-lang/rust#112403) - [Support 128-bit enum variant in debuginfo codegen](rust-lang/rust#112474) - [compiler: update solaris/illumos to enable tsan support.](rust-lang/rust#112039) Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document memory orderings of `thread::{park, unpark}`](rust-lang/rust#99587) - [io: soften ‘at most one write attempt’ requirement in io::Write::write](rust-lang/rust#107200) - [Specify behavior of HashSet::insert](rust-lang/rust#107619) - [Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>`](rust-lang/rust#111074) - [Update runtime guarantee for `select_nth_unstable`](rust-lang/rust#111974) - [Return `Ok` on kill if process has already exited](rust-lang/rust#112594) - [Implement PartialOrd for `Vec`s over different allocators](rust-lang/rust#112632) - [Use 128 bits for TypeId hash](rust-lang/rust#109953) - [Don't drain-on-drop in DrainFilter impls of various collections.](rust-lang/rust#104455) - [Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata](rust-lang/rust#106450) Rustdoc ------- - [Allow whitespace as path separator like double colon](rust-lang/rust#108537) - [Add search result item types after their name](rust-lang/rust#110688) - [Search for slices and arrays by type with `[]`](rust-lang/rust#111958) - [Clean up type unification and "unboxing"](rust-lang/rust#112233) Stabilized APIs --------------- - [`impl<T: Send> Sync for mpsc::Sender<T>`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E) - [`impl TryFrom<&OsStr> for &str`](https://doc.rust-lang.org/nightly/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str) - [`String::leak`](https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.leak) These APIs are now stable in const contexts: - [`CStr::from_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_str`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) Cargo ----- - Enable `-Zdoctest-in-workspace` by default. When running each documentation test, the working directory is set to the root directory of the package the test belongs to. [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-test.html#working-directory-of-tests) [openwrt#12221](rust-lang/cargo#12221) [openwrt#12288](rust-lang/cargo#12288) - Add support of the "default" keyword to reset previously set `build.jobs` parallelism back to the default. [openwrt#12222](rust-lang/cargo#12222) Compatibility Notes ------------------- - [Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses](rust-lang/rust#112606) - Cargo changed feature name validation check to a hard error. The warning was added in Rust 1.49. These extended characters aren't allowed on crates.io, so this should only impact users of other registries, or people who don't publish to a registry. [openwrt#12291](rust-lang/cargo#12291) Refreshed patches. Signed-off-by: Tianling Shen <[email protected]> (cherry picked from commit 846ee0b) Signed-off-by: Jeffery To <[email protected]>
Version 1.72.0 (2023-08-24) ========================== Language -------- - [Replace const eval limit by a lint and add an exponential backoff warning](rust-lang/rust#103877) - [expand: Change how `#![cfg(FALSE)]` behaves on crate root](rust-lang/rust#110141) - [Stabilize inline asm for LoongArch64](rust-lang/rust#111235) - [Uplift `clippy::undropped_manually_drops` lint](rust-lang/rust#111530) - [Uplift `clippy::invalid_utf8_in_unchecked` lint](rust-lang/rust#111543) - [Uplift `clippy::cast_ref_to_mut` lint](rust-lang/rust#111567) - [Uplift `clippy::cmp_nan` lint](rust-lang/rust#111818) - [resolve: Remove artificial import ambiguity errors](rust-lang/rust#112086) - [Don't require associated types with Self: Sized bounds in `dyn Trait` objects](rust-lang/rust#112319) Compiler -------- - [Remember names of `cfg`-ed out items to mention them in diagnostics](rust-lang/rust#109005) - [Support for native WASM exceptions](rust-lang/rust#111322) - [Add support for NetBSD/aarch64-be (big-endian arm64).](rust-lang/rust#111326) - [Write to stdout if `-` is given as output file](rust-lang/rust#111626) - [Force all native libraries to be statically linked when linking a static binary](rust-lang/rust#111698) - [Add Tier 3 support for `loongarch64-unknown-none*`](rust-lang/rust#112310) - [Prevent `.eh_frame` from being emitted for `-C panic=abort`](rust-lang/rust#112403) - [Support 128-bit enum variant in debuginfo codegen](rust-lang/rust#112474) - [compiler: update solaris/illumos to enable tsan support.](rust-lang/rust#112039) Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document memory orderings of `thread::{park, unpark}`](rust-lang/rust#99587) - [io: soften ‘at most one write attempt’ requirement in io::Write::write](rust-lang/rust#107200) - [Specify behavior of HashSet::insert](rust-lang/rust#107619) - [Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>`](rust-lang/rust#111074) - [Update runtime guarantee for `select_nth_unstable`](rust-lang/rust#111974) - [Return `Ok` on kill if process has already exited](rust-lang/rust#112594) - [Implement PartialOrd for `Vec`s over different allocators](rust-lang/rust#112632) - [Use 128 bits for TypeId hash](rust-lang/rust#109953) - [Don't drain-on-drop in DrainFilter impls of various collections.](rust-lang/rust#104455) - [Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata](rust-lang/rust#106450) Rustdoc ------- - [Allow whitespace as path separator like double colon](rust-lang/rust#108537) - [Add search result item types after their name](rust-lang/rust#110688) - [Search for slices and arrays by type with `[]`](rust-lang/rust#111958) - [Clean up type unification and "unboxing"](rust-lang/rust#112233) Stabilized APIs --------------- - [`impl<T: Send> Sync for mpsc::Sender<T>`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E) - [`impl TryFrom<&OsStr> for &str`](https://doc.rust-lang.org/nightly/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str) - [`String::leak`](https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.leak) These APIs are now stable in const contexts: - [`CStr::from_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_str`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) Cargo ----- - Enable `-Zdoctest-in-workspace` by default. When running each documentation test, the working directory is set to the root directory of the package the test belongs to. [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-test.html#working-directory-of-tests) [#12221](rust-lang/cargo#12221) [#12288](rust-lang/cargo#12288) - Add support of the "default" keyword to reset previously set `build.jobs` parallelism back to the default. [#12222](rust-lang/cargo#12222) Compatibility Notes ------------------- - [Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses](rust-lang/rust#112606) - Cargo changed feature name validation check to a hard error. The warning was added in Rust 1.49. These extended characters aren't allowed on crates.io, so this should only impact users of other registries, or people who don't publish to a registry. [#12291](rust-lang/cargo#12291) Refreshed patches. Signed-off-by: Tianling Shen <[email protected]> (cherry picked from commit 846ee0b) Signed-off-by: Jeffery To <[email protected]>
Pkgsrc changes: * Adjust patches and cargo checksums to new versions. Upstream changes: Version 1.72.0 (2023-08-24) ========================== Language -------- - [Replace const eval limit by a lint and add an exponential backoff warning] (rust-lang/rust#103877) - [expand: Change how `#![cfg(FALSE)]` behaves on crate root] (rust-lang/rust#110141) - [Stabilize inline asm for LoongArch64] (rust-lang/rust#111235) - [Uplift `clippy::undropped_manually_drops` lint] (rust-lang/rust#111530) - [Uplift `clippy::invalid_utf8_in_unchecked` lint] (rust-lang/rust#111543) - [Uplift `clippy::cast_ref_to_mut` lint] (rust-lang/rust#111567) - [Uplift `clippy::cmp_nan` lint] (rust-lang/rust#111818) - [resolve: Remove artificial import ambiguity errors] (rust-lang/rust#112086) - [Don't require associated types with Self: Sized bounds in `dyn Trait` objects] (rust-lang/rust#112319) Compiler -------- - [Remember names of `cfg`-ed out items to mention them in diagnostics] (rust-lang/rust#109005) - [Support for native WASM exceptions] (rust-lang/rust#111322) - [Add support for NetBSD/aarch64-be (big-endian arm64).] (rust-lang/rust#111326) - [Write to stdout if `-` is given as output file] (rust-lang/rust#111626) - [Force all native libraries to be statically linked when linking a static binary] (rust-lang/rust#111698) - [Add Tier 3 support for `loongarch64-unknown-none*`] (rust-lang/rust#112310) - [Prevent `.eh_frame` from being emitted for `-C panic=abort`] (rust-lang/rust#112403) - [Support 128-bit enum variant in debuginfo codegen] (rust-lang/rust#112474) - [compiler: update solaris/illumos to enable tsan support.] (rust-lang/rust#112039) Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document memory orderings of `thread::{park, unpark}`] (rust-lang/rust#99587) - [io: soften â<80><98>at most one write attemptâ<80><99> requirement in io::Write::write] (rust-lang/rust#107200) - [Specify behavior of HashSet::insert] (rust-lang/rust#107619) - [Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>`] (rust-lang/rust#111074) - [Update runtime guarantee for `select_nth_unstable`] (rust-lang/rust#111974) - [Return `Ok` on kill if process has already exited] (rust-lang/rust#112594) - [Implement PartialOrd for `Vec`s over different allocators] (rust-lang/rust#112632) - [Use 128 bits for TypeId hash] (rust-lang/rust#109953) - [Don't drain-on-drop in DrainFilter impls of various collections.] (rust-lang/rust#104455) - [Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata] (rust-lang/rust#106450) Rustdoc ------- - [Allow whitespace as path separator like double colon] (rust-lang/rust#108537) - [Add search result item types after their name] (rust-lang/rust#110688) - [Search for slices and arrays by type with `[]`] (rust-lang/rust#111958) - [Clean up type unification and "unboxing"] (rust-lang/rust#112233) Stabilized APIs --------------- - [`impl<T: Send> Sync for mpsc::Sender<T>`] (https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E) - [`impl TryFrom<&OsStr> for &str`] (https://doc.rust-lang.org/nightly/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str) - [`String::leak`] (https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.leak) These APIs are now stable in const contexts: - [`CStr::from_bytes_with_nul`] (https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes`] (https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes_with_nul`] (https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_str`] (https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) Cargo ----- - Enable `-Zdoctest-in-workspace` by default. When running each documentation test, the working directory is set to the root directory of the package the test belongs to. [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-test.html#working-directory-of-tests) [#12221](rust-lang/cargo#12221) [#12288](rust-lang/cargo#12288) - Add support of the "default" keyword to reset previously set `build.jobs` parallelism back to the default. [#12222](rust-lang/cargo#12222) Compatibility Notes ------------------- - [Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses] (rust-lang/rust#112606) - Cargo changed feature name validation check to a hard error. The warning was added in Rust 1.49. These extended characters aren't allowed on crates.io, so this should only impact users of other registries, or people who don't publish to a registry. [#12291](rust-lang/cargo#12291)
Version 1.72.0 (2023-08-24) ========================== Language -------- - [Replace const eval limit by a lint and add an exponential backoff warning](rust-lang/rust#103877) - [expand: Change how `#![cfg(FALSE)]` behaves on crate root](rust-lang/rust#110141) - [Stabilize inline asm for LoongArch64](rust-lang/rust#111235) - [Uplift `clippy::undropped_manually_drops` lint](rust-lang/rust#111530) - [Uplift `clippy::invalid_utf8_in_unchecked` lint](rust-lang/rust#111543) - [Uplift `clippy::cast_ref_to_mut` lint](rust-lang/rust#111567) - [Uplift `clippy::cmp_nan` lint](rust-lang/rust#111818) - [resolve: Remove artificial import ambiguity errors](rust-lang/rust#112086) - [Don't require associated types with Self: Sized bounds in `dyn Trait` objects](rust-lang/rust#112319) Compiler -------- - [Remember names of `cfg`-ed out items to mention them in diagnostics](rust-lang/rust#109005) - [Support for native WASM exceptions](rust-lang/rust#111322) - [Add support for NetBSD/aarch64-be (big-endian arm64).](rust-lang/rust#111326) - [Write to stdout if `-` is given as output file](rust-lang/rust#111626) - [Force all native libraries to be statically linked when linking a static binary](rust-lang/rust#111698) - [Add Tier 3 support for `loongarch64-unknown-none*`](rust-lang/rust#112310) - [Prevent `.eh_frame` from being emitted for `-C panic=abort`](rust-lang/rust#112403) - [Support 128-bit enum variant in debuginfo codegen](rust-lang/rust#112474) - [compiler: update solaris/illumos to enable tsan support.](rust-lang/rust#112039) Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. Libraries --------- - [Document memory orderings of `thread::{park, unpark}`](rust-lang/rust#99587) - [io: soften ‘at most one write attempt’ requirement in io::Write::write](rust-lang/rust#107200) - [Specify behavior of HashSet::insert](rust-lang/rust#107619) - [Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>`](rust-lang/rust#111074) - [Update runtime guarantee for `select_nth_unstable`](rust-lang/rust#111974) - [Return `Ok` on kill if process has already exited](rust-lang/rust#112594) - [Implement PartialOrd for `Vec`s over different allocators](rust-lang/rust#112632) - [Use 128 bits for TypeId hash](rust-lang/rust#109953) - [Don't drain-on-drop in DrainFilter impls of various collections.](rust-lang/rust#104455) - [Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata](rust-lang/rust#106450) Rustdoc ------- - [Allow whitespace as path separator like double colon](rust-lang/rust#108537) - [Add search result item types after their name](rust-lang/rust#110688) - [Search for slices and arrays by type with `[]`](rust-lang/rust#111958) - [Clean up type unification and "unboxing"](rust-lang/rust#112233) Stabilized APIs --------------- - [`impl<T: Send> Sync for mpsc::Sender<T>`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Sender.html#impl-Sync-for-Sender%3CT%3E) - [`impl TryFrom<&OsStr> for &str`](https://doc.rust-lang.org/nightly/std/primitive.str.html#impl-TryFrom%3C%26'a+OsStr%3E-for-%26'a+str) - [`String::leak`](https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.leak) These APIs are now stable in const contexts: - [`CStr::from_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_bytes_with_nul`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) - [`CStr::to_str`](https://doc.rust-lang.org/nightly/std/ffi/struct.CStr.html#method.from_bytes_with_nul) Cargo ----- - Enable `-Zdoctest-in-workspace` by default. When running each documentation test, the working directory is set to the root directory of the package the test belongs to. [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-test.html#working-directory-of-tests) [openwrt#12221](rust-lang/cargo#12221) [openwrt#12288](rust-lang/cargo#12288) - Add support of the "default" keyword to reset previously set `build.jobs` parallelism back to the default. [openwrt#12222](rust-lang/cargo#12222) Compatibility Notes ------------------- - [Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses](rust-lang/rust#112606) - Cargo changed feature name validation check to a hard error. The warning was added in Rust 1.49. These extended characters aren't allowed on crates.io, so this should only impact users of other registries, or people who don't publish to a registry. [openwrt#12291](rust-lang/cargo#12291) Refreshed patches. Signed-off-by: Tianling Shen <[email protected]>
Motivation
Currently, rustc does not support native WASM exceptions. It does support JavaScript based exceptions for the wasm32-emscripten-target, but this requires back&forth with javascript for many calls, which is very slow.
Native wasm support for exceptions is quite common: Clang+LLVM implemented them years ago, and all major browsers support them by now. They enable zero-cost exceptions, at least with regard to runtime-performance-cost. They may increase startup-time and code size, though.
Important: This PR does not change default behaviour
Exceptions usually add a lot of code in form of unwinding blocks, increasing the binary size. Most users probably do not want that, especially which regard to web development.
Therefore, wasm exceptions play a similar role as WASM-threads: rustc should support them, like clang does, but users who want to use it have to use some command-line magic like rustflags to opt in.
What does this PR do?
As stated above, the default behaviour is not changed. It is already possible to opt-in into wasm exceptions using the command line. Unfortunately, the LLVM IR is invalid and the LLVM backend crashes.
As it turns out, LLVM is quite picky when it comes to IR for exception handling. If the IR does not look exactly like it should, some LLVM-assertions fail and the code generation crashes.
This PR adds the necessary modifications to the code generator to make it work. It also adds
exception-handling
as a wasm target feature.What this PR does not / what is missing
This PR is not a full fledges solution. It is the first step. A few parts are still missing; however, it is already useable (see next section).
Currently missing:
How to use the compiler given this PR?
This PR does not add any command line flags or features. It uses those which are already there. To compile with exceptions enabled, you need
-C panic=unwind
-C target-feature=+exception-handling
-C llvm-args=-wasm-enable-eh
Since the standard library has not been adapted, you can only use it in [no_std] crates as of now. The intrinsic
core::intrinsics::r#try
works. To throw exceptions, you need the@llvm.wasm.throw
intrinsic.I created a sample application which works for me: https://github.com/mirkootter/rust-wasm-demos
This example can be run at https://webassembly.sh