Commit graph

132202 commits

Author SHA1 Message Date
Ralf Jung 0e014be359 move UnsafeCell-in-const check from interning to validation 2020-10-26 08:56:54 +01:00
Ralf Jung d0a23e613d ensure we intern all promoteds as InternKind::Promoted 2020-10-26 08:56:54 +01:00
bors 69e68cf550 Auto merge of #75728 - nagisa:improve_align_offset_2, r=Mark-Simulacrum
Optimise align_offset for stride=1 further

`stride == 1` case can be computed more efficiently through `-p (mod
a)`. That, then translates to a nice and short sequence of LLVM
instructions:

    %address = ptrtoint i8* %p to i64
    %negptr = sub i64 0, %address
    %offset = and i64 %negptr, %a_minus_one

And produces pretty much ideal code-gen when this function is used in
isolation.

Typical use of this function will, however, involve use of
the result to offset a pointer, i.e.

    %aligned = getelementptr inbounds i8, i8* %p, i64 %offset

This still looks very good, but LLVM does not really translate that to
what would be considered ideal machine code (on any target). For example
that's the codegen we obtain for an unknown alignment:

    ; x86_64
    dec     rsi
    mov     rax, rdi
    neg     rax
    and     rax, rsi
    add     rax, rdi

In particular negating a pointer is not something that’s going to be
optimised for in the design of CISC architectures like x86_64. They
are much better at offsetting pointers. And so we’d love to utilize this
ability and produce code that's more like this:

    ; x86_64
    lea     rax, [rsi + rdi - 1]
    neg     rsi
    and     rax, rsi

To achieve this we need to give LLVM an opportunity to apply its
various peep-hole optimisations that it does during DAG selection. In
particular, the `and` instruction appears to be a major inhibitor here.
We cannot, sadly, get rid of this load-bearing operation, but we can
reorder operations such that LLVM has more to work with around this
instruction.

One such ordering is proposed in #75579 and results in LLVM IR that
looks broadly like this:

    ; using add enables `lea` and similar CISCisms
    %offset_ptr = add i64 %address, %a_minus_one
    %mask = sub i64 0, %a
    %masked = and i64 %offset_ptr, %mask
    ; can be folded with `gepi` that may follow
    %offset = sub i64 %masked, %address

…and generates the intended x86_64 machine code.
One might also wonder how the increased amount of code would impact a
RISC target. Turns out not much:

    ; aarch64 previous                 ; aarch64 new
    sub     x8, x1, #1                 add     x8, x1, x0
    neg     x9, x0                     sub     x8, x8, #1
    and     x8, x9, x8                 neg     x9, x1
    add     x0, x0, x8                 and     x0, x8, x9

    (and similarly for ppc, sparc, mips, riscv, etc)

The only target that seems to do worse is… wasm32.

Onto actual measurements – the best way to evaluate snipets like these
is to use llvm-mca. Much like Aarch64 assembly would allow to suspect,
there isn’t any performance difference to be found. Both snippets
execute in same number of cycles for the CPUs I tried. On x86_64,
we get throughput improvement of >50%!

Fixes #75579
2020-10-26 06:49:34 +00:00
bors 1cd97cad6e Auto merge of #78387 - Dylan-DPC:rollup-ch0st6z, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #74477 (`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm)
 - #77836 (transmute_copy: explain that alignment is handled correctly)
 - #78126 (Properly define va_arg and va_list for aarch64-apple-darwin)
 - #78137 (Initialize tracing subscriber in compiletest tool)
 - #78161 (Add issue template link to IRLO)
 - #78214 (Tweak match arm semicolon removal suggestion to account for futures)
 - #78247 (Fix #78192)
 - #78252 (Add codegen test for #45964)
 - #78268 (Do not try to report on closures to avoid ICE)
 - #78295 (Add some regression tests)

Failed merges:

r? `@ghost`
2020-10-26 04:34:46 +00:00
Dylan DPC c8e0f4d90b
Rollup merge of #78295 - Alexendoo:ice-regression-tests, r=nagisa
Add some regression tests

Closes #56229
Closes #59494
Closes #70746
Closes #73229
2020-10-26 03:09:13 +01:00
Dylan DPC 463b6cc0e1
Rollup merge of #78268 - JohnTitor:issue-78262, r=estebank
Do not try to report on closures to avoid ICE

