Commit Graph

228149 Commits

Author SHA1 Message Date
Matthias Krüger
4696a92183
Rollup merge of #111322 - mirkootter:master, r=davidtwco
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
2023-06-29 16:36:30 +02:00
Bryanskiy
35c6a1d0f3 Fix type privacy lints error message 2023-06-29 16:24:07 +03:00
Jakub Beránek
32428ab5f3
CI: do not cancel concurrent builds on the same branch
Add an exception for try and try-perf branches to enable concurrent try builds and unrolled rollup builds.
2023-06-29 14:52:52 +02:00
bors
e69c7306e2 Auto merge of #113151 - RalfJung:miri, r=RalfJung,oli-obk
update Miri

r? `@ghost`
2023-06-29 10:55:40 +00:00
Oli Scherer
78f58f96aa Use a valid target directory in miri ui tests 2023-06-29 10:43:49 +00:00
Vadim Petrochenkov
4dcce38cda resolve: Remove artificial import ambiguity errors 2023-06-29 13:42:58 +03:00
ozkanonur
cde54ffc99 refactor tool_doc! so that it can accept additional arguments.
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-06-29 12:37:48 +03:00
lcnr
d04775d739 change snapshot tracking in fulfillment contexts 2023-06-29 10:02:26 +02:00
Tshepang Mbambo
5b46aa1122
make HashMap::or_insert_with example more simple 2023-06-29 09:33:15 +02:00
Ralf Jung
a3cea7f179 update lockfile 2023-06-29 09:31:47 +02:00
bors
de22388873 Auto merge of #113134 - TaKO8Ki:rollup-4hvqzf6, r=TaKO8Ki
Rollup of 5 pull requests

Successful merges:

 - #112946 (Improve cgu naming and ordering)
 - #113048 (Fix build on Solaris where fd-lock cannot be used.)
 - #113100 (Fix display of long items in search results)
 - #113107 (add check for ConstKind::Value(_) to in_operand())
 - #113119 (rustdoc: Reduce internal function visibility.)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-29 07:07:37 +00:00
bors
feed376e15 Auto merge of #2946 - RalfJung:rustup, r=RalfJung
Rustup
2023-06-29 06:45:06 +00:00
Ralf Jung
cca0c81027 Merge from rustc 2023-06-29 08:43:01 +02:00
Ralf Jung
8d4b2bdf7b Preparing for merge from rustc 2023-06-29 08:42:56 +02:00
bors
0a32ca9831 Auto merge of #113146 - matthiaskrgr:rollup-bxtr51e, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112670 (privacy: Type privacy lints fixes and cleanups)
 - #112929 (Test that we require implementing trait items whose bounds don't hold in the current impl)
 - #113054 (Make `rustc_on_unimplemented` std-agnostic)
 - #113137 (don't suggest `move` for borrows that aren't closures)
 - #113139 (style-guide: Clarify let-else further)
 - #113140 (style-guide: Add an example of formatting a multi-line attribute)
 - #113143 (style-guide: Narrow guidance about references and dereferencing)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-29 04:34:46 +00:00
Matthias Krüger
7a7ffced6a
Rollup merge of #113143 - joshtriplett:style-guide-narrow-dereference-guidance, r=calebcartwright
style-guide: Narrow guidance about references and dereferencing

The style guide advises "prefer dereferencing to taking references", but
doesn't give guidance on when that "preference" should get overridden by
other considerations. Give an example of when it's fine to ignore
that advice.
2023-06-29 05:48:41 +02:00
Matthias Krüger
c0e37ad127
Rollup merge of #113140 - joshtriplett:style-guide-example-multi-line-attribute, r=calebcartwright
style-guide: Add an example of formatting a multi-line attribute

We already say to format attributes like functions, but we didn't have
an example of formatting a multi-line attribute.
2023-06-29 05:48:41 +02:00
Matthias Krüger
c4dc70eb31
Rollup merge of #113139 - joshtriplett:style-clarify-let-else, r=calebcartwright
style-guide: Clarify let-else further

Give some additional examples with multi-line patterns.

Make it clearer to go on to the next case if the conditions aren't met.
2023-06-29 05:48:41 +02:00
Matthias Krüger
7e1869f9b4
Rollup merge of #113137 - lukas-code:no-moving-references, r=compiler-errors
don't suggest `move` for borrows that aren't closures

fixes https://github.com/rust-lang/rust/issues/113087
2023-06-29 05:48:40 +02:00
Matthias Krüger
f35f213d27
Rollup merge of #113054 - Rageking8:make-rustc_on_unimplemented-std-agnostic, r=WaffleLapkin
Make `rustc_on_unimplemented` std-agnostic

See #112923

