Commit Graph

166355 Commits

Author SHA1 Message Date
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
bors
625e4dd13a Auto merge of #95125 - JakobDegen:uninit-variant-rvalue, r=oli-obk
Add new `Deinit` statement

This rvalue replaces `SetDiscriminant` for ADTs. This PR is an alternative to #94590 , which only specifies that the behavior of `SetDiscriminant` is the same as what this rvalue would do. The motivation for this change are discussed in that PR and [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/SetDiscriminant.20and.20aggregate.20initialization.20.2394590)

r? `@oli-obk`
2022-04-11 14:49:30 +00:00
Jakob Degen
2f03767eef Remove inlining cost of Deinit statements 2022-04-11 10:23:33 -04:00
Jakob Degen
48b01a0d0e Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
Jakob Degen
f7ca97a209 Add const eval tests ensuring padding gets correctly marked as deinit on deaggregation 2022-04-11 09:26:26 -04:00
Jakob Degen
2a040284a5 Fix tests broken by deaggregation change 2022-04-11 09:26:26 -04:00
Jakob Degen
fe796cd0f6 Bless tests that broke in a trivial way due to change in deaggregation 2022-04-11 09:26:26 -04:00
Takayuki Maeda
c4b83362c0 fix a bad error message for relative paths are not supported in visibilities error 2022-04-11 22:15:45 +09:00
Jakob Degen
4cbe13adab Document semantics of Deinit and SetDiscriminant MIR statements 2022-04-11 08:55:03 -04:00
Jakob Degen
9b6b1a625b Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
Mara Bos
8339381741 Use is_ or has_ prefix for pure -> bool functions. 2022-04-11 14:52:02 +02:00
Mara Bos
c4a4f48c52 Use compare_exchange_weak in futex rwlock implementation. 2022-04-11 14:29:32 +02:00
Mara Bos
1f2c2bb24f Add comments to futex rwlock implementation. 2022-04-11 14:27:06 +02:00
Mara Bos
7c28791565 Add doc comments to futex operations. 2022-04-11 14:26:52 +02:00
bors
43998d5441 Auto merge of #95931 - matthiaskrgr:rollup-1c5zhit, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #95743 (Update binary_search example to instead redirect to partition_point)
 - #95771 (Update linker-plugin-lto.md to 1.60)
 - #95861 (Note that CI tests Windows 10)
 - #95875 (bootstrap: show available paths help text for aliased subcommands)
 - #95876 (Add a note for unsatisfied `~const Drop` bounds)
 - #95907 (address fixme for diagnostic variable name)
 - #95917 (thin_box test: import from std, not alloc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-11 11:12:26 +00:00
Matthias Krüger
5b8e2ea520
Rollup merge of #95917 - RalfJung:thin-box-test, r=dtolnay
thin_box test: import from std, not alloc