Fixes #78262
2020-10-26 03:09:11 +01:00
Dylan DPC 752bce5197
Rollup merge of #78252 - bugadani:issue-45964, r=Mark-Simulacrum
Add codegen test for #45964

Closes #45964
2020-10-26 03:09:09 +01:00
Dylan DPC 8646c2a15b
Rollup merge of #78247 - simonvandel:fix-78192, r=oli-obk
Fix #78192

Check which places are marked dead.

Fixes #78192
2020-10-26 03:09:08 +01:00
Dylan DPC 083a5cd9a2
Rollup merge of #78214 - estebank:match-semicolon, r=oli-obk
Tweak match arm semicolon removal suggestion to account for futures

* Tweak and extend "use `.await`" suggestions
* Suggest removal of semicolon on prior match arm
* Account for `impl Future` when suggesting semicolon removal
* Silence some errors when encountering `await foo()?` as can't be certain what the intent was

*Thanks to https://twitter.com/a_hoverbear/status/1318960787105353728 for pointing this out!*
2020-10-26 03:09:06 +01:00
Dylan DPC 9e907d420e
Rollup merge of #78161 - jonas-schievink:irlo-issue-link, r=Mark-Simulacrum
Add issue template link to IRLO
2020-10-26 03:09:04 +01:00
Dylan DPC efbbdac163
Rollup merge of #78137 - tmiasko:compiletest-tracing, r=Mark-Simulacrum
Initialize tracing subscriber in compiletest tool

The logging in compiletest was migrated from log crate to a tracing, but
the initialization code was never changed, so logging is non-functional.

Initialize tracing subscriber using default settings.
2020-10-26 03:09:02 +01:00
Dylan DPC 147a001fd3
Rollup merge of #78126 - shepmaster:aarch64-apple-darwin-valist, r=nagisa
Properly define va_arg and va_list for aarch64-apple-darwin

From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-26 03:09:00 +01:00
Dylan DPC 9885232019
Rollup merge of #77836 - RalfJung:transmute_copy, r=Mark-Simulacrum
transmute_copy: explain that alignment is handled correctly

The doc comment currently is somewhat misleading because if it actually transmuted `&T` to `&U`, a higher-aligned `U` would be problematic.
2020-10-26 03:08:58 +01:00
Dylan DPC e0c08ae4e1
Rollup merge of #74477 - chansuke:sys-wasm-unsafe-op-in-unsafe-fn, r=Mark-Simulacrum
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm

This is part of #73904.

This encloses unsafe operations in unsafe fn in `libstd/sys/wasm`.

@rustbot modify labels: F-unsafe-block-in-unsafe-fn
2020-10-26 03:08:56 +01:00
bors 16e9ed0b1c Auto merge of #77283 - estebank:if-let-sugg, r=Mark-Simulacrum
Tweak `if let` suggestion to be more liberal with suggestion and to not ICE

Fix #77218. Fix #77238.
2020-10-26 01:53:51 +00:00
Jake Goulding 0a91755ff4 Properly define va_arg and va_list for aarch64-apple-darwin
From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-25 21:37:01 -04:00
Esteban Küber ff61949860 Tweak invalid fn header and body parsing
* Recover empty `fn` bodies when encountering `}`
* Recover trailing `>` in return types
* Recover from non-type in array type `[<BAD TOKEN>; LEN]`
2020-10-25 18:34:14 -07:00
Tomasz Miąsko 124b63acf3 simplify-locals: Add yet to be optimized test cases 2020-10-26 00:00:00 +00:00
bors b6ac411f45 Auto merge of #78015 - ssomers:btree_merge_mergers, r=Mark-Simulacrum
btree: merge the implementations of MergeIter

Also remove the gratuitous Copy bounds. Same benchmark performance.

r? `@Mark-Simulacrum`
2020-10-25 22:29:02 +00:00
Esteban Küber cabf6d0523 Tweak if let suggestion to be more liberal with suggestion and to not ICE
Fix #77218. Fix #77238.
2020-10-25 15:21:14 -07:00
Taiki Endo 04c0018d1b Use ? in core/std macros 2020-10-26 07:15:37 +09:00
est31 6c9b8ada0c Precompute the associated items
The associated_items(def_id) call
allocates internally.
Previously, we'd have called it for
each pair, so we'd have had O(n^2)
many calls. By precomputing the
associated items, we avoid
repeating so many allocations.

The only instance where this precomputation
would be a regression is if there's only
one inherent impl block for the type,
as the inner loop then doesn't run.
In that instance, we just early return.