r? `@WaffleLapkin`
2023-06-29 05:48:40 +02:00
Matthias Krüger
1963688f93
Rollup merge of #112929 - oli-obk:what_if_an_impl_item_just_doesnt_wanna_be_impld, r=compiler-errors
Test that we require implementing trait items whose bounds don't hold in the current impl

I initially tried to make most of these pass, but that's a big can of worms, so I'm just adding them as tests, considering we have no tests for these things.
2023-06-29 05:48:39 +02:00
Matthias Krüger
42a495da7e
Rollup merge of #112670 - petrochenkov:typriv, r=eholk
privacy: Type privacy lints fixes and cleanups

See individual commits.
Follow up to https://github.com/rust-lang/rust/pull/111801.
2023-06-29 05:48:39 +02:00
Nicholas Nethercote
7e786e81b0 Avoid cloning LocalDecls.
`DerefChecker` can just hold a reference instead. This avoids quite a
lot of allocations for some benchmarks.
2023-06-29 11:53:41 +10:00
Nicholas Nethercote
8d7084d65f Simplify the bundles vectors.
After the last commit, they contain `Option<&OperandBundleDef<'a>>` but
the values are always `Some(_)`. This commit removes the needless
`Option` wrapper. This also simplifies the type signatures of
`LLVMRustBuild{Invoke,Call}`, which were relying on the fact that the
represention of `Option<&T>` is the same as `&T` for non-`None` values.
2023-06-29 11:51:00 +10:00
Nicholas Nethercote
81436ebd55 Use SmallVec for the bundles vectors.
They never have a length of more than two. So this commit changes them
to `SmallVec<[_; 2]>`.

Also, we possibly push `None` values and then filter those `None` values
out again with `retain`. So this commit removes the `retain` and instead
only pushes the values if they are `Some(_)`.
2023-06-29 11:47:39 +10:00
Nicholas Nethercote
d20b1a8f6b Set capacity of the string passed to push_item_name.
Other callsites already do this, but these two were missed. This avoids
some allocations.
2023-06-29 11:46:25 +10:00
Nicholas Nethercote
f2d863fa75 Remove SmallStr.
It no longer has any uses. If it's needed in the future, it can be
easily reinstated. Or a crate such as `smallstr` can be used, much like
we use `smallvec`.
2023-06-29 11:45:52 +10:00
Nicholas Nethercote
de1914af34 Avoid an unnecessary use of SmallStr.
I don't know why `SmallStr` was used here; some ad hoc profiling showed
this code is not that hot, the string is usually empty, and when it's
not empty it's usually very short. However, the use of a
`SmallStr<1024>` does result in 1024 byte `memcpy` call on each
execution, which shows up when I do `memcpy` profiling. So using a
normal string makes the code both simpler and very slightly faster.
2023-06-29 11:37:12 +10:00
Nicholas Nethercote
45fcd1d0c5 Use partition_point in SourceMap::lookup_source_file_idx.
This makes it (a) a little simpler, and (b) more similar to
`SourceFile::lookup_line`.
2023-06-29 11:36:09 +10:00
Nicholas Nethercote
b4c6e19ade Replace a lookup_debug_loc call.
`lookup_debug_loc` finds a file, line, and column, which requires two
binary searches. But this call site only needs the file.

This commit replaces the call with `lookup_source_file`, which does a
single binary search.
2023-06-29 11:31:43 +10:00
Nicholas Nethercote
a13be655a5 Avoid unnecessary line lookup.
`lookup_debug_loc` calls `SourceMap::lookup_line`, which does a binary
search over the files, and then a binary search over the lines within
the found file. It then calls `SourceFile::line_begin_pos`, which redoes
the binary search over the lines within the found file.

This commit removes the second binary search over the lines, instead
getting the line starting pos directly using the result of the first
binary search over the lines.

(And likewise for `get_span_loc`, in the cranelift backend.)
2023-06-29 11:26:39 +10:00
Michael Goulet
aafc801d69 Make the Elaboratable trait take clauses 2023-06-29 00:46:41 +00:00
Josh Triplett
025dd3aef0 style-guide: Narrow guidance about references and dereferencing
The style guide advises "prefer dereferencing to taking references", but
doesn't give guidance on when that "preference" should get overridden by
other considerations. Give an example of when it's fine to ignore
that advice.
2023-06-28 17:10:03 -07:00
bors
75726cae37 Auto merge of #112629 - compiler-errors:atb-imply, r=jackh726
Make associated type bounds in supertrait position implied

`trait A: B<Assoc: C> {}` should be able to imply both `Self: B` and `<Self as B>::Assoc: C`. Adjust the way that we collect implied predicates to do so.