Importing from `alloc` makes [Miri fail](https://github.com/rust-lang/miri-test-libstd/runs/5964922742?check_suite_focus=true), probably due to the hack that we used to resolve https://github.com/rust-lang/miri-test-libstd/issues/4. There might be better ways around this, but for now this is the easiest thing to do -- no other alloc integration test is importing from `alloc::`.
2022-04-11 12:06:58 +02:00
Matthias Krüger
053f70332f
Rollup merge of #95907 - compiler-errors:diag, r=Dylan-DPC
address fixme for diagnostic variable name

quick rename
2022-04-11 12:06:57 +02:00
Matthias Krüger
7ed15fb584
Rollup merge of #95876 - fee1-dead:note-const-drop, r=oli-obk
Add a note for unsatisfied `~const Drop` bounds

r? ``@oli-obk``
2022-04-11 12:06:56 +02:00
Matthias Krüger
69fb8f6349
Rollup merge of #95875 - aswild:pr/alias-cmd-paths, r=Mark-Simulacrum
bootstrap: show available paths help text for aliased subcommands

Running `./x.py build -h -v` shows a list of available build targets,
but the short alias `./x.py b -h -v` does not. Fix so that the aliases
behave the same as their spelled out counterparts.
2022-04-11 12:06:55 +02:00
Matthias Krüger
361a0ec3ab
Rollup merge of #95861 - ChrisDenton:windows7-support, r=Dylan-DPC
Note that CI tests Windows 10

Currently being [discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Windows.207).

r? `````@joshtriplett`````
2022-04-11 12:06:54 +02:00
Matthias Krüger
021738751a
Rollup merge of #95771 - str4d:update-linker-plugin-lto.md-to-1.60, r=pietroalbini
Update linker-plugin-lto.md to 1.60

I remembered this table when I was looking into what version of LLVM 1.60.0 was using 🙂
2022-04-11 12:06:53 +02:00
Matthias Krüger
e25bc303f1
Rollup merge of #95743 - yaahc:binary-search-clarification, r=Mark-Simulacrum
Update binary_search example to instead redirect to partition_point

Inspired by discussion in the tracking issue for `Result::into_ok_or_err`: https://github.com/rust-lang/rust/issues/82223#issuecomment-1067098167

People are surprised by us not providing a `Result<T, T> -> T` conversion, and the main culprit for this confusion seems to be the `binary_search` API. We should instead redirect people to the equivalent API that implicitly does that `Result<T, T> -> T` conversion internally which should obviate the need for the `into_ok_or_err` function and give us time to work towards a more general solution that applies to all enums rather than just `Result` such as making or_patterns usable for situations like this via postfix `match`.

I choose to duplicate the example rather than simply moving it from `binary_search` to partition point because most of the confusion seems to arise when people are looking at `binary_search`. It makes sense to me to have the example presented immediately rather than requiring people to click through to even realize there is an example. If I had to put it in only one place I'd leave it in `binary_search` and remove it from `partition_point` but it seems pretty obviously relevant to `partition_point` so I figured the best option would be to duplicate it.
2022-04-11 12:06:52 +02:00
bors
d00e77078c Auto merge of #95758 - compiler-errors:issue-54771, r=estebank
Only suggest removing semicolon when expression is compatible with `impl Trait`

https://github.com/rust-lang/rust/issues/54771#issuecomment-476423690
> It still needs checking that the last statement's expr can actually conform to the trait, but the naïve behavior is there.

Only suggest removing a semicolon when the type behind the semicolon actually implements the trait in an RPIT `-> impl Trait`. Also upgrade the label that suggests removing the semicolon to a suggestion (should it be verbose?).

cc #54771
2022-04-11 08:31:37 +00:00
Jakub Beránek
aeb3df76f6
CI: do not compile libcore twice when performing LLVM PGO 2022-04-11 10:05:05 +02:00
Giles Cope
3ee7bb19c6
better def of is signed in tests. 2022-04-11 07:37:53 +01:00
liangyongrui
03b2588837 fix Layout struct member naming style 2022-04-11 13:35:18 +08:00
bors
48a9e104df Auto merge of #95754 - compiler-errors:binder-assoc-ty, r=nagisa
Better error for `for<...>` on associated type bound

With GATs just around the corner, we'll probably see more people trying out `Trait<for<'a> Assoc<'a> = ..>`.

This PR improves the syntax error slightly, and also makes it slightly easier to make this into real syntax in the future.

Feel free to push back if the reviewer thinks this should have a suggestion on how to fix it (i.e. push the `for<'a>` outside of the angle brackets), but that can also be handled in a follow-up PR.
2022-04-11 05:16:48 +00:00
Michael Goulet
d2b1bb8a9b use find_ancestor_inside to get right span in CastCheck 2022-04-10 22:15:31 -07:00
Ralf Jung
dbc0afa215 thin_box test: import from std, not alloc 2022-04-10 22:59:51 -04:00
Deadbeef
7f54d68f26
Add a note for unsatisfied ~const Drop bounds 2022-04-11 12:00:39 +10:00
bors
d12b857816 Auto merge of #94243 - compiler-errors:compiler-flags-typo, r=Mark-Simulacrum
`s/compiler-flags/compile-flags` in compiletest

Also make compiletest panic so this doesn't happen in the future! I literally always forget which it's called, so I wanted to make my life easier in the future.

Also open to the possibility of parsing both.
2022-04-11 00:58:22 +00:00
Michael Howell
dae1df68b0 Fix test case for windows 2022-04-10 17:46:30 -07:00
Michael Goulet
b65265b5e1 better error for binder on associated type bound 2022-04-10 16:41:15 -07:00
Nicholas Nethercote
edd7f2cdab Add a useful comment. 2022-04-11 09:38:40 +10:00
Nicholas Nethercote
4ba609601f Tweak NamedMatch representation.
The `Lrc` isn't necessary, neither is the `SmallVec`. Performance is
changed negligibly, but the new code is simpler.
2022-04-11 09:38:40 +10:00
Nicholas Nethercote
482b25b321 Change internal naming of macros.
When a `macro_rules! foo { ... }` invocation is compiled the name used
is `foo`, not `macro_rules!`. This is different to all other macro
invocations, and confused me when I was inserted debugging println
statements for macro evaluation.

This commit changes it to `macro_rules` (or just `macro`), which is what
I expected. There are no externally visible changes.
2022-04-11 09:38:40 +10:00
Eric Huss
be23ead9a4 Fix crate_type attribute to not warn on duplicates 2022-04-10 16:35:37 -07:00
Michael Goulet
dfe13dbbcf only suggest removing semicolon when expr implements trait 2022-04-10 16:30:14 -07:00
Roc Yu
7feb7383d2
rustdoc: Reduce allocations in a theme function 2022-04-10 19:17:38 -04:00
Joshua Nelson
4c1438332b 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.
2022-04-10 17:15:31 -05:00
Joshua Nelson
986c1687f8 Remove duplicate aliases for codegen_{cranelift,gcc}
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.
2022-04-10 17:15:31 -05:00
bors
1f7fb6413d Auto merge of #95889 - Dylan-DPC:rollup-1cmywu4, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #95566 (Avoid duplication of doc comments in `std::char` constants and functions)
 - #95784 (Suggest replacing `typeof(...)` with an actual type)
 - #95807 (Suggest adding a local for vector to fix borrowck errors)
 - #95849 (Check for git submodules in non-git source tree.)
 - #95852 (Fix missing space in lossy provenance cast lint)
 - #95857 (Allow multiple derefs to be splitted in deref_separator)
 - #95868 (rustdoc: Reduce allocations in a `html::markdown` function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-10 21:01:13 +00:00
Christopher Durham
b92cd1a32c
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.
2022-04-10 15:04:57 -05:00
nyanpasu64
bb3a071df8
Fix formatting error in pin.rs docs 2022-04-10 12:41:31 -07:00
Luqman Aden
84fb481bf5 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. 2022-04-10 15:40:16 -04:00