Commit Graph

166535 Commits

Author SHA1 Message Date
Matthias Krüger
2836143380
Rollup merge of #95909 - vacuus:theme-build-rule, r=GuillaumeGomez
rustdoc: Reduce allocations in a `theme` function

`str::replace` allocates a new `String`...

This could probably be made more efficient, but I think it'd have to be clunky imperative code to achieve that.
2022-04-12 08:46:58 +02:00
Matthias Krüger
3ff5cb20b6
Rollup merge of #95881 - TaKO8Ki:use-to-string-instead-of-format, r=compiler-errors
Use `to_string` instead of `format!`
2022-04-12 08:46:57 +02:00
Matthias Krüger
a899ebd102
Rollup merge of #95722 - xu-cheng:pre-push, r=Mark-Simulacrum
pre-push.sh: Use python3 if python is not found

Since Python 2 has reached EOL, `python` may not be available in certain systems (e.g., recent macOS). We should use `python3` in this case to avoid error like `python: No such file or directory`.
2022-04-12 08:46:56 +02:00
Matthias Krüger
1d35179077
Rollup merge of #95320 - JakobDegen:mir-docs, r=oli-obk
Document the current MIR semantics that are clear from existing code

This PR adds documentation to places, operands, rvalues, statementkinds, and terminatorkinds that describes their existing semantics and requirements. In many places the semantics depend on the Rust memory model or other T-Lang decisions - when this is the case, it is just noted as such with links to UCG issues where possible. I'm hopeful that none of the documentation added here can be used to justify optimizations that depend on the memory model. The documentation for places and operands probably comes closest to running afoul of this - if people think that it cannot be merged as is, it can definitely also be taken out.

The goal here is to only document parts of MIR that seem to be decided already, or are at least depended on by existing code. That leaves quite a number of open questions - those are marked as "needs clarification." I'm not sure what to do with those in this PR - we obviously can't decide all these questions here. Should I just leave them in as is? Take them out? Keep them in but as `//` instead of `///` comments?

If this is too big to review at once, I can split this up.

r? rust-lang/mir-opt
2022-04-12 08:46:56 +02:00
Mara Bos
d4e44a6391 Add missing unsafe marker.
This is now necessary because of deny(unsafe_op_in_unsafe_fn).
2022-04-12 08:44:39 +02:00
Mara Bos
8a2c9a9615 Allow cvt_nz to be unused on some platforms. 2022-04-12 08:44:39 +02:00
Mara Bos
5b2591299a Add #[deny(unsafe_op_in_unsafe_fn)] to thread_local!(const).
This avoids 'unused unsafe' warnings when using this feature inside std.
2022-04-12 08:44:39 +02:00
Mara Bos
83e8b9e4dd Add debug asserts to futex ReentrantMutex impl. 2022-04-12 08:44:39 +02:00
Mara Bos
43651aa34f Initialize thread local with const{}. 2022-04-12 08:44:39 +02:00
Mara Bos
319a9b0f71 Move current_thread_unique_ptr to the only module that uses it. 2022-04-12 08:44:39 +02:00
Mara Bos
ebebe6f837 Make current_thread_unique_ptr work during thread destruction.
Otherwise we can't use println!() within atexit handlers etc.
2022-04-12 08:44:38 +02:00
Mara Bos
bd61bec67d Add futex-based ReentrantMutex on Linux. 2022-04-12 08:44:38 +02:00
Mara Bos
c62c8cb82d Add current_thread_unique_ptr() in std::sys_common. 2022-04-12 08:41:42 +02:00
bors
4e1927db3c Auto merge of #95399 - gilescope:plan_b, r=scottmcm
Faster parsing for lower numbers for radix up to 16 (cont.)