Fixes #112573
Fixes #112568
2023-06-28 23:58:28 +00:00
Josh Triplett
4cc80651b8 style-guide: Add an example of formatting a multi-line attribute
We already say to format attributes like functions, but we didn't have
an example of formatting a multi-line attribute.
2023-06-28 15:35:05 -07:00
Lukas Markeffsky
5e83ddd279 don't suggest move for borrows that aren't closures 2023-06-28 23:56:58 +02:00
Josh Triplett
5abeb801b8 syle-guide: Clarify let-else further
Give some additional examples with multi-line patterns.

Make it clearer to go on to the next case if the conditions aren't met.
2023-06-28 14:56:21 -07:00
bors
cec5ec44b1 Auto merge of #2936 - Vanille-N:unique, r=RalfJung
Optional semantics for `Unique`

Use with `-Zmiri-unique-is-unique`, makes `core::ptr::Unique` get a reborrow with its own permissions.
2023-06-28 21:21:42 +00:00
Takayuki Maeda
8a5272cb37
Rollup merge of #113119 - aDotInTheVoid:reduce-viz, r=notriddle
rustdoc: Reduce internal function visibility.

As suggested [here](1862fcb1df (r1211200570)).
2023-06-29 03:29:34 +09:00
Takayuki Maeda
74d6958297
Rollup merge of #113107 - mj10021:issue-113012-fix, r=oli-obk
add check for ConstKind::Value(_) to in_operand()

Added check for valtree value to close #113012 which fixes the issue, although I am not sure if adding the check there is sound or not cc `@oli-obk`
2023-06-29 03:29:33 +09:00
Takayuki Maeda
5871bc8486
Rollup merge of #113100 - GuillaumeGomez:search-result-long-name, r=notriddle
Fix display of long items in search results

Fixes https://github.com/rust-lang/rust/issues/113060.

You can test the result [here](https://rustdoc.crud.net/imperio/search-result-long-name/lib2/index.html).

To make it a bit better, I also reduced a bit the size of the short documentation from half to 2 fifth of the width.

r? `@notriddle`
2023-06-29 03:29:33 +09:00
Takayuki Maeda
376c944bd2
Rollup merge of #113048 - psumbera:solaris-bootstrap-cfgs, r=ozkanonur
Fix build on Solaris where fd-lock cannot be used.

This fixes build regression after e7e584b7d9.

Resolves #113085
2023-06-29 03:29:32 +09:00
Takayuki Maeda
bad0688563
Rollup merge of #112946 - nnethercote:improve-cgu-naming-and-ordering, r=wesleywiser
Improve cgu naming and ordering

Some quality of life improvements when debugging and profiling CGU formation.

r? `@wesleywiser`
2023-06-29 03:29:32 +09:00
Neven Villani
0671f14733
Unique gets special treatment when -Zmiri-unique-is-unique 2023-06-28 18:42:13 +02:00
bors
5bd28f5eac Auto merge of #98867 - cjgillot:metaloop, r=oli-obk
Refactor metadata emission to avoid visiting HIR

This PR refactors metadata emission to be based on tables and iteration over definitions.

In a first part, this PR moves information from the `EntryKind` enum to tables, until removing the `EntryKind` enum.
In a second part, the iteration scheme is refactored to avoid fetching HIR unless strictly necessary.

r? `@ghost`
2023-06-28 16:16:27 +00:00
bors
eb76764ea4 Auto merge of #113120 - Dylan-DPC:rollup-cz4qr3o, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #111571 (Implement proposed API for `proc_macro_span`)
 - #112236 (Simplify computation of killed borrows)
 - #112867 (More `ImplSource` nits)
 - #113019 (add note for non-exhaustive matches with guards)
 - #113094 (Fix invalid HTML DIV tag used in HEAD)
 - #113111 (add myself to review for t-types stuff)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-28 13:25:41 +00:00
bors
1ffe627f05 Auto merge of #2945 - oli-obk:gha_mk_pr, r=RalfJung
Try running a sync automatically

absolutely no clue if this works, but it happens after the zulip message, so worst case we'll see the failure after the cron job did everything it currently does.
2023-06-28 12:59:55 +00:00
Oli Scherer
e1b2951450 Try running a sync automatically 2023-06-28 12:59:29 +00:00
Dylan DPC
11c8dbf9f7
Rollup merge of #113111 - BoxyUwU:boxy_t_types_review, r=compiler-errors
add myself to review for t-types stuff

I think this is how the triagebot stuff works 😅 should mean that `r? types` can now assign me
2023-06-28 18:28:48 +05:30
Dylan DPC
a70842c7d1
Rollup merge of #113094 - GuillaumeGomez:fix-invalid-div-tag-in-head, r=notriddle,fmease
Fix invalid HTML DIV tag used in HEAD

Fixes https://github.com/rust-lang/rust/issues/113067.

The issue also nicely explains the whole problem.

r? ``@notriddle``
2023-06-28 18:28:48 +05:30