Matthias Krüger [Sat, 10 Dec 2022 23:30:18 +0000 (00:30 +0100)]
Rollup merge of #105459 - jyn514:proc-macro-default, r=Mark-Simulacrum
Build rust-analyzer proc-macro server by default
This allows getting rid of some documentation and an extra step when building a custom toolchain: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#creating-a-rustup-toolchain and it seems likely that people will want to do this if they want rustdoc (which is also built by default).
bors [Sat, 10 Dec 2022 16:37:36 +0000 (16:37 +0000)]
Auto merge of #105531 - matthiaskrgr:rollup-7y7zbgl, r=matthiaskrgr
Rollup of 6 pull requests
Successful merges:
- #104460 (Migrate parts of `rustc_expand` to session diagnostics)
- #105192 (Point at LHS on binop type err if relevant)
- #105234 (Remove unneeded field from `SwitchTargets`)
- #105239 (Avoid heap allocation when truncating thread names)
- #105410 (Consider `parent_count` for const param defaults)
- #105482 (Fix invalid codegen during debuginfo lowering)
Matthias Krüger [Sat, 10 Dec 2022 14:01:45 +0000 (15:01 +0100)]
Rollup merge of #105482 - wesleywiser:fix_debuginfo_ub, r=tmiasko
Fix invalid codegen during debuginfo lowering
In order for LLVM to correctly generate debuginfo for msvc, we sometimes need to spill arguments to the stack and perform some direct & indirect offsets into the value. Previously, this code always performed those actions, even when not required as LLVM would clean it up during optimization.
However, when MIR inlining is enabled, this can cause problems as the operations occur prior to the spilled value being initialized. To solve this, we first calculate the necessary offsets using just the type which is side-effect free and does not alter the LLVM IR. Then, if we are in a situation which requires us to generate the LLVM IR (and this situation only occurs for arguments, not local variables) then we perform the same calculation again, this time generating the appropriate LLVM IR as we go.
r? `@tmiasko` but feel free to reassign if you want 🙂
Matthias Krüger [Sat, 10 Dec 2022 14:01:44 +0000 (15:01 +0100)]
Rollup merge of #105239 - gh2o:no-heap-alloc-on-thread-start, r=cuviper
Avoid heap allocation when truncating thread names
Ensure that heap allocation does not occur in a thread until `std::thread` is ready. This fixes issues with custom allocators that call `std::thread::current()`, since doing so prematurely initializes `THREAD_INFO` and causes the following `thread_info::set()` to fail.
Matthias Krüger [Sat, 10 Dec 2022 14:01:43 +0000 (15:01 +0100)]
Rollup merge of #105234 - JakobDegen:unneeded-field, r=oli-obk
Remove unneeded field from `SwitchTargets`
This had a fixme already. The only change in behavior is that the mir dumps now no longer contains labels for the types of the integers on the edges of a switchint:
I don't think that's a problem though. The information is still available to a user that really cares by checking the type of `_2`, so it honestly feels like a bit of an improvement to me.
Matthias Krüger [Sat, 10 Dec 2022 14:01:42 +0000 (15:01 +0100)]
Rollup merge of #104460 - Nilstrieb:expand-the-translation, r=davidtwco
Migrate parts of `rustc_expand` to session diagnostics
This migrates everything but the `mbe` and `proc_macro` modules. It also contains a few cleanups and drive-by/accidental diagnostic improvements which can be seen in the diff for the UI tests.
bors [Sat, 10 Dec 2022 11:16:18 +0000 (11:16 +0000)]
Auto merge of #105525 - matthiaskrgr:rollup-ricyw5s, r=matthiaskrgr
Rollup of 10 pull requests
Successful merges:
- #98391 (Reimplement std's thread parker on top of events on SGX)
- #104019 (Compute generator sizes with `-Zprint_type_sizes`)
- #104512 (Set `download-ci-llvm = "if-available"` by default when `channel = dev`)
- #104901 (Implement masking in FileType comparison on Unix)
- #105082 (Fix Async Generator ABI)
- #105109 (Add LLVM KCFI support to the Rust compiler)
- #105505 (Don't warn about unused parens when they are used by yeet expr)
- #105514 (Introduce `Span::is_visible`)
- #105516 (Update cargo)
- #105522 (Remove wrong note for short circuiting operators)
nils [Tue, 15 Nov 2022 13:24:33 +0000 (14:24 +0100)]
Migrate parts of `rustc_expand` to session diagnostics
This migrates everything but the `mbe` and `proc_macro` modules. It also
contains a few cleanups and drive-by/accidental diagnostic improvements
which can be seen in the diff for the UI tests.
Matthias Krüger [Sat, 10 Dec 2022 08:24:45 +0000 (09:24 +0100)]
Rollup merge of #105522 - est31:remove_or_and_note, r=scottmcm
Remove wrong note for short circuiting operators
They *are* representable by traits, even if the short-circuiting behaviour requires a different approach than the non-short-circuiting operators. For an example proposal, see the postponed [RFC 2722](https://github.com/rust-lang/rfcs/pull/2722). As it is not accurate, remove most of the note.
Matthias Krüger [Sat, 10 Dec 2022 08:24:43 +0000 (09:24 +0100)]
Rollup merge of #105109 - rcvalle:rust-kcfi, r=bjorn3
Add LLVM KCFI support to the Rust compiler
This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.)
Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653).
LLVM KCFI can be enabled with -Zsanitizer=kcfi.
Thank you again, `@bjorn3,` `@eddyb,` `@nagisa,` and `@ojeda,` for all the help!
Matthias Krüger [Sat, 10 Dec 2022 08:24:43 +0000 (09:24 +0100)]
Rollup merge of #105082 - Swatinem:async-abi, r=compiler-errors
Fix Async Generator ABI
This change was missed when making async generators implement `Future` directly.
It did not cause any problems in codegen so far, as `GeneratorState<(), Output>`
happens to have the same ABI as `Poll<Output>`.
Matthias Krüger [Sat, 10 Dec 2022 08:24:41 +0000 (09:24 +0100)]
Rollup merge of #104512 - jyn514:download-ci-llvm-default, r=Mark-Simulacrum
Set `download-ci-llvm = "if-available"` by default when `channel = dev`
See https://github.com/rust-lang/compiler-team/issues/566. The motivation for changing the default is to avoid downloading and building LLVM when someone runs `x build` before running `x setup`. The motivation for only doing it on `channel = "dev"` is to avoid breaking distros or users installing from source. It works because `dev` is also the default channel.
The diff looks larger than it is; most of it is moving the `llvm` branch below the `rust` so `config.channel` is set.
r? `@Mark-Simulacrum` cc `@oli-obk` `@bjorn3` `@cuviper`
Matthias Krüger [Sat, 10 Dec 2022 08:24:40 +0000 (09:24 +0100)]
Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-se
Reimplement std's thread parker on top of events on SGX
Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore, the generic `Parker` needs to be replaced on all platforms where the new lock implementation will be used.
SGX enclaves have a per-thread event state, which allows waiting for and setting specific bits. This is already used by the current mutex implementation. The thread parker can however be much more efficient, as it only needs to store the `TCS` address of one thread. This address is stored in a state variable, which can also be set to indicate the thread was already notified.
`park_timeout` does not guard against spurious wakeups like the current condition variable does. This is allowed by the API of `Parker`, and I think it is better to let users handle these wakeups themselves as the guarding is quite expensive and might not be necessary.
`@jethrogb` as you wrote the initial SGX support for `std`, I assume you are the target maintainer? Could you help me test this, please? Lacking a x86_64 chip, I can't run SGX.
est31 [Sat, 10 Dec 2022 03:36:23 +0000 (04:36 +0100)]
Correct wrong note for short circuiting operators
They *are* representable by traits, even if the short-circuiting
behaviour requires a different approach than the non-short-circuiting
operators. For an example proposal, see the postponed RFC 2722.
As it is not accurate, reword the note.
bors [Sat, 10 Dec 2022 05:32:44 +0000 (05:32 +0000)]
Auto merge of #105512 - matthiaskrgr:rollup-i74avrf, r=matthiaskrgr
Rollup of 9 pull requests
Successful merges:
- #102406 (Make `missing_copy_implementations` more cautious)
- #105265 (Add `rustc_on_unimplemented` to `Sum` and `Product` trait.)
- #105385 (Skip test on s390x as LLD does not support the platform)
- #105453 (Make `VecDeque::from_iter` O(1) from `vec(_deque)::IntoIter`)
- #105468 (Mangle "main" as "__main_void" on wasm32-wasi)
- #105480 (rustdoc: remove no-op mobile CSS `#sidebar-toggle { text-align }`)
- #105489 (Fix typo in apple_base.rs)
- #105504 (rustdoc: make stability badge CSS more consistent)
- #105506 (Tweak `rustc_must_implement_one_of` diagnostic output)
* They all get rounded corners now. A test case has been added for this, too.
* There are now broadly two kinds of stability badge, where there used to be three: item-info "fat badge", and the "thin badge" in both item tables and in docblocks (which got merged). The fat badges can have icons, while the thin badges can't.
* The old Ayu design doesn't make sense to me. Does anyone know why it was done that way?
Matthias Krüger [Fri, 9 Dec 2022 21:31:57 +0000 (22:31 +0100)]
Rollup merge of #105480 - notriddle:notriddle/sidebar-toggle-mobile-center, r=GuillaumeGomez
rustdoc: remove no-op mobile CSS `#sidebar-toggle { text-align }`
Since 8b001b4da0716936e0ca32303cc0e3c5e53e42f8 make the sidebar toggle a flex container, and already centers its content in desktop mode, this rule doesn't do anything.
Matthias Krüger [Fri, 9 Dec 2022 21:31:57 +0000 (22:31 +0100)]
Rollup merge of #105468 - sunfishcode:sunfishcode/main-void-wasi, r=estebank
Mangle "main" as "__main_void" on wasm32-wasi
On wasm, the age-old C trick of having a main function which can either have no arguments or argc+argv doesn't work, because wasm requires caller and callee signatures to match. WASI's current strategy is to have compilers mangle main's name to indicate which signature they're using. Rust uses the no-argument form, which should be mangled as `__main_void`.
bors [Fri, 9 Dec 2022 21:27:35 +0000 (21:27 +0000)]
Auto merge of #105363 - WaffleLapkin:thin2win_box_next_argument, r=nnethercote
Shrink `rustc_parse_format::Piece`
This makes both variants closer together in size (previously they were different by 208 bytes -- 16 vs 224). This may make things worse, but it's worth a try.
Michael Howell [Fri, 9 Dec 2022 17:40:49 +0000 (10:40 -0700)]
rustdoc: make stability badge CSS more consistent
* They all get rounded corners now. A test case has been added for this, too.
* There are now broadly two kinds of stability badge, where there used to be
three: item-info "fat badge", and the "thin badge" in both item tables and
in docblocks (which got merged). The fat badges can have icons, while the
thin badges can't.
bors [Fri, 9 Dec 2022 15:42:18 +0000 (15:42 +0000)]
Auto merge of #105262 - eduardosm:more-inline-always, r=thomcc
Make some trivial functions `#[inline(always)]`
This is some kind of follow-up of PRs like https://github.com/rust-lang/rust/pull/85218, https://github.com/rust-lang/rust/pull/84061, https://github.com/rust-lang/rust/pull/87150. Functions that do very basic operations are made `#[inline(always)]` to avoid pessimizing them in debug builds when compared to using built-in operations directly.
Matthias Krüger [Fri, 9 Dec 2022 06:25:47 +0000 (07:25 +0100)]
Rollup merge of #105470 - flip1995:clippy_backport, r=Manishearth
Clippy: backport ICE fix before beta branch
r? `@Manishearth`
Before beta is branched tomorrow we should backport the fix from https://github.com/rust-lang/rust-clippy/pull/10027 for an ICE. That way we'll get this into stable one release sooner.
This only cherry-picks the fix, not the tests for it. The proper sync of this will be done next week Thursday.
Matthias Krüger [Fri, 9 Dec 2022 06:25:47 +0000 (07:25 +0100)]
Rollup merge of #105455 - lcnr:correct-reveal-in-validate, r=jackh726
use the correct `Reveal` during validation
supersedes #105454. Deals with https://github.com/rust-lang/rust/issues/105009#issuecomment-1342395333, not closing #105009 as the ICE may leak into beta
The issue was the following:
- we optimize the mir, using `Reveal::All`
- some optimization relies on the hidden type of an opaque type
- we then validate using `Reveal::UserFacing` again which is not able to observe the hidden type
* The rule `display: block` had no noticeable effect. Technically, because markdown tables have a tbody and thead, they get wrapped in an [anonymous table box] in the CSS tree, nested within the `<table>` element's block layout box.
This rule was added in #87230 to make the table side-scrolling, but this same issue was doubly fixed in #88742 by wrapping it in an explicit `<div>` tag. Since accessibility advocates recommend the wrapper div over marking the table as `display: block`, we'll stick with that.
Matthias Krüger [Fri, 9 Dec 2022 06:25:44 +0000 (07:25 +0100)]
Rollup merge of #105387 - willcrichton:scrape-examples-ui-improvements, r=notriddle
Improve Rustdoc scrape-examples UI
This PR combines a few different improvements to the scrape-examples UI. See a live demo here: https://willcrichton.net/misc/scrape-examples/small-first-example/clap/struct.Arg.html
### 1. The first scraped example now takes up significantly less screen height.
Inserting the first scraped example takes up a lot of vertical screen space. I don't want this addition to overwhelm users, so I decided to reduce the height of the initial example in two ways: (A) the default un-expanded height is reduced from 240px (10 LOC) to 120px (5 LOC), and (B) the link to the example is now positioned *over* the example instead of *atop* the example (only on desktop though, not mobile). The changes to `scrape-examples.js` and `rustdoc.css` implement this fix.
Here is what an example docblock now looks like:
![Screen Shot 2022-12-06 at 10 02 21 AM](https://user-images.githubusercontent.com/663326/205987450-3940063c-5973-4a34-8579-baff6a43aa9b.png)
### 2. Expanding all docblocks will not expand "More examples".
The "More examples blocks" are huge, so fully expanding everything on the page would take up too much vertical space. The changes to `main.js` implement this fix. This is tested in `scrape-examples-toggle.goml`.
### 3. Examples from binary crates are sorted higher than examples from library crates.
Code that is written as an example of an API is probably better for learning than code that happens to use an API, but isn't intended for pedagogic purposes. Unfortunately Rustc doesn't know whether a particular crate comes from an example target (only Cargo knows this). But we can at least create a proxy that prefers examples from binary crates over library crates, which we know from `--crate-type`.
This change is implemented by adding a new field `bin_crate` in `Options` (see `config.rs`). An `is_bin` field has been added to the scraped examples metadata (see `scrape_examples.rs`). Then the example sorting metric uses `is_bin` as the first entry of a lexicographic sort on `(is_bin, example_size, display_name)` (see `render/mod.rs`).
Note that in the future we can consider adding another flag like `--scrape-examples-cargo-target` that would pass target information from Cargo into the example metadata. But I'm proposing a less intrusive change for now.
### 4. The scrape-examples help page has been updated to reflect the latest Cargo interface.
See `scrape-examples-help.md`.
r? `@notriddle`
P.S. once this PR and rust-lang/cargo#11450 are merged, then I think the scrape-examples feature is officially ready for deployment on docs.rs!
Matthias Krüger [Fri, 9 Dec 2022 06:25:44 +0000 (07:25 +0100)]
Rollup merge of #105245 - RalfJung:align_to, r=Amanieu
attempt to clarify align_to docs
This is not intended the change the docs at all, but `@workingjubilee` said the current docs are incomprehensible to some people so this is an attempt to fix that. No idea if it helps, so -- feedback welcome.
(Please let's not use this to discuss *changing* the spec. Whoever wants to change the spec should please make a separate PR for that.)
bors [Fri, 9 Dec 2022 03:05:27 +0000 (03:05 +0000)]
Auto merge of #105456 - matthiaskrgr:rollup-yennygf, r=matthiaskrgr
Rollup of 10 pull requests
Successful merges:
- #104922 (Detect long types in E0308 and write them to disk)
- #105120 (kmc-solid: `std::sys` code maintenance)
- #105255 (Make nested RPIT inherit the parent opaque's generics.)
- #105317 (make retagging work even with 'unstable' places)
- #105405 (Stop passing -export-dynamic to wasm-ld.)
- #105408 (Add help for `#![feature(impl_trait_in_fn_trait_return)]`)
- #105423 (Use `Symbol` for the crate name instead of `String`/`str`)
- #105433 (CI: add missing line continuation marker)
- #105434 (Fix warning when libcore is compiled with no_fp_fmt_parse)
- #105441 (Remove `UnsafetyState`)
Wesley Wiser [Wed, 7 Dec 2022 18:48:34 +0000 (13:48 -0500)]
Don't generate pointer loads to spills unless necessary
In order for LLVM to correctly generate debuginfo for msvc, we sometimes
need to spill arguments to the stack and perform some direct & indirect
offsets into the value. Previously, this code always performed those
actions, even when not required as LLVM would clean it up during
optimization.
However, when MIR inlining is enabled, this can cause problems as the
operations occur prior to the spilled value being initialized. To solve
this, we first calculate the necessary offsets using just the type which
is side-effect free and does not alter the LLVM IR. Then, if we are in a
situation which requires us to generate the LLVM IR (and this situation
only occurs for arguments, not local variables) then we perform the same
calculation again, this time generating the appropriate LLVM IR as we
go.
Ramon de C Valle [Tue, 22 Nov 2022 05:29:00 +0000 (21:29 -0800)]
Add LLVM KCFI support to the Rust compiler
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to
the Rust compiler. It initially provides forward-edge control flow
protection for operating systems kernels for Rust-compiled code only by
aggregating function pointers in groups identified by their return and
parameter types. (See llvm/llvm-project@cff5bef.)
Forward-edge control flow protection for C or C++ and Rust -compiled
code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code
share the same virtual address space) will be provided in later work as
part of this project by identifying C char and integer type uses at the
time types are encoded (see Type metadata in the design document in the
tracking issue #89653).
Michael Howell [Fri, 9 Dec 2022 00:38:07 +0000 (17:38 -0700)]
rustdoc: remove no-op mobile CSS `#sidebar-toggle { text-align }`
Since 8b001b4da0716936e0ca32303cc0e3c5e53e42f8 make the sidebar toggle a
flex container, and already centers its content in desktop mode, this
rule doesn't do anything.
Arpad Borsos [Tue, 29 Nov 2022 22:17:08 +0000 (23:17 +0100)]
Fix Async Generator ABI
This change was missed when making async generators implement `Future` directly.
It did not cause any problems in codegen so far, as `GeneratorState<(), Output>`
happens to have the same ABI as `Poll<Output>`.
Dan Gohman [Thu, 8 Dec 2022 18:35:46 +0000 (10:35 -0800)]
Mangle "main" as "__main_void" on wasm32-wasi
On wasm, the age-old C trick of having a main function which can either have
no arguments or argc+argv doesn't work, because wasm requires caller and
callee signatures to match. WASI's current strategy is to have compilers
mangle main's name to indicate which signature they're using. Rust uses the
no-argument form, which should be mangled as `__main_void`.