( Continuation of https://github.com/rust-lang/rust/pull/83371 )

With LingMan's change I think this is potentially ready.
2022-04-12 05:54:50 +00:00
bors
b8f4cb6231 Auto merge of #95893 - luqmana:no-prepopulate-passes-tweaks, r=nikic
Respect -Z verify-llvm-ir and other flags that add extra passes when combined with -C no-prepopulate-passes in the new LLVM Pass Manager.

As part of the switch to the new LLVM Pass Manager the behaviour of flags such as `-Z verify-llvm-ir` (e.g. sanitizer, instrumentation) was modified when combined with `-C no-prepopulate-passes`. With the old PM, rustc was the one manually constructing the pipeline and respected those flags but in the new pass manager, those flags are used to build a list of callbacks that get invoked at certain extension points in the pipeline. Unfortunately, `-C no-prepopulate-passes` would skip building the pipeline altogether meaning we'd never add the corresponding passes. The fix here is to just manually invoke those callbacks as needed.

Fixes #95874

Demonstrating the current vs fixed behaviour using the bug in #95864
```console
$ rustc +nightly asm-miscompile.rs --edition 2021 --emit=llvm-ir -C no-prepopulate-passes -Z verify-llvm-ir
$ echo $?
0
$ rustc +stage1 asm-miscompile.rs --edition 2021 --emit=llvm-ir -C no-prepopulate-passes -Z verify-llvm-ir
Basic Block in function '_ZN14asm_miscompile3foo28_$u7b$$u7b$closure$u7d$$u7d$17h360e2f7eee1275c5E' does not have terminator!
label %bb1
LLVM ERROR: Broken module found, compilation aborted!
```
2022-04-12 03:26:53 +00:00
Martin Pool
7cdef0876d Document that DirEntry holds the directory open 2022-04-11 19:00:29 -07:00
Jacob Pratt
2638e969c8
Bump stdarch 2022-04-11 21:40:31 -04:00
Luqman Aden
03bcbbf928 [bootstrap] Grab the right FileCheck binary for dist when cross-compiling. 2022-04-11 21:32:45 -04:00
bors
36f4ded69e Auto merge of #93408 - liangyongrui:master, r=scottmcm
fix Layout struct member naming style
2022-04-12 00:18:51 +00:00
AnthonyMikh
39e83c1e2a
fix broken link in coverage tools docs 2022-04-12 02:46:53 +03:00
Takayuki Maeda
29c41280a1 use to_string instead of format! 2022-04-12 07:51:23 +09:00
bors
de392c7d31 Auto merge of #95944 - Dylan-DPC:rollup-idggkrh, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #95008 ([`let_chains`] Forbid `let` inside parentheses)
 - #95801 (Replace RwLock by a futex based one on Linux)
 - #95864 (Fix miscompilation of inline assembly with outputs in cases where we emit an invoke instead of call instruction.)
 - #95894 (Fix formatting error in pin.rs docs)
 - #95895 (Clarify str::from_utf8_unchecked's invariants)
 - #95901 (Remove duplicate aliases for `check codegen_{cranelift,gcc}` and fix `build codegen_gcc`)
 - #95927 (CI: do not compile libcore twice when performing LLVM PGO)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-11 21:55:58 +00:00
Michael Howell
daa903c462 Fix line numbers 2022-04-11 13:02:50 -07:00
Oliver Downard
3b4589a309 simplify const params diagnostic on stable 2022-04-11 21:01:18 +01:00
Jakob Degen
8732bf5db3 Remove rule that place loads may not happen with variant index set 2022-04-11 15:56:04 -04:00
Jakob Degen
4bce639c3b Add more clarifications in response to Ralf's comments 2022-04-11 15:56:04 -04:00
Jakob Degen
411ae6f5ad Address various comments and change some details around place to value conversions 2022-04-11 15:22:32 -04:00
Jakob Degen
1d318e42e7 Improve MIR phases documentation with summaries of changes 2022-04-11 15:22:32 -04:00
Jakob Degen
f2d7908ff7 Adjust MIR validator to check a few more things for terminators 2022-04-11 15:22:32 -04:00
Jakob Degen
f1f25c0f81 Improve documentation for MIR terminators 2022-04-11 15:22:32 -04:00
Jakob Degen
8e01cd6127 Improve documentation for MIR statement kinds. 2022-04-11 15:22:29 -04:00
Jakob Degen
9ac5e986ed Extend the MIR validator to check many more things around rvalues. 2022-04-11 15:18:54 -04:00
Jakob Degen
634369170a Add documentation for the semantics of MIR rvalues 2022-04-11 15:18:54 -04:00
Jakob Degen
2f4a7a0742 Adjust computation of place types to detect more invalid places 2022-04-11 15:18:53 -04:00
Jakob Degen
dae5c842fc Improve documentation of Place and Operand 2022-04-11 15:18:53 -04:00
Josh Stone
2d5eda8fb0 Use const Box::default in P::<[T]>::new 2022-04-11 12:14:18 -07:00
Josh Stone
a2902ebe57 impl const Default for Box<[T]> and Box<str> 2022-04-11 12:14:18 -07:00
Cheng XU
365d4f4fd0
pre-push.sh: Use python3 if python is not found
Since Python 2 has reached EOL, `python` may not be available in certain
systems (e.g., recent macOS). We should use `python3` in this case to
avoid error like `python: No such file or directory`.
2022-04-11 12:02:40 -07:00
bors
90ca44752a Auto merge of #95796 - bzEq:bzEq/curl-redirect, r=Dylan-DPC
[bootstrap.py] Instruct curl to follow redirect

Some mirror RUSTUP_DIST_SERVER (like https://mirrors.sjtug.sjtu.edu.cn/rust-static) perform redirection when downloading
stage0 compiler. Curl should be able to follow that.
2022-04-11 18:59:40 +00:00
Dylan DPC
070e8ed18d
Rollup merge of #95927 - Kobzol:ci-pgo-libcore, r=lqd
CI: do not compile libcore twice when performing LLVM PGO

I forgot the delete the first compilation when modifying this file in a previous PR.

r? ```@lqd```
2022-04-11 20:00:46 +02:00
Dylan DPC
ec95e7d2a5
Rollup merge of #95901 - jyn514:remove-duplicate-aliases, r=Mark-Simulacrum
Remove duplicate aliases for `check codegen_{cranelift,gcc}` and fix `build codegen_gcc`

* Remove duplicate aliases
    Bootstrap already allows selecting these in `PathSet::has`, which allows
    any string that matches the end of a full path.

    I found these by adding `assert!(path.exists())` in `StepDescription::paths`.
    I think ideally we wouldn't have any aliases that aren't paths, but I've held
    off on enforcing that here since it may be controversial, I'll open a separate PR.

* Add `build compiler/rustc_codegen_gcc` as an alias for `CodegenBackend`

    These paths (`_cranelift` and `_gcc`) are somewhat misleading, since they
    actually tell bootstrap to build *all* codegen backends. But this seems like
    a useful improvement in the meantime.

cc ```@bjorn3``` ```@antoyo```
2022-04-11 20:00:45 +02:00
Dylan DPC
ae6f75a0c3
Rollup merge of #95895 - CAD97:patch-2, r=Dylan-DPC
Clarify str::from_utf8_unchecked's invariants

Specifically, make it clear that it is immediately UB to pass ill-formed UTF-8 into the function. The previous wording left space to interpret that the UB only occurred when calling another function, which "assumes that `&str`s are valid UTF-8."

This does not change whether str being UTF-8 is a safety or a validity invariant. (As per previous discussion, it is a safety invariant, not a validity invariant.) It just makes it clear that valid UTF-8 is a precondition of str::from_utf8_unchecked, and that emitting an Abstract Machine fault (e.g. UB or a sanitizer error) on invalid UTF-8 is a valid thing to do.

If user code wants to create an unsafe `&str` pointing to ill-formed UTF-8, it must be done via transmutes. Also, just, don't.

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/str.3A.3Afrom_utf8_unchecked.20Safety.20requirement
2022-04-11 20:00:44 +02:00
Dylan DPC
82a6463b1c
Rollup merge of #95894 - nyanpasu64:fix-pin-docs, r=Dylan-DPC
Fix formatting error in pin.rs docs

Not sure if there's more formatting issues I missed; I kinda lost interest reading midway through.
2022-04-11 20:00:43 +02:00
Dylan DPC
3f606ceaec
Rollup merge of #95864 - luqmana:inline-asm-unwind-store-miscompile, r=Amanieu
Fix miscompilation of inline assembly with outputs in cases where we emit an invoke instead of call instruction.

We ran into this bug where rustc would segfault while trying to compile certain uses of inline assembly.

Here is a simple repro that demonstrates the issue:
```rust
#![feature(asm_unwind)]

fn main() {
    let _x = String::from("string here just cause we need something with a non-trivial drop");
    let foo: u64;
    unsafe {
        std::arch::asm!(
            "mov {}, 1",
            out(reg) foo,
            options(may_unwind)
        );
    }
    println!("{}", foo);
}
```
([playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=7d6641e83370d2536a07234aca2498ff))

But crucially `feature(asm_unwind)` is not actually needed and this can be triggered on stable as a result of the way async functions/generators are handled in the compiler. e.g.:

```rust
extern crate futures; // 0.3.21

async fn bar() {
    let foo: u64;
    unsafe {
        std::arch::asm!(
            "mov {}, 1",
            out(reg) foo,
        );
    }
    println!("{}", foo);
}

fn main() {
    futures::executor::block_on(bar());
}
```
([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1c7781c34dd4a3e80ae4bd936a0c82fc))

An example of the incorrect LLVM generated:
```llvm
bb1:                                              ; preds = %start
  %1 = invoke i64 asm sideeffect alignstack inteldialect unwind "mov ${0:q}, 1", "=&r,~{dirflag},~{fpsr},~{flags},~{memory}"()
          to label %bb2 unwind label %cleanup, !srcloc !9
  store i64 %1, i64* %foo, align 8

bb2:
[...snip...]
```

The store should not be placed after the asm invoke but rather should be in the normal control flow basic block (`bb2` in this case).

[Here](https://gist.github.com/luqmana/be1af5b64d2cda5a533e3e23a7830b44) is a writeup of the investigation that lead to finding this.
2022-04-11 20:00:42 +02:00
Dylan DPC
a15ac30162
Rollup merge of #95801 - m-ou-se:futex-rwlock, r=Amanieu
Replace RwLock by a futex based one on Linux

This replaces the pthread-based RwLock on Linux by a futex based one.

This implementation is similar to [the algorithm](https://gist.github.com/kprotty/3042436aa55620d8ebcddf2bf25668bc) suggested by `@kprotty,` but modified to prefer writers and spin before sleeping. It uses two futexes: One for the readers to wait on, and one for the writers to wait on. The readers futex contains the state of the RwLock: The number of readers, a bit indicating whether writers are waiting, and a bit indicating whether readers are waiting. The writers futex is used as a simple condition variable and its contents are meaningless; it just needs to be changed on every notification.

Using two futexes rather than one has the obvious advantage of allowing a separate queue for readers and writers, but it also means we avoid the problem a single-futex RwLock would have of making it hard for a writer to go to sleep while the number of readers is rapidly changing up and down, as the writers futex is only changed when we actually want to wake up a writer.

It always prefers writers, as we decided [here](https://github.com/rust-lang/rust/issues/93740#issuecomment-1070696128).

To be able to prefer writers, it relies on futex_wake to return the number of awoken threads to be able to handle write-unlocking while both the readers-waiting and writers-waiting bits are set. Instead of waking both and letting them race, it first wakes writers and only continues to wake the readers too if futex_wake reported there were no writers to wake up.

r? `@Amanieu`
2022-04-11 20:00:41 +02:00
Dylan DPC
2ad701e450
Rollup merge of #95008 - c410-f3r:let-chains-paren, r=wesleywiser
[`let_chains`] Forbid `let` inside parentheses

Parenthesizes are mostly a no-op in let chains, in other words, they are mostly ignored.

```rust
let opt = Some(Some(1i32));

if (let Some(a) = opt && (let Some(b) = a)) && b == 1 {
    println!("`b` is declared inside but used outside");
}
```

As seen above, such behavior can lead to confusion.

A proper fix or nested encapsulation would probably require research, time and a modified MIR graph so in this PR I simply denied any `let` inside parentheses. Non-let stuff are still allowed.

```rust
fn main() {
    let fun = || true;

    if let true = (true && fun()) && (true) {
        println!("Allowed");
    }
}
```

It is worth noting that `let ...`  is not an expression and the RFC did not mention this specific situation.

cc `@matthewjasper`
2022-04-11 20:00:40 +02:00
O01eg
3f4bbd50fd
Fix documentation for wasm32-unknown-unknown 2022-04-11 19:16:51 +03:00
Rémy Rakic
734adb3a1a update ui tests using opaque types in impl headers 2022-04-11 15:12:54 +00:00
Rémy Rakic
d652cd4959 add regression tests for opaque types in impl headers 2022-04-11 15:11:27 +00:00
Rémy Rakic
7d5bbf55f2 prevent opaque types from appearing in impl headers 2022-04-11 15:11:27 +00:00