Also, use SmallVec to avoid doing an
allocation at all if the number is small
(the case for most impl blocks out there).
2020-10-25 22:50:48 +01:00
bors 4760b8fb88 Auto merge of #78179 - RalfJung:miri-comments, r=oli-obk
Miri engine: entirely skip interning of ZST, and improve some comments

r? `@oli-obk`
2020-10-25 20:15:44 +00:00
LeSeulArtichaut 9de15188b0 Fix typo in debug statement 2020-10-25 20:54:44 +01:00
Esteban Küber 040f568815 Rely on regular "expected"/"found" parser error for fn 2020-10-25 12:13:27 -07:00
Bastian Kauschke 0e419efb1c check for object safety violations in constants 2020-10-25 18:33:45 +01:00
Bastian Kauschke 9dadcf8370 warn -> debug in collect 2020-10-25 18:05:18 +01:00
bors 0dce3f606e Auto merge of #77901 - jonas-schievink:unignore-test-36710, r=Mark-Simulacrum
Unignore test for #36710 on MUSL

This now works fine thanks to autodetected `-C link-self-contained`.

Closes #36710
2020-10-25 16:37:01 +00:00
Tim Diekmann 06e4497a04 Merge remote-tracking branch 'upstream/master' into box-alloc 2020-10-25 16:32:28 +01:00
bors 430feb24a4 Auto merge of #78253 - Aaron1011:bump-llvm-deadarg, r=cuviper
Bump LLVM for DeadArgElim fix

Fixes #76387

Pulls in https://github.com/rust-lang/llvm-project/pull/82
2020-10-25 14:17:26 +00:00
Ralf Jung 3bd5cc900c also test non-extern uninhabited statics 2020-10-25 15:01:52 +01:00
bjorn3 8ec977e763 Replace write with write_all 2020-10-25 13:33:39 +01:00
bors f392479de6 Auto merge of #78350 - JohnTitor:rollup-vbbm5wf, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #77984 (Compute proper module parent during resolution)
 - #78085 (MIR validation should check `SwitchInt` values are valid for the type)
 - #78208 (replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s)
 - #78209 (Update `compiler_builtins` to 0.1.36)
 - #78276 (Bump backtrace-rs to enable Mach-O support on iOS.)
 - #78320 (Link to cargo's `build-std` feature instead of `xargo` in custom target docs)
 - #78322 (BTreeMap: stop mistaking node::MIN_LEN for a node level constraint)
 - #78326 (Split out statement attributes changes from #78306)

Failed merges:

r? `@ghost`
2020-10-25 11:35:26 +00:00
Olivier FAURE 666afba684 Update description for error E0308
As per #76462
2020-10-25 12:20:25 +01:00
Yuki Okushi 0a26e4ba7e
Rollup merge of #78326 - Aaron1011:fix/min-stmt-lints, r=petrochenkov
Split out statement attributes changes from #78306

This is the same as PR https://github.com/rust-lang/rust/pull/78306, but `unused_doc_comments` is modified to explicitly ignore statement items (which preserves the current behavior).

This shouldn't have any user-visible effects, so it can be landed without lang team discussion.

---------
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-25 18:43:49 +09:00
Yuki Okushi 9085656512
Rollup merge of #78322 - ssomers:btree_no_min_len_at_node_level, r=Mark-Simulacrum
BTreeMap: stop mistaking node::MIN_LEN for a node level constraint

Correcting #77612 that fell into the trap of assuming that node::MIN_LEN is an imposed minimum everywhere, and trying to make it much more clear it is an offered minimum at the node level.

r? @Mark-Simulacrum
2020-10-25 18:43:47 +09:00
Yuki Okushi 63e48cd410
Rollup merge of #78320 - phil-opp:patch-5, r=GuillaumeGomez,alexcrichton
Link to cargo's `build-std` feature instead of `xargo` in custom target docs

The `xargo` tool is in maintenance mode since 2018 and the `build-std` feature of cargo already works reasonably well for most use cases.
2020-10-25 18:43:45 +09:00
Yuki Okushi 3e017c709d
Rollup merge of #78276 - cutsoy:bump-backtrace, r=nagisa
Bump backtrace-rs to enable Mach-O support on iOS.

Related to rust-lang/backtrace-rs#378. Fixes backtraces on iOS that were missing in Rust v1.47.0 after switching to gimli because it only enabled Mach-O support on macOS.
2020-10-25 18:43:44 +09:00
Yuki Okushi e00e611c28
Rollup merge of #78209 - JohnTitor:compiler-builtins, r=Amanieu
Update `compiler_builtins` to 0.1.36

So, the libc build with cargo's `build-std` feature emits a lot of warnings like:
```
 warning: a method with this name may be added to the standard library in the future
   --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.35/src/int/udiv.rs:98:23
    |
98  |             q = n << (<$ty>::BITS - sr);
    |                       ^^^^^^^^^^^
...
268 |         udivmod_inner!(n, d, rem, u128)
    |         ------------------------------- in this macro invocation
    |
    = warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <rust-lang/rust/issues/48919>
    = help: call with fully qualified syntax `Int::BITS(...)` to keep using the current method
    = help: add `#![feature(int_bits_const)]` to the crate attributes to enable `num::<impl u128>::BITS`
    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
```

(You can find the full log in https://github.com/rust-lang/libc/runs/1283695796?check_suite_focus=true for example.)

0.1.36 contains https://github.com/rust-lang/compiler-builtins/pull/332 so this version should remove this warning.

cc https://github.com/rust-lang/libc/issues/1942
2020-10-25 18:43:42 +09:00
Yuki Okushi 72e02b015e
Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obk
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s

`#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks.
While it was originally only meant to be used only on macros, its use was expanded to `const fn`s.

This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s.

This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540).

Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'.

Closes rust-lang/rust#69399

r? @oli-obk
2020-10-25 18:43:40 +09:00
Yuki Okushi dbdc61f9f9
Rollup merge of #78085 - wesleywiser:mir_validation_switch_int, r=oli-obk
MIR validation should check `SwitchInt` values are valid for the type

Fixes #75440
2020-10-25 18:43:38 +09:00
Yuki Okushi 569d29d55c
Rollup merge of #77984 - Aaron1011:fix/macro-mod-weird-parent, r=petrochenkov
Compute proper module parent during resolution

Fixes #75982

The direct parent of a module may not be a module
(e.g. `const _: () =  { #[path = "foo.rs"] mod foo; };`).

To find the parent of a module for purposes of resolution, we need to
walk up the tree until we hit a module or a crate root.
2020-10-25 18:43:37 +09:00
Yuki Okushi 4f34537708 Fix small typos 2020-10-25 18:35:24 +09:00
Yuki Okushi 88d39673d7 Use its own TypeckResults to avoid ICE 2020-10-25 18:35:24 +09:00
bors 5171cc76c2 Auto merge of #77476 - tgnottingham:buffered_siphasher128, r=nnethercote
perf: buffer SipHasher128

This is an attempt to improve Siphasher128 performance by buffering input. Although it reduces instruction count, I'm not confident the effect on wall times, or lack-thereof, is worth the change.

---

Additional notes not reflected in source comments:

* Implementation choices were guided by a combination of results from rustc-perf and micro-benchmarks, mostly the former.
* ~~I tried a couple of different struct layouts that might be more cache friendly with no obvious effect.~~ Update: a particular struct layout was chosen, but it's not critical to performance. See comments in source and discussion below.
* I suspect that buffering would be important to a SIMD-accelerated algorithm, but from what I've read and my own tests, SipHash does not seem very amenable to SIMD acceleration, at least by SSE.
2020-10-25 09:23:45 +00:00
Joshua Nelson e2183801b5 Make some functions private that don't have to be public 2020-10-25 05:19:46 -04:00
bors 3e0dd24a6c Auto merge of #77546 - lcnr:impl-trait-closure, r=eddyb
fix def collector for impl trait

fixes #77329

We now consistently make `impl Trait` a hir owner, requiring some special casing for synthetic generic params.

r? `@eddyb`
2020-10-25 07:03:58 +00:00
bors 17cc9b6256 Auto merge of #77398 - wesleywiser:measureme_0_8, r=Mark-Simulacrum
Upgrade to measureme 9.0.0

I believe I did this correctly but there's still a reference to `measureme@0.7.1` coming from `rustc-ap-rustc_data_structures` and I'm not sure how to resolve that.

r? `@Mark-Simulacrum`

We'll also need to deploy the new version of the tools on perf.rlo.
2020-10-25 04:48:37 +00:00
Yuki Okushi 4ec396ea5d Test with NLL explicitly 2020-10-25 11:43:26 +09:00
Wesley Wiser 5ac5556d63 Upgrade to measureme 9.0.0 2020-10-24 22:39:42 -04:00