Commit Graph

1132 Commits

Author SHA1 Message Date
Dylan MacKenzie 37f37dc5ba Emit multiple function pointer errors from const-checker 2020-09-29 19:20:33 -07:00
Dylan MacKenzie b400871b9c Don't emit duplicate errors for the return place 2020-09-29 19:20:33 -07:00
Dylan MacKenzie 5b3145574e Priority levels 2020-09-29 19:20:33 -07:00
Dylan MacKenzie a23297f5c0 Bless mut tests 2020-09-29 19:20:33 -07:00
Dylan MacKenzie b518ccb4c3 Give `MutDeref` a real error message 2020-09-29 19:20:33 -07:00
Dylan MacKenzie de35c4293d Remove `ops::non_const`
This helper function was meant to reduce code duplication between
const-checking pre- and post-drop-elaboration. Most of the functionality
is only relevant for the pre-drop-elaboration pass.
2020-09-29 19:20:33 -07:00
Dylan MacKenzie ce50939952 Fix "unstable in stable" error
The "otherwise" note is printed before the suggestion currently.
2020-09-29 19:20:33 -07:00
Dylan MacKenzie 782a595d7c Return a `DiagnosticBuilder` from structured errors
This ensures that `emit_error` will actually cause compilation to fail.
2020-09-29 19:20:33 -07:00
Dylan MacKenzie 20e07e7b8e Forbid generator-specific MIR in all const-contexts 2020-09-29 19:20:33 -07:00
Dylan MacKenzie c38aca0502 `delay_span_bug` if const-checking an `async` function
This errors during AST lowering. Any errors we emit here are just noise.
2020-09-29 19:20:33 -07:00
Dylan MacKenzie 25c7753eee Continue after `impl Trait` in `const fn` 2020-09-29 19:13:11 -07:00
Dylan MacKenzie 325b7d42ec Continue const-checking after errors when easy
This doesn't change any UI test output
2020-09-29 17:38:28 -07:00
Dylan MacKenzie 4d343a5e59 Useful derives on `mir::LocalKind` 2020-09-29 17:38:28 -07:00
Tomasz Miąsko 93e3db30e9 liveness: Use Option::None to represent absent live nodes
No functional changes intended.
2020-09-30 00:00:00 +00:00
Tomasz Miąsko 924e8aaaf2 Liveness analysis for everybody
Perform liveness analysis for every body instead of limiting it to fns.
2020-09-29 23:45:31 +02:00
bors 381b445ff5 Auto merge of #77274 - tmiasko:liveness-cnd, r=lcnr
Liveness refactoring continued

* Move body_owner field from IrMaps to Liveness (the only user of the field).
* Use upvars instead of FnKind to check for closures (avoids FnKind, will be useful when checking all bodies, not just fns).
* Use visit_param to add variables corresponding to params.
* Store upvars_mentioned inside Liveness struct.
* Inline visitor implementation for IrMaps, avoiding unnecessary indirection.
* Test interaction with automatically_derived attribute (not covered by any of existing tests).

No functional changes intended.
2020-09-29 19:25:10 +00:00
David Wood 9ef68f53e1
resolve: improve "try using the enum's variant"
This commit improves the "try using the enum's variant" suggestion:

- Variants in suggestions would not result in more errors (e.g. use
  of a struct variant is only suggested if the suggestion can
  trivially construct that variant). Therefore, suggestions are only
  emitted for variants that have no fields (since the suggestion
  can't know what value fields would have).
- Suggestions include the syntax for constructing the variant. If a
  struct or tuple variant is suggested, then it is constructed in the
  suggestion - unless in pattern-matching or when arguments are already
  provided.
- A help message is added which mentions the variants which are no
  longer suggested.

Signed-off-by: David Wood <david@davidtw.co>
2020-09-29 16:52:43 +01:00
bors 4d52dc4790 Auto merge of #76754 - varkor:diagnostic-cleanup-ii, r=ecstatic-morse
Clean up diagnostics for arithmetic operation errors

Plus a small tweak to a range pattern error message.
2020-09-29 14:28:58 +00:00
bors 26373fb4ba Auto merge of #77275 - petrochenkov:interpid, r=varkor
expand: Stop normalizing `NtIdent`s before passing them to built-in macros

Built-in macros should be able to deal with `NtIdents` in the input by themselves like any other parser code.

You can't imagine how bad mutable AST visitors are, *especially* if they are modifying tokens.
This is one step towards removing token visiting from the visitor infrastructure (https://github.com/rust-lang/rust/pull/77271 also works in this direction.)
2020-09-29 05:14:36 +00:00
Aaron Hill c6107c53d7
Don't fire `const_item_mutation` lint on writes through a pointer
Fixes #77321
2020-09-28 23:51:57 -04:00
bors 48cab67447 Auto merge of #77257 - ecstatic-morse:optimize-int-range-from-pat, r=Mark-Simulacrum
Optimize `IntRange::from_pat`, then shrink `ParamEnv`

Resolves #77058.

r? `@Mark-Simulacrum`
cc `@vandenheuvel`

Looking at the output of `perf report` for #76244, the hot instructions seemed to be around the call to `pat_constructor` in `IntRange::from_pat`. I carried out an obvious optimization, but it actually made the instruction count higher (see #77075). However, it seems to have mitigated whatever was causing the pipeline stalls, so when combined with #76244, it's a net win.

As you can see below, the regression in #76244 seems to have originated from something measured by `stalled-cycles-backend`. I'll try to collect some finer-grained stats to see if I can isolate it. I wish I had a better idea of what was going on here. I'd like to prevent the regression from reappearing in the future due to small changes in unrelated code.

<details>
<summary>Current `master`:</summary>

```
 Performance counter stats for 'cargo +baseline-stage1 check':

          2,275.67 msec task-clock:u              #    0.998 CPUs utilized
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
            49,826      page-faults:u             #    0.022 M/sec
     5,117,221,678      cycles:u                  #    2.249 GHz
       299,655,943      stalled-cycles-frontend:u #    5.86% frontend cycles idle
     2,284,213,395      stalled-cycles-backend:u  #   44.64% backend cycles idle
     8,051,871,959      instructions:u            #    1.57  insn per cycle
                                                  #    0.28  stalled cycles per insn
     1,359,589,402      branches:u                #  597.447 M/sec
         7,359,347      branch-misses:u           #    0.54% of all branches

       2.281030026 seconds time elapsed

       2.108197000 seconds user
       0.164183000 seconds sys
```
</details>

<details>
<summary>Shrink `ParamEnv` without changing `IntRange::from_pat`:</summary>

```
 Performance counter stats for 'cargo +perf-stage1 check':

          2,751.79 msec task-clock:u              #    0.996 CPUs utilized
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
            50,103      page-faults:u             #    0.018 M/sec
     6,260,590,019      cycles:u                  #    2.275 GHz
       317,355,920      stalled-cycles-frontend:u #    5.07% frontend cycles idle
     3,397,743,582      stalled-cycles-backend:u  #   54.27% backend cycles idle
     8,276,224,367      instructions:u            #    1.32  insn per cycle
                                                  #    0.41  stalled cycles per insn
     1,370,453,386      branches:u                #  498.023 M/sec
         7,281,031      branch-misses:u           #    0.53% of all branches

       2.763265838 seconds time elapsed

       2.544578000 seconds user
       0.204548000 seconds sys
```
</details>

<details>
<summary>Shrink `ParamEnv` and change `IntRange::from_pat`: </summary>

```
 Performance counter stats for 'cargo +perf-stage1 check':

          2,295.57 msec task-clock:u              #    0.996 CPUs utilized
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
            49,959      page-faults:u             #    0.022 M/sec
     5,151,407,066      cycles:u                  #    2.244 GHz
       324,517,829      stalled-cycles-frontend:u #    6.30% frontend cycles idle
     2,301,671,001      stalled-cycles-backend:u  #   44.68% backend cycles idle
     8,130,868,329      instructions:u            #    1.58  insn per cycle
                                                  #    0.28  stalled cycles per insn
     1,356,618,512      branches:u                #  590.972 M/sec
         7,323,800      branch-misses:u           #    0.54% of all branches

       2.304509653 seconds time elapsed

       2.128090000 seconds user
       0.163909000 seconds sys
```
</details>
2020-09-29 02:29:13 +00:00
Aaron Hill 46d8c4bdb7
Fix recursive nonterminal expansion during pretty-print/reparse check
Makes progress towards #43081

In PR #73084, we started recursively expanded nonterminals during the
pretty-print/reparse check, allowing them to be properly compared
against the reparsed tokenstream.

Unfortunately, the recursive logic in that PR only handles the case
where a nonterminal appears inside a `TokenTree::Delimited`. If a
nonterminal appears directly in the expanded tokens of another
nonterminal, the inner nonterminal will not be expanded.

This PR fixes the recursive expansion of nonterminals, ensuring that
they are expanded wherever they occur.
2020-09-28 19:14:42 -04:00
Vadim Petrochenkov 4a4a7f8599 expand: Minor fn ptr call cleanup 2020-09-28 23:10:48 +03:00
Vadim Petrochenkov 85ef265dbe expand: Stop un-interpolating `NtIdent`s before passing them to built-in macros
This was a big hack, and built-in macros should be able to deal with `NtIdents` in the input by themselves like any other parser code.
2020-09-28 23:10:44 +03:00
Bastian Kauschke db5b70f193 move candidate_from_obligation_no_cache 2020-09-28 20:21:44 +02:00
Bastian Kauschke a4783debe0 const evaluatable: improve `TooGeneric` handling 2020-09-28 20:18:06 +02:00
Oliver Scherer 43c181bac4 Use `tracing` spans to trace the entire MIR interp stack 2020-09-28 20:07:57 +02:00
bors fc2daaae61 Auto merge of #77302 - RalfJung:rollup-n8gg3v6, r=RalfJung
Rollup of 7 pull requests

Successful merges:

 - #76454 (UI to unit test for those using Cell/RefCell/UnsafeCell)
 - #76474 (Add option to pass a custom codegen backend from a driver)
 - #76711 (diag: improve closure/generic parameter mismatch)
 - #77170 (Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`)
 - #77194 (Add doc alias for iterator fold)
 - #77288 (fix building libstd for Miri on macOS)
 - #77295 (Update unstable-book: Fix ABNF in inline assembly docs)

Failed merges:

r? `@ghost`
2020-09-28 18:02:45 +00:00
Ralf Jung 85a59d40f1
Rollup merge of #77170 - ecstatic-morse:const-fn-ptr, r=oli-obk
Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`

`rustc_allow_const_fn_ptr` was a hack to work around the lack of an escape hatch for the "min `const fn`" checks in const-stable functions. Now that we have co-opted `allow_internal_unstable` for this purpose, we no longer need a bespoke attribute.

Now this functionality is gated under `const_fn_fn_ptr_basics` (how concise!), and `#[allow_internal_unstable(const_fn_fn_ptr_basics)]` replaces `#[rustc_allow_const_fn_ptr]`. `const_fn_fn_ptr_basics` allows function pointer types to appear in the arguments and locals of a `const fn` as well as function pointer casts to be performed inside a `const fn`. Both of these were allowed in constants and statics already. Notably, this does **not** allow users to invoke function pointers in a const context. Presumably, we will use a nicer name for that (`const_fn_ptr`?).

r? @oli-obk
2020-09-28 18:39:44 +02:00
Ralf Jung 88ae20d8aa
Rollup merge of #76711 - davidtwco:issue-51154-param-closure, r=estebank
diag: improve closure/generic parameter mismatch

Fixes #51154.

This PR improves the diagnostic when a type parameter is expected and a closure is found, noting that each closure has a distinct type and therefore could not always match the caller-chosen type of the parameter.

r? @estebank
2020-09-28 18:39:42 +02:00
Ralf Jung 6a8cdbd285
Rollup merge of #76474 - bjorn3:driver_selected_codegen, r=oli-obk
Add option to pass a custom codegen backend from a driver

This allows the driver to pass information to the codegen backend. For example the headcrab debugger may in the future want to use cg_clif to JIT code to be injected in the debuggee. This would PR make it possible to tell cg_clif which symbol can be found at which address and to tell it to inject the JITed code into the right process.

This PR may also help with https://github.com/rust-lang/miri/pull/1540 by allowing miri to provide a codegen backend that only emits metadata and doesn't perform any codegen.

cc @nbaksalyar (headcrab)
cc @RalfJung (miri)
2020-09-28 18:39:40 +02:00
bors d62d3f7fa9 Auto merge of #76899 - wesleywiser:experimental_unsound_mir_opts_flag, r=oli-obk
[mir-opt] Introduce a new flag to enable experimental/unsound mir opts

This implements part of https://github.com/rust-lang/compiler-team/issues/319. The exact name of this flag was not decided as part of that MCP and some people expressed that it should include "unsound" in some way.

I've chosen to use `enable-experimental-unsound-mir-opts` as the name. While long, I don't think that matters too much as really it will only be used by some mir-opt tests. If you object or have a better name, please leave a comment!

r? `@oli-obk`
cc `@rust-lang/wg-mir-opt` `@RalfJung`
2020-09-28 15:32:27 +00:00
bors 535d27ac9a Auto merge of #77236 - matthewjasper:defer-typeof-impl-trait, r=davidtwco
Compute underlying type of impl trait types later in compilation

Also change a `bug!` to `delay_span_bug`
Closes #74018
2020-09-28 12:47:23 +00:00
bors 96555ba608 Auto merge of #77261 - oli-obk:const_generic_array_serializer, r=matthewjasper
Deduplicate and generalize some (de/)serializer impls

I noticed this while implementing #77227 and getting a "not implemented for [T; 16]" error. There's likely more things we can deduplicate in this file, but I didn't need any additional changes.
2020-09-28 08:33:00 +00:00
bors 4e3eb52493 Auto merge of #77265 - vandenheuvel:chalkup, r=Dylan-DPC
Update chalk to 0.29.0
2020-09-28 06:20:02 +00:00
Aman Arora c923da0b49 pretty.rs: Update Closure and Generator print
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
Co-authored-by: Logan Mosier <logmosier@gmail.com>
2020-09-28 01:27:19 -04:00
Valerii Lashmanov 92a0668c20 SsoHashMap minor refactoring, SSO_ARRAY_SIZE introduced 2020-09-27 23:48:19 -05:00
Wesley Wiser b9d0ea95c8 [mir-opt] Introduce a new flag to enable experimental/unsound mir opts 2020-09-27 19:21:01 -04:00
Tomasz Miąsko 33dde94d33 liveness: Inline visitor implementation for IrMaps 2020-09-27 23:55:53 +02:00
Tomasz Miąsko 536b51aca0 liveness: Store upvars_mentioned inside Liveness struct 2020-09-27 23:55:53 +02:00
Tomasz Miąsko b629ffd96b liveness: Use visit_param to add variables corresponding to params 2020-09-27 23:55:53 +02:00
Tomasz Miąsko e0db21dc7e liveness: Use upvars instead of FnKind to check for closures
Avoiding FnKind will make it easier to run liveness analysis on all
bodies in the future, not just fn-like things.
2020-09-27 23:55:52 +02:00
Tomasz Miąsko e3319e7d16 liveness: Move body_owner field from IrMaps to Liveness
The Liveness struct is the only user of body_owner field.  Move the
field there.
2020-09-27 23:55:52 +02:00
bors c0b15cc6ed Auto merge of #77242 - ecstatic-morse:dataflow-switch-int, r=jonas-schievink
Replace `discriminant_switch_effect` with more general version

#68528 added a new edge-specific effect for `SwitchInt` terminators, `discriminant_switch_effect`, to the dataflow framework. While this accomplished the short-term goal of making drop elaboration more precise, it wasn't really useful in other contexts: It only supported `SwitchInt`s on the discriminant of an `enum` and did not allow effects to be applied along the "otherwise" branch. In const-propagation, for example, arbitrary edge-specific effects for the targets of a `SwitchInt` can be used to remember the value a `match` scrutinee must have in each arm.

This PR replaces `discriminant_switch_effect` with a more general `switch_int_edge_effects` method. The new method has a slightly different interface from the other edge-specific effect methods (e.g. `call_return_effect`). This divergence is explained in the new method's documentation, and reading the changes to the various dataflow impls as well as `direction.rs` should further clarify things. This PR should not change behavior.
2020-09-27 21:54:49 +00:00
bors 7f7a1cbfd3 Auto merge of #77229 - tmiasko:liveness, r=lcnr
Small improvements in liveness pass

* Remove redundant debug logging (`add_variable` already contains logging).
* Remove redundant fields for a number of live nodes and variables.
* Delay conversion from a symbol to a string until linting.
* Inline contents of specials struct.
* Remove unnecessary local variable exit_ln.
* Use newtype_index for Variable and LiveNode.
* Access live nodes directly through self.lnks[ln].

No functional changes intended (except those related to the logging).
2020-09-27 19:38:01 +00:00
Dylan MacKenzie 3cbd17fcc6 Remove `rustc_allow_const_fn_ptr`
This was a hack to work around the lack of an escape hatch for the "min
`const fn`" checks in const-stable functions. Now that we have co-opted
`allow_internal_unstable` for this purpose, we no longer need the
bespoke attribute.
2020-09-27 10:46:41 -07:00
Dylan MacKenzie 1ff143191c Add a feature gate for basic function pointer use in `const fn` 2020-09-27 10:46:41 -07:00
Jonas Schievink 344ab3fb7b
Rollup merge of #77263 - bugadani:cleanup, r=lcnr
Clean up trivial if let
2020-09-27 18:37:29 +02:00
Jonas Schievink 65298ee49c
Rollup merge of #77262 - bugadani:redundant-comment, r=Dylan-DPC
Remove duplicate comment
2020-09-27 18:37:28 +02:00
Jonas Schievink 06677cbcfc
Rollup merge of #77256 - jyn514:typo, r=Aaron1011
Fix typo in ExpnData documentation

This mis-highlighted the entire documentation as code: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/hygiene/struct.ExpnData.html#structfield.krate
2020-09-27 18:37:26 +02:00
Jonas Schievink 2a90d31423
Rollup merge of #77249 - jyn514:private-links, r=Manishearth
Separate `private_intra_doc_links` and `broken_intra_doc_links` into separate lints

This is not ideal because it means `deny(broken_intra_doc_links)` will
no longer `deny(private_intra_doc_links)`. However, it can't be fixed
with a new lint group, because `broken` is already in the `rustdoc` lint
group; there would need to be a way to nest groups somehow.

This also removes the early `return` so that the link will be generated
even though it gives a warning.

r? @Manishearth
cc @ecstatic-morse (https://github.com/rust-lang/rust/pull/77242#issuecomment-699565095)
2020-09-27 18:37:23 +02:00
Jonas Schievink 9f086fcb00
Rollup merge of #77203 - ecstatic-morse:const-stability-attr-checks, r=oli-obk
Check for missing const-stability attributes in `rustc_passes`

Currently, this happens as a side effect of `is_min_const_fn`, which is non-obvious. Also adds a test for this case, since we didn't seem to have one before.
2020-09-27 18:37:21 +02:00
Jonas Schievink ec1766c5b6
Rollup merge of #76839 - lzutao:mips-asm, r=Amanieu
Add asm! support for MIPS

For now, I only add support for mips32.
mips64 may come in future PRs if I could learn more about the target.
2020-09-27 18:37:20 +02:00
Joshua Nelson 80ffaed809 Add documentation for `private_intra_doc_links` 2020-09-27 10:44:41 -04:00
Joshua Nelson 03d8be0896 Separate `private_intra_doc_links` and `broken_intra_doc_links` into separate lints
This is not ideal because it means `deny(broken_intra_doc_links)` will
no longer `deny(private_intra_doc_links)`. However, it can't be fixed
with a new lint group, because `broken` is already in the `rustdoc` lint
group; there would need to be a way to nest groups somehow.

This also removes the early `return` so that the link will be generated
even though it gives a warning.
2020-09-27 09:58:29 -04:00
Bram van den Heuvel ef7377eb05 Update chalk to 0.29.0 2020-09-27 15:54:07 +02:00
bors d902752866 Auto merge of #77118 - exrook:stability-generic-parameters-2, r=varkor
Stability annotations on generic parameters (take 2.5)

Rebase of #72314 + more tests

Implements rust-lang/wg-allocators#2.
2020-09-27 12:51:21 +00:00
bjorn3 71bc62b9f6 Add option to pass a custom codegen backend from a driver 2020-09-27 14:16:42 +02:00
bors b8363295d5 Auto merge of #71274 - RalfJung:raw-init-check-aggregate, r=petrochenkov
might_permit_raw_init: also check aggregate fields

This is the next step for https://github.com/rust-lang/rust/issues/66151: when doing `mem::zeroed`/`mem::uninitialized`, also recursively check fields of aggregates (except for arrays) for whether they permit zero/uninit initialization.
2020-09-27 10:17:09 +00:00
Dániel Buga e4200512ff Clean up trivial if let 2020-09-27 11:54:50 +02:00
Dániel Buga 3d4a2e6bb9 Remove duplicate comment 2020-09-27 11:00:46 +02:00
bors 71bdb84817 Auto merge of #76955 - jyn514:refactor-diagnostics, r=euclio
Refactor and fix intra-doc link diagnostics, and fix links to primitives

Closes https://github.com/rust-lang/rust/issues/76925, closes https://github.com/rust-lang/rust/issues/76693, closes https://github.com/rust-lang/rust/issues/76692.

Originally I only meant to fix #76925. But the hack with `has_primitive` was so bad it was easier to fix the primitive issues than to try and work around it.

Note that this still has one bug: `std::primitive::i32::MAX` does not resolve. However, this fixes the ICE so I'm fine with fixing the link in a later PR.

This is part of a series of refactors to make #76467 possible.

This is best reviewed commit-by-commit; it has detailed commit messages.

r? `@euclio`
2020-09-27 08:12:29 +00:00
Joshua Nelson d9fc5b5ea8 Fix typo in ExpnData documentation
This mis-highlighted the entire documentation as code.
2020-09-27 00:10:54 -04:00
Dylan MacKenzie c4d8089f00 Revert "Add an unused field of type `Option<DefId>` to `ParamEnv` struct."
This reverts commit ab83d372ed.
2020-09-26 21:01:09 -07:00
Dylan MacKenzie bb6c249f99 Speed up `IntRange::from_pat`
Previously, this method called the more general `pat_constructor`
function, which can return other pattern variants besides `IntRange`.
Then it throws away any non-`IntRange` variants. Specialize it so work
is only done when it could result in an `IntRange`.
2020-09-26 20:00:54 -07:00
Lzu Tao 9000710959 Add MIPS asm! support
This patch also:
* Add soft-float supports: only f32
* zero-extend i8/i16 to i32 because MIPS only supports register-length
  arithmetic.
* Update table in asm! chapter in unstable book.
2020-09-27 02:36:50 +00:00
bors 62fe055aba Auto merge of #76986 - jonas-schievink:ret-in-reg, r=nagisa
Return values up to 128 bits in registers

This fixes https://github.com/rust-lang/rust/issues/26494#issuecomment-619506345 by making Rust's default ABI pass return values up to 128 bits in size in registers, just like the System V ABI.

The result is that these methods from the comment linked above now generate the same code, making the Rust ABI as efficient as the `"C"` ABI:

```rust
pub struct Stats { x: u32, y: u32, z: u32, }

pub extern "C" fn sum_c(a: &Stats, b: &Stats) -> Stats {
    return Stats {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
}

pub fn sum_rust(a: &Stats, b: &Stats) -> Stats {
    return Stats {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
}
```

```asm
sum_rust:
	movl	(%rsi), %eax
	addl	(%rdi), %eax
	movl	4(%rsi), %ecx
	addl	4(%rdi), %ecx
	movl	8(%rsi), %edx
	addl	8(%rdi), %edx
	shlq	$32, %rcx
	orq	%rcx, %rax
	retq
```
2020-09-27 02:35:11 +00:00
Eric Huss 7420d7a980 Move add_apple_sdk out of add_pre_link_args. 2020-09-26 19:12:38 -07:00
Dylan MacKenzie c0cd1b0a26 Remove intra-doc link 2020-09-26 17:29:55 -07:00
Tomasz Miąsko d68aa227c6 liveness: Access live nodes directly through self.lnks[ln] 2020-09-27 00:00:00 +00:00
Jonas Schievink 7a1a87114e
Rollup merge of #77235 - petrochenkov:reparse, r=Aaron1011
pretty-print-reparse hack: Rename some variables for clarity

This will also make it easier to make the comparisons asymmetric.

Also one impossible case is removed.

r? @Aaron1011
2020-09-27 01:53:29 +02:00
Jonas Schievink aa35c527fd
Rollup merge of #77231 - oli-obk:clippy_const_fn, r=Manishearth
Move helper function for `missing_const_for_fn` out of rustc to clippy

cc @rust-lang/clippy @ecstatic-morse #76618

r? @Manishearth

I also removed all support for suggesting a function could be `const fn` when that would require feature gates to actually work.

This means we'll now have to maintain this ourselves in clippy, but that's how most lints work anyway, so...
2020-09-27 01:53:27 +02:00
Jonas Schievink 593b38be6a
Rollup merge of #77209 - jyn514:fix-docs, r=petrochenkov
Fix documentation highlighting in ty::BorrowKind

Previously it looked a little odd: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.BorrowKind.html#variant.UniqueImmBorrow

Noticed this while reviewing https://github.com/rust-lang/rustc-dev-guide/pull/894.
2020-09-27 01:53:25 +02:00
Jonas Schievink 3d1d24da94
Rollup merge of #77208 - mati865:late-link-args-order, r=petrochenkov
Late link args order

MSYS2 changed how winpthreads is built and as the result it now depends on more mingw-w64 libraries.

This PR affects only MinGW targets since nobody else is using `late_link_args_{dynamic,static}`. Now the order is similar to how it used to be before https://github.com/rust-lang/rust/pull/67502.
2020-09-27 01:53:23 +02:00
Jonas Schievink 6b8fb3fbd8
Rollup merge of #77107 - bugadani:perf, r=oli-obk
Enable const propagation into operands at mir_opt_level=2

Feature was added in #74507 but gated with `mir_opt_level>=3` because of compile time regressions. Let's see whether the LLVM 11 update solves that.

As the [perf results](https://github.com/rust-lang/rust/pull/77107#issuecomment-697668154) show, enabling this optimization results in a lot less regression as before.

cc @oli-obk

r? @ghost
2020-09-27 01:53:16 +02:00
Valerii Lashmanov 41942fac7d SsoHashSet reimplemented as a wrapper on top of SsoHashMap
SsoHashSet::replace had to be removed because
it requires missing API from SsoHashMap.
It's not a widely used function, so I think it's ok
to omit it for now.

EitherIter moved into its own file.

Also sprinkled code with #[inline] attributes where appropriate.
2020-09-26 18:42:26 -05:00
Dylan MacKenzie 2364b58b87 Update dataflow impls to reflect new interface 2020-09-26 15:15:06 -07:00
Dylan MacKenzie 43e6ef876f Update engine to use new interface 2020-09-26 15:15:06 -07:00
Dylan MacKenzie 4c5f9f742c Replace `discriminant_switch_effect` with more general version
...that allows arbitrary effects on each edge of a `SwitchInt`
terminator.
2020-09-26 14:50:47 -07:00
bors 623fb90b5a Auto merge of #76897 - Aaron1011:feature/min-proc-macro-metadata, r=petrochenkov
Encode less metadata for proc-macro crates

Currently, we serialize the same crate metadata for proc-macro crates as
we do for normal crates. This is quite wasteful - almost none of this
metadata is ever used, and much of it can't even be deserialized (if it
contains a foreign `CrateNum`).

This PR changes metadata encoding to skip encoding the majority of crate
metadata for proc-macro crates. Most of the `Lazy<[T]>` fields are left
completetly empty, while the non-lazy fields are left as-is.

Additionally, proc-macros now have a def span that does not include
their body. This was done for normal functions in #75465, but was missed
for proc-macros.

As a result of this PR, we should only ever encode local `CrateNum`s
when encoding proc-macro crates. I've added a specialized serialization
impl for `CrateNum` to assert this.
2020-09-26 20:57:31 +00:00
Valerii Lashmanov 0600b178aa SsoHashSet/SsoHashMap API greatly expanded
Now both provide almost complete API of their non-SSO counterparts.
2020-09-26 14:30:05 -05:00
Valerii Lashmanov 5c224a484d MiniSet/MiniMap moved and renamed into SsoHashSet/SsoHashMap
It is a more descriptive name and with upcoming changes
there will be nothing "mini" about them.
2020-09-26 14:30:05 -05:00
bors e37c99fa1c Auto merge of #77224 - RalfJung:rollup-hdvb96c, r=RalfJung
Rollup of 12 pull requests

Successful merges:

 - #75454 (Explicitly document the size guarantees that Option makes.)
 - #76631 (Add `x.py setup`)
 - #77076 (Add missing code examples on slice iter types)
 - #77093 (merge `need_type_info_err(_const)`)
 - #77122 (Add `#![feature(const_fn_floating_point_arithmetic)]`)
 - #77127 (Update mdBook)
 - #77161 (Remove TrustedLen requirement from BuilderMethods::switch)
 - #77166 (update Miri)
 - #77181 (Add doc alias for pointer primitive)
 - #77204 (Remove stray word from `ClosureKind::extends` docs)
 - #77207 (Rename `whence` to `span`)
 - #77211 (Remove unused #[allow(...)] statements from compiler/)

Failed merges:

 - #77170 (Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`)

r? `@ghost`
2020-09-26 17:50:26 +00:00
Vadim Petrochenkov fe3e5aa729 pretty-print-reparse hack: Remove an impossible case
Delimiters cannot appear as isolated tokens in a token stream
2020-09-26 20:27:14 +03:00
Vadim Petrochenkov 275bf626f6 pretty-print-reparse hack: Rename some variables for clarity 2020-09-26 20:27:09 +03:00
Matthew Jasper 3a81adeca2 Call `type_of` for opaque types later in compilation
This ensures that various wf checks have already been done before we
typeck item bodies.
2020-09-26 17:56:03 +01:00
Aaron Hill b9653568a7
Encode less metadata for proc-macro crates
Currently, we serialize the same crate metadata for proc-macro crates as
we do for normal crates. This is quite wasteful - almost none of this
metadata is ever used, and much of it can't even be deserialized (if it
contains a foreign `CrateNum`).

This PR changes metadata encoding to skip encoding the majority of crate
metadata for proc-macro crates. Most of the `Lazy<[T]>` fields are left
completetly empty, while the non-lazy fields are left as-is.

Additionally, proc-macros now have a def span that does not include
their body. This was done for normal functions in #75465, but was missed
for proc-macros.

As a result of this PR, we should only ever encode local `CrateNum`s
when encoding proc-macro crates. I've added a specialized serialization
impl for `CrateNum` to assert this.
2020-09-26 12:26:27 -04:00
Matthew Jasper ef83742b2b Delay bug for non-universal regions in member constraints 2020-09-26 17:16:25 +01:00
Tomasz Miąsko 57d38975cc liveness: Use newtype_index for Variable and LiveNode 2020-09-26 16:44:41 +02:00
Tomasz Miąsko 49d1ce00f3 liveness: Remove unnecessary local variable exit_ln 2020-09-26 16:44:28 +02:00
Oliver Scherer 1b843896c8 Move `qualify_min_const_fn` out of rustc into clippy 2020-09-26 16:08:24 +02:00
Tomasz Miąsko 141b91da6c liveness: Inline contents of specials struct 2020-09-26 15:38:56 +02:00
Tomasz Miąsko 70f150b51e liveness: Delay conversion from a symbol to a string until linting 2020-09-26 15:38:51 +02:00
Tomasz Miąsko 2fb1564457 liveness: Remove redundant fields for a number of live nodes and variables 2020-09-26 15:38:30 +02:00
Tomasz Miąsko 9b5835ec79 liveness: Remove redundant debug logging
The IrMaps::add_variable already contains debug logging. Don't duplicate it.
2020-09-26 15:38:22 +02:00
Jonas Schievink 4c5acc4ed7 Return values up to 128 bits in registers 2020-09-26 15:34:26 +02:00
Oliver Scherer 455f284496 Deduplicate and generalize some (de/)serializer impls 2020-09-26 14:55:42 +02:00
varkor 94c789b275 `char` not char 2020-09-26 13:34:49 +01:00
varkor 8eb42ba0fb Make invalid integer operation messages consistent 2020-09-26 13:34:49 +01:00
Ralf Jung 9e02642fb3
Rollup merge of #77211 - est31:remove_unused_allow, r=oli-obk
Remove unused #[allow(...)] statements from compiler/
2020-09-26 12:58:34 +02:00
Ralf Jung 67f8c5914f
Rollup merge of #77204 - LingMan:patch-3, r=jonas-schievink
Remove stray word from `ClosureKind::extends` docs
2020-09-26 12:58:30 +02:00
Ralf Jung 7c47b1e5f4
Rollup merge of #77161 - est31:swich_len_already_trusted, r=petrochenkov
Remove TrustedLen requirement from BuilderMethods::switch

The main use case of TrustedLen is allowing APIs to specialize on it,
but no use of it uses that specialization. Instead, only the .len()
function provided by ExactSizeIterator is used, which is already
required to be accurate.

Thus, the TrustedLen requirement on BuilderMethods::switch is redundant.
2020-09-26 12:58:24 +02:00
Ralf Jung 3b544e73ae
Rollup merge of #77122 - ecstatic-morse:const-fn-arithmetic, r=RalfJung,oli-obk
Add `#![feature(const_fn_floating_point_arithmetic)]`

cc #76618

This is a template for splitting up `const_fn` into granular feature gates. I think this will make it easier, both for us and for users, to track stabilization of each individual feature. We don't *have* to do this, however. We could also keep stabilizing things out from under `const_fn`.

cc @rust-lang/wg-const-eval
r? @oli-obk
2020-09-26 12:58:20 +02:00
Ralf Jung ac8169dc10
Rollup merge of #77093 - lcnr:const-generics-infer-warning, r=varkor
merge `need_type_info_err(_const)`

I hoped that this would automatically solve #76737 but it doesn't quite seem like it

fixes #77092

r? @varkor
2020-09-26 12:58:17 +02:00
Ralf Jung 6f881b3b7d might_permit_raw_init: also check aggregate fields 2020-09-26 12:29:01 +02:00
bors 6f9a8a7f9b Auto merge of #76485 - estebank:format_arg_capture_spans, r=davidtwco
Point at named argument not found when using `format_args_capture` instead of whole format string
2020-09-26 10:05:49 +00:00
Bastian Kauschke 9a607c0a27 unused into 2020-09-26 10:31:34 +02:00
Bastian Kauschke 32195ac8f4 rename functions 2020-09-26 10:28:15 +02:00
bors fd15e6180d Auto merge of #70743 - oli-obk:eager_const_to_pat_conversion, r=eddyb
Fully destructure constants into patterns

r? `@varkor`

as discussed in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/constants.20in.20patterns/near/192789924

we should probably crater it once reviewed
2020-09-26 06:44:28 +00:00
est31 12187b7f86 Remove unused #[allow(...)] statements from compiler/ 2020-09-26 01:25:55 +02:00
Joshua Nelson 58d57f3f5e Fix documentation highlighting in ty::BorrowKind
Previously it looked a little odd: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.BorrowKind.html#variant.UniqueImmBorrow
2020-09-25 18:54:05 -04:00
marmeladema 5946c12476 Move `is_raw_guess` check in `ty::print::pretty` 2020-09-25 22:48:44 +01:00
marmeladema 35bad3edbf Address review comment 2020-09-25 22:48:44 +01:00
marmeladema f25d0bc559 Remove now unused `double_braced_*` symbols 2020-09-25 22:46:15 +01:00
marmeladema 23085b6360 Fix profiling query key creation 2020-09-25 22:46:15 +01:00
marmeladema bb8e1764bb Simplify some match statements on `DefPathDataName' 2020-09-25 22:46:15 +01:00
marmeladema 75130b06bf Avoid calling `Symbol::interner` in `compute_codegen_unit_name` 2020-09-25 22:46:15 +01:00
marmeladema 657ecdb75e Rename `DefPathData::get_name()` to `DefPathData::name()` 2020-09-25 22:46:15 +01:00
marmeladema 2708ad8bb4 Fix pretty-printing of `DisambiguatedDefPathData` 2020-09-25 22:46:15 +01:00
marmeladema 9f50c49117 Implement `Display` for `DisambiguatedDefPathData` and `DefPathData` 2020-09-25 22:46:15 +01:00
marmeladema f1878d19fa Move from {{closure}}#0 syntax to {closure#0} for (def) path components 2020-09-25 22:46:14 +01:00
LingMan 900daba2cb
Remove stray word from `ClosureKind::extends` docs 2020-09-25 23:35:07 +02:00
Dylan MacKenzie 76c6f2dc3f No need to call `is_min_const_fn` for side-effects 2020-09-25 14:31:32 -07:00
Dylan MacKenzie 11bfc60a4b Change error in `fn_queries` to `delay_span_bug`
This should be caught by the new check in `rustc_passes`. At some point,
this function will be removed entirely.
2020-09-25 14:31:32 -07:00
Dylan MacKenzie 61d86fa06c Check for missing const-stability attributes in `stability`
This used to happen as a side-effect of `is_min_const_fn`, which was
subtle.
2020-09-25 14:31:32 -07:00
bors c6e4db620a Auto merge of #77198 - jonas-schievink:rollup-i59i41h, r=jonas-schievink
Rollup of 15 pull requests

Successful merges:

 - #76932 (Relax promises about condition variable.)
 - #76973 (Unstably allow assume intrinsic in const contexts)
 - #77005 (BtreeMap: refactoring around edges)
 - #77066 (Fix dest prop miscompilation around references)
 - #77073 (dead_code: look at trait impls even if they don't contain items)
 - #77086 (Include libunwind in the rust-src component.)
 - #77097 (Make [].as_[mut_]ptr_range() (unstably) const.)
 - #77106 (clarify that `changelog-seen = 1` goes to the beginning of config.toml)
 - #77120 (Add `--keep-stage-std` to `x.py` for keeping only standard library artifacts)
 - #77126 (Invalidate local LLVM cache less often)
 - #77146 (Install std for non-host targets)
 - #77155 (remove enum name from ImplSource variants)
 - #77176 (Removing erroneous semicolon in transmute documentation)
 - #77183 (Allow multiple allow_internal_unstable attributes)
 - #77189 (Remove extra space from vec drawing)

Failed merges:

r? `@ghost`
2020-09-25 19:35:33 +00:00
Eric Huss c29a29cba0 Defer Apple SDKROOT detection to link time. 2020-09-25 12:07:46 -07:00
Jonas Schievink 12b8d8943d
Rollup merge of #77183 - bugadani:issue-77088, r=varkor
Allow multiple allow_internal_unstable attributes

Fixes #77088
2020-09-25 19:42:52 +02:00
Jonas Schievink e739468f97
Rollup merge of #77155 - lcnr:ImplSource, r=ecstatic-morse
remove enum name from ImplSource variants

This is quite a lot cleaner in my opinion.
2020-09-25 19:42:48 +02:00
Jonas Schievink ba44e9fe34
Rollup merge of #77073 - lcnr:ty-trait-param, r=matthewjasper
dead_code: look at trait impls even if they don't contain items

fixes #70225
2020-09-25 19:42:35 +02:00
Jonas Schievink 452aa759b7
Rollup merge of #77066 - jonas-schievink:dest-prop-borrow, r=oli-obk
Fix dest prop miscompilation around references

Closes https://github.com/rust-lang/rust/issues/77002
2020-09-25 19:42:33 +02:00
Jonas Schievink 1b8c939a8d
Rollup merge of #76973 - lzutao:unstably-const-assume, r=oli-obk
Unstably allow assume intrinsic in const contexts

Not sure much about this usage because there are concerns
about [blocking  optimization][1] and [slowing down LLVM][2] when using `assme` intrinsic
in inline functions.
But since Oli suggested in https://github.com/rust-lang/rust/issues/76960#issuecomment-695772221,
here we are.

[1]: https://github.com/rust-lang/rust/pull/54995#issuecomment-429302709
[2]: https://github.com/rust-lang/rust/issues/49572#issuecomment-589615423
2020-09-25 19:42:29 +02:00
Dylan MacKenzie 659028f48b Use proper issue for `const_fn_floating_point_arithmetic` 2020-09-25 10:39:11 -07:00
Dylan MacKenzie 2049052cb9 Put floating point arithmetic behind its own feature gate
This refactors handling of `Rvalue::{Unary,Binary}Op` in the
const-checker. Now we `span_bug` if there's an unexpected type in a
primitive operation. This also allows unary negation on
`char` values through the const-checker because it makes the code a bit
cleaner. `char` does not actually support these operations, and if it
did, we could evaluate them at compile-time.
2020-09-25 10:37:52 -07:00
Dylan MacKenzie 0d2521aaf7 Add `const_fn_floating_point_arithmetic` 2020-09-25 10:37:52 -07:00
bors 10ef7f9ebf Auto merge of #77157 - tmiasko:simplify-cfg-dup, r=jonas-schievink
Remove duplicated SimplifyCfg pass
2020-09-25 17:27:52 +00:00
bors 5b9e886403 Auto merge of #73453 - erikdesjardins:tuplayout, r=eddyb
Ignore ZST offsets when deciding whether to use Scalar/ScalarPair layout

This is important because Scalar/ScalarPair layout previously would not be used if any ZST had nonzero offset.
For example, before this change, only `((), u128)` would be laid out like `u128`, not `(u128, ())`.

Fixes #63244
2020-09-25 14:42:20 +00:00
Dániel Buga 54c9c949a1 Allow multiple allow_internal_unstable attributes
Co-authored-by: varkor <github@varkor.com>
2020-09-25 15:19:46 +02:00
bors b984ef6797 Auto merge of #77152 - vandenheuvel:update_chalk_further, r=jackh726
Update chalk to 0.28.0
2020-09-25 12:22:05 +00:00
Mateusz Mikuła bfdb7903c9 Link dynamic and static late_link_args before generic ones 2020-09-25 13:35:49 +02:00
bors 521d8d8a22 Auto merge of #77041 - lcnr:const-eval-perf, r=ecstatic-morse
perf: move cold path of `process_obligations` into a separate function

cc #76575

This probably won't matter too much in the long run once #69218 is merged so we may not want to merge this.

r? `@ecstatic-morse`
2020-09-25 10:14:47 +00:00
bors 9d74efe32e Auto merge of #76844 - simonvandel:fix-76803, r=wesleywiser
Fix #76803 miscompilation

Fixes #76803
Seems like it was an oversight that the discriminant value being set was not compared to the target value from the SwitchInt, as a comment says this is a requirement for the optimization to be sound.

r? `@wesleywiser` since you are probably familiar with the optimization and made #76837 to workaround the bug
2020-09-25 04:17:03 +00:00
bors 5bfeee5fe0 Auto merge of #77172 - jonas-schievink:rollup-a041rou, r=jonas-schievink
Rollup of 15 pull requests

Successful merges:

 - #75438 (Use adaptive SVG favicon for rustdoc like other rust sites)
 - #76304 (Make delegation methods of `std::net::IpAddr` unstably const)
 - #76724 (Allow a unique name to be assigned to dataflow graphviz output)
 - #76978 (Documented From impls in std/sync/mpsc/mod.rs)
 - #77044 (Liballoc bench vec use mem take not replace)
 - #77050 (Typo fix: "satsify" -> "satisfy")
 - #77074 (add array::from_ref)
 - #77078 (Don't use an if guard to check equality with a constant)
 - #77079 (Use `Self` in docs when possible)
 - #77081 (Merge two almost identical match arms)
 - #77121 (Updated html_root_url for compiler crates)
 - #77136 (Suggest `const_mut_refs`, not `const_fn` for mutable references in `const fn`)
 - #77160 (Suggest `const_fn_transmute`, not `const_fn`)
 - #77164 (Remove workaround for deref issue that no longer exists.)
 - #77165 (Followup to #76673)

Failed merges:

r? `@ghost`
2020-09-25 01:56:06 +00:00
Jonas Schievink 8515efb193
Rollup merge of #77165 - simonvandel:do-not-fire-on-drop-and-replace, r=oli-obk
Followup to #76673

Resolves https://github.com/rust-lang/rust/pull/76673#discussion_r494426303
r? @tmiasko
2020-09-25 02:29:52 +02:00
Jonas Schievink b8d158b0f8
Rollup merge of #77160 - ecstatic-morse:const-fn-transmute-suggestion, r=oli-obk
Suggest `const_fn_transmute`, not `const_fn`

More fallout from #76850 in the vein of #77134. The fix is the same. I looked through the structured errors file and didn't see any more of this kind of diagnostics bug.

r? @oli-obk
2020-09-25 02:29:49 +02:00
Jonas Schievink 473ae229f0
Rollup merge of #77136 - ecstatic-morse:issue-77134, r=oli-obk
Suggest `const_mut_refs`, not `const_fn` for mutable references in `const fn`

Resolves #77134.

Prior to #76850, most uses of `&mut` in `const fn` ~~required~~ involved two feature gates, `const_mut_refs` and `const_fn`. The first allowed all mutable borrows of locals. The second allowed only locals, arguments and return values whose types contained `&mut`. I switched the second check to the `const_mut_refs` gate. However, I forgot update the error message with the new suggestion.

Alternatively, we could revert to having two different feature gates for this. OP's code never borrows anything mutably, so it didn't need `const_mut_refs` in the past, only `const_fn`. I'd prefer to keep everything under a single gate, however.

r? @oli-obk
2020-09-25 02:29:47 +02:00
Jonas Schievink 6f3da3d53f
Rollup merge of #77121 - duckymirror:html-root-url, r=jyn514
Updated html_root_url for compiler crates

Closes #77103

r? @jyn514
2020-09-25 02:29:45 +02:00
Jonas Schievink b8ab6eb217
Rollup merge of #77081 - LingMan:patch-1, r=jonas-schievink
Merge two almost identical match arms
2020-09-25 02:29:44 +02:00
Jonas Schievink 28e0bc997e
Rollup merge of #77078 - LingMan:patch-2, r=jonas-schievink
Don't use an if guard to check equality with a constant

Match on it directly instead
2020-09-25 02:29:40 +02:00
Jonas Schievink d766c239bd
Rollup merge of #76724 - ecstatic-morse:dataflow-pass-names, r=lcnr
Allow a unique name to be assigned to dataflow graphviz output

Previously, if the same analysis were invoked multiple times in a single compilation session, the graphviz output for later runs would overwrite that of previous runs. Allow callers to add a unique identifier to each run so this can be avoided.
2020-09-25 02:29:31 +02:00
bors 9b5c98f640 Auto merge of #77014 - tmiasko:arena, r=Mark-Simulacrum
DroplessArena: Allocate objects from the end of memory chunk

Allocating from the end of memory chunk simplifies the alignment code
and reduces the number of checked arithmetic operations.
2020-09-24 23:51:45 +00:00
Bastian Kauschke 06d2325a50 perf: split progress_obligations with inline(never) 2020-09-24 22:13:41 +02:00
Bastian Kauschke ff7009a4d2 nit 2020-09-24 22:03:39 +02:00
Bastian Kauschke e5430e5306 the two hardest things in programming, names and... 2020-09-24 22:01:46 +02:00
Dylan MacKenzie ebf024bba8 Suggest `const_fn_transmute` instead of `const_fn` 2020-09-24 12:07:41 -07:00
Simon Vandel Sillesen 7dec440340 Resolve https://github.com/rust-lang/rust/pull/76673#discussion_r494426303 2020-09-24 21:02:53 +02:00
Bram van den Heuvel 51c781f613 Upgrade chalk to 0.28.0 2020-09-24 20:54:33 +02:00
bors e599b53e67 Auto merge of #76918 - ishitatsuyuki:match-fastpath, r=oli-obk
Add fast path for match checking

This adds a fast path that would reduce the complexity to linear on matches consisting of only variant patterns (i.e. enum matches). (Also see: #7462) Unfortunately, I was too lazy to add a similar fast path for constants (mostly for integer matches), ideally that could be added another day.

TBH, I'm not confident with the performance claims due to the fact that enums tends to be small and FxHashMap could add a lot of overhead.

r? `@Mark-Simulacrum`

needs perf
2020-09-24 17:22:56 +00:00
Bastian Kauschke 1857184cd1 remove enum name from ImplSource variants 2020-09-24 19:22:36 +02:00
est31 12ada5cf4b Remove TrustedLen requirement from BuilderMethods::switch
The main use case of TrustedLen is allowing APIs to specialize on it,
but no use of it uses that specialization. Instead, only the .len()
function provided by ExactSizeIterator is used, which is already
required to be accurate.

Thus, the TrustedLen requirement on BuilderMethods::switch is redundant.
2020-09-24 19:10:34 +02:00
Bram van den Heuvel 5f67571e34 Update chalk to 0.27.0 2020-09-24 19:10:01 +02:00
Bram van den Heuvel 61b2a6f5e5 Update chalk to 0.26.0 2020-09-24 19:10:01 +02:00
Bram van den Heuvel ed784023e5 Update chalk to 0.25.0 2020-09-24 19:10:01 +02:00
Bram van den Heuvel cb660c6ab5 Update chalk to 0.24.0 2020-09-24 19:10:01 +02:00
Bram van den Heuvel 52eeff6fbe Update chalk to 0.23.0 2020-09-24 19:10:00 +02:00
Bram van den Heuvel b832a97a51 Update chalk to 0.22.0 2020-09-24 19:10:00 +02:00
bors 87d262acb5 Auto merge of #77006 - oli-obk:🐌_const_queries, r=Mark-Simulacrum
Cache `eval_to_allocation_raw` on disk

https://github.com/rust-lang/rust/pull/74949#issuecomment-695833161 regressed the performance on these queries, this PR gets the perf back.
2020-09-24 15:12:17 +00:00
Oliver Scherer 40629ef827 Always cache const eval queries 2020-09-24 17:09:09 +02:00
Oliver Scherer fc9f2947da Document `FallbackToConstRef` and make sure we don't accidentally use it 2020-09-24 17:01:03 +02:00
bors 893fadd11a Auto merge of #76820 - jyn514:query-comments, r=davidtwco
Preserve doc-comments when generating queries

Closes https://github.com/rust-lang/rust/issues/76812
2020-09-24 13:01:46 +00:00
Matthias Krüger d7a5c574b1 use std::mem::take(x) instead of std::mem::replace(x, Default::default()) (clippy::mem_replace_with_default) 2020-09-24 13:38:08 +02:00
Matthias Krüger 2ad46acd7f EarlyOtherwiseBranch::run_pass(): don't convert Place to Place (clippy::useless_conversion) 2020-09-24 13:38:07 +02:00
bors 3a4da87f58 Auto merge of #77049 - lcnr:const-eval-function-signature, r=oli-obk
const_evaluatable_checked: extend predicate collection

We now walk the hir instead of using `ty` so that we get better spans here, While I am still not completely sure if that's
what we want in the end, it does seem a lot closer to the final goal than the previous version.

We also look into type aliases (and use a `TypeVisitor` here), about which I am not completely sure, but we will see how well this works.

We also look into fn decls, so the following should work now.
```rust
fn test<T>() -> [u8; std::mem::size_of::<T>()] {
    [0; std::mem::size_of::<T>()]
}
```
Additionally, we visit the optional trait and self type of impls.

r? `@oli-obk`
2020-09-24 10:29:14 +00:00
Oliver Scherer 9550ca6242 Deduplicate the "needs partialeq derive" message creation sites 2020-09-24 10:18:51 +02:00
bors 86b4172305 Auto merge of #77028 - andjo403:mini, r=matthewjasper
Move MiniSet to data_structures

remove the need for T to be copy from MiniSet as was done for MiniMap

MiniMap and MiniSet was added by https://github.com/rust-lang/rust/pull/72412

think that this can be used in https://github.com/rust-lang/rust/pull/68828
2020-09-24 08:14:30 +00:00
Oliver Scherer e4928d77a1 Use correct type in diagnostics again 2020-09-24 10:06:07 +02:00
Oliver Scherer 2bc54d4273 Don't talk about determinism 2020-09-24 09:43:10 +02:00
Bastian Kauschke 3f9015b22d visit impl self ty + trait 2020-09-24 09:04:26 +02:00
Bastian Kauschke b8402d6a6e assign the correct `DefId` in `nominal_obligations` 2020-09-24 09:04:23 +02:00
Bastian Kauschke f8d3f401df walk hir to get const evaluatable predicates 2020-09-24 09:03:50 +02:00
Bastian Kauschke ac1d0d8b28 fmt, use IndexSet directly instead of UniquePredicates 2020-09-24 09:03:14 +02:00
Bastian Kauschke e1f408e6c8 const_evaluatable_checked: collect predicates from fn_sig 2020-09-24 09:03:07 +02:00
bors 5562bb6d74 Auto merge of #76748 - tmiasko:no-op-jumps, r=matthewjasper
Fix underflow when calculating the number of no-op jumps folded

When removing unwinds to no-op blocks and folding jumps to no-op blocks,
remove the unwind target first. Otherwise we cannot determine if target
has been already folded or not.

Previous implementation incorrectly assumed that all resume targets had
been folded already, occasionally resulting in an underflow:

```
remove_noop_landing_pads: removed 18446744073709551613 jumps and 3 landing pads
```
2020-09-24 05:57:06 +00:00
Dylan MacKenzie a320ef751b Suggest `const_mut_refs` for mutable references in const fn 2020-09-23 21:04:07 -07:00
Joshua Nelson 472e52e5a0 Fix intra-doc links for primitives
- Add `PrimTy::name` and `PrimTy::name_str`
- Use those new functions to distinguish between the name in scope and
the canonical name
- Fix diagnostics for primitive types
- Add tests for primitives
2020-09-23 21:04:22 -04:00
Tomasz Miąsko a09d607844 Remove duplicated SimplifyCfg pass 2020-09-24 00:00:00 +00:00
bors c35177582b Auto merge of #77102 - Dylan-DPC:rollup-2jfrg3u, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #76898 (Record `tcx.def_span` instead of `item.span` in crate metadata)
 - #76939 (emit errors during AbstractConst building)
 - #76965 (Add cfg(target_has_atomic_equal_alignment) and use it for Atomic::from_mut.)
 - #76993 (Changing the alloc() to accept &self instead of &mut self)
 - #76994 (fix small typo in docs and comments)
 - #77017 (Add missing examples on Vec iter types)
 - #77042 (Improve documentation for ToSocketAddrs)
 - #77047 (Miri: more informative deallocation error messages)
 - #77055 (Add #[track_caller] to more panicking Cell functions)

Failed merges:

r? `@ghost`
2020-09-23 22:34:44 +00:00
bors 8b4085359a Auto merge of #76673 - simonvandel:remove-unneeded-drops, r=oli-obk
MIR pass to remove unneeded drops on types not needing drop

This is heavily dependent on MIR inlining running to actually see the drop statement.

Do we want to special case replacing a call to std::mem::drop with a goto aswell?
2020-09-23 20:13:47 +00:00
Erik Hofmayer 764967a7e5 tidy 2020-09-23 22:08:30 +02:00
Erik Hofmayer 138a2e5eaa /nightly/nightly-rustc 2020-09-23 21:51:56 +02:00
Erik Hofmayer dd66ea2d3d Updated html_root_url for compiler crates 2020-09-23 21:14:43 +02:00
Dániel Buga 90c7731f6c Enable const prop into operands at mir_opt_level=2 2020-09-23 19:03:10 +02:00
Oliver Scherer 9aa1c0934c Update documentation tests 2020-09-23 18:55:27 +02:00
Oliver Scherer da217644a1 Make sure we keep emitting a hard error 2020-09-23 18:36:53 +02:00
Oliver Scherer 017423179a Make sure we report a future incompat error in all cases 2020-09-23 18:04:44 +02:00
Oliver Scherer 6a33de0170 Name function correctly 2020-09-23 17:55:14 +02:00
Oliver Scherer 9a7e66aeaf Make sure we don't hide errors just because a lint has been emitted 2020-09-23 17:52:37 +02:00
Oliver Scherer 177d0cef48 Deduplicate errors in const to pat conversion 2020-09-23 17:03:31 +02:00
Oliver Scherer d486486afd Talk about unpredictable instead of "not deterministic" 2020-09-23 16:38:30 +02:00
Oliver Scherer 1b1b6eabaa Remove the "lift constant to reference" logic 2020-09-23 16:28:45 +02:00
Dylan DPC f8dec3d054
Rollup merge of #77047 - RalfJung:miri-dealloc, r=oli-obk
Miri: more informative deallocation error messages

Make sure we show the affected AllocId.

r? @oli-obk
2020-09-23 14:54:13 +02:00
Dylan DPC bcdbe79f0c
Rollup merge of #76994 - yuk1ty:fix-small-typo, r=estebank
fix small typo in docs and comments

Fixed `the the` to `the`, as far as I found.
2020-09-23 14:54:07 +02:00
Dylan DPC eaaf5d7e38
Rollup merge of #76965 - fusion-engineering-forks:fix-atomic-from-mut, r=Amanieu
Add cfg(target_has_atomic_equal_alignment) and use it for Atomic::from_mut.

Fixes some platform-specific problems with #74532 by using the actual alignment of the types instead of hardcoding a few `target_arch`s.

r? @RalfJung
2020-09-23 14:54:04 +02:00
Dylan DPC 98e5ee7df0
Rollup merge of #76939 - lcnr:const-evaluatable-cont, r=oli-obk
emit errors during AbstractConst building

There changes are currently still untested, so I don't expect this to pass CI 😆

It seems to me like this is the direction we want to go in, though we didn't have too much of a discussion about this.

r? @oli-obk
2020-09-23 14:54:02 +02:00
Dylan DPC a22eb31668
Rollup merge of #76898 - Aaron1011:fix/item-def-span, r=oli-obk
Record `tcx.def_span` instead of `item.span` in crate metadata

This was missed in PR #75465. As a result, a few places have been using
the full body span of functions, instead of just the header span.
2020-09-23 14:54:00 +02:00
Bastian Kauschke 0e84b61053 use relevant span when unifying `ConstVarValue`s 2020-09-23 11:00:44 +02:00
Bastian Kauschke 3dbfdb0182 use the correct span when dealing with inference variables 2020-09-23 10:44:11 +02:00
bors feca2c229e Auto merge of #76659 - simonvandel:76432, r=oli-obk
SimplifyComparisonIntegral: fix miscompilation

Fixes #76432
Only insert StorageDeads if we actually removed one.
Fixes an issue where we added StorageDead to a place with no StorageLive

r? `@oli-obk`
2020-09-23 08:23:00 +00:00
Bastian Kauschke 0abb1abf04 unused path 2020-09-23 10:06:32 +02:00
Bastian Kauschke 45d92b43e3 merge `need_type_info_err(_const)` 2020-09-23 09:24:58 +02:00
Andreas Jonson 6586c37bec Move MiniSet to data_structures
remove the need for T to be copy from MiniSet as was done for MiniMap
2020-09-23 08:09:16 +02:00
bors f6d59207ad Auto merge of #76850 - ecstatic-morse:const-checking-refactor, r=oli-obk
Remove `qualify_min_const_fn`

~~Blocked on #76807 (the first six commits).~~

With this PR, all checks in `qualify_min_const_fn` are replicated in `check_consts`, and the former is no longer invoked. My goal was to have as few changes to test output as possible, since making sweeping changes to the code *while* doing big batches of diagnostics updates turned out to be a headache. To this end, there's a few `HACK`s in `check_consts` to achieve parity with `qualify_min_const_fn`.

The new system that replaces `is_min_const_fn` is referred to as "const-stability"  My end goal for the const-stability rules is this:
* Const-stability is only applicable to functions defined in `staged_api` crates.
* All functions not marked `rustc_const_unstable` are considered "const-stable".
    - NB. This is currently not implemented. `#[unstable]` functions are also const-unstable. This causes problems when searching for feature gates.
    - All "const-unstable" functions have an associated feature gate
* const-stable functions can only call other const-stable functions
     - `allow_internal_unstable` can be used to circumvent this.
* All const-stable functions are subject to some additional checks (the ones that were unique to `qualify_min_const_fn`)

The plan is to remove each `HACK` individually in subsequent PRs. That way, changes to error message output can be reviewed in isolation.
2020-09-23 05:40:35 +00:00
Jacob Hughes 3f1b4b39e3 Fix compilation & test failures 2020-09-22 22:54:52 -04:00
Avi Dessauer 2793da3f39 Update src/librustc_passes/stability.rs
Co-authored-by: varkor <github@varkor.com>
2020-09-22 21:55:38 -04:00
Avi Dessauer 25dba40cbe Update src/librustc_middle/middle/stability.rs
Co-authored-by: varkor <github@varkor.com>
2020-09-22 21:55:35 -04:00
Avi Dessauer 9eb595705e Update src/librustc_typeck/astconv.rs
Co-authored-by: varkor <github@varkor.com>
2020-09-22 21:55:32 -04:00
Avi Dessauer 41eec9065a Update src/librustc_passes/stability.rs
Co-authored-by: varkor <github@varkor.com>
2020-09-22 21:55:29 -04:00
Avi Dessauer 19e90843a4 Add documentation 2020-09-22 21:55:23 -04:00
Avi Dessauer 3947591ee8 Remove now unneeded check_stability argument 2020-09-22 21:54:16 -04:00
Avi Dessauer a7a2086053 Stability annotations on generic trait parameters 2020-09-22 21:53:48 -04:00
LingMan d76b80768c
Merge two almost identical match arms 2020-09-23 01:09:24 +02:00
bors 6d3acf5129 Auto merge of #76928 - lcnr:opaque-types-cache, r=tmandry
cache types during normalization

partially fixes #75992

reduces the following test from 14 to 3 seconds locally.

cc `@Mark-Simulacrum` would it make sense to add that test to `perf`?
```rust
#![recursion_limit="2048"]
#![type_length_limit="112457564"]

pub async fn h0(v: &String, x: &u64) { println!("{} {}", v, x) }
pub async fn h1(v: &String, x: &u64) { h0(v, x).await }
pub async fn h2(v: &String, x: &u64) { h1(v, x).await }
pub async fn h3(v: &String, x: &u64) { h2(v, x).await }
pub async fn h4(v: &String, x: &u64) { h3(v, x).await }
pub async fn h5(v: &String, x: &u64) { h4(v, x).await }
pub async fn h6(v: &String, x: &u64) { h5(v, x).await }
pub async fn h7(v: &String, x: &u64) { h6(v, x).await }
pub async fn h8(v: &String, x: &u64) { h7(v, x).await }
pub async fn h9(v: &String, x: &u64) { h8(v, x).await }

pub async fn h10(v: &String, x: &u64) { h9(v, x).await }
pub async fn h11(v: &String, x: &u64) { h10(v, x).await }
pub async fn h12(v: &String, x: &u64) { h11(v, x).await }
pub async fn h13(v: &String, x: &u64) { h12(v, x).await }
pub async fn h14(v: &String, x: &u64) { h13(v, x).await }
pub async fn h15(v: &String, x: &u64) { h14(v, x).await }
pub async fn h16(v: &String, x: &u64) { h15(v, x).await }
pub async fn h17(v: &String, x: &u64) { h16(v, x).await }
pub async fn h18(v: &String, x: &u64) { h17(v, x).await }
pub async fn h19(v: &String, x: &u64) { h18(v, x).await }

macro_rules! async_recursive {
    (29, $inner:expr) => { async { async_recursive!(28, $inner) }.await };
    (28, $inner:expr) => { async { async_recursive!(27, $inner) }.await };
    (27, $inner:expr) => { async { async_recursive!(26, $inner) }.await };
    (26, $inner:expr) => { async { async_recursive!(25, $inner) }.await };
    (25, $inner:expr) => { async { async_recursive!(24, $inner) }.await };
    (24, $inner:expr) => { async { async_recursive!(23, $inner) }.await };
    (23, $inner:expr) => { async { async_recursive!(22, $inner) }.await };
    (22, $inner:expr) => { async { async_recursive!(21, $inner) }.await };
    (21, $inner:expr) => { async { async_recursive!(20, $inner) }.await };
    (20, $inner:expr) => { async { async_recursive!(19, $inner) }.await };

    (19, $inner:expr) => { async { async_recursive!(18, $inner) }.await };
    (18, $inner:expr) => { async { async_recursive!(17, $inner) }.await };
    (17, $inner:expr) => { async { async_recursive!(16, $inner) }.await };
    (16, $inner:expr) => { async { async_recursive!(15, $inner) }.await };
    (15, $inner:expr) => { async { async_recursive!(14, $inner) }.await };
    (14, $inner:expr) => { async { async_recursive!(13, $inner) }.await };
    (13, $inner:expr) => { async { async_recursive!(12, $inner) }.await };
    (12, $inner:expr) => { async { async_recursive!(11, $inner) }.await };
    (11, $inner:expr) => { async { async_recursive!(10, $inner) }.await };
    (10, $inner:expr) => { async { async_recursive!(9, $inner) }.await };

    (9, $inner:expr) => { async { async_recursive!(8, $inner) }.await };
    (8, $inner:expr) => { async { async_recursive!(7, $inner) }.await };
    (7, $inner:expr) => { async { async_recursive!(6, $inner) }.await };
    (6, $inner:expr) => { async { async_recursive!(5, $inner) }.await };
    (5, $inner:expr) => { async { async_recursive!(4, $inner) }.await };
    (4, $inner:expr) => { async { async_recursive!(3, $inner) }.await };
    (3, $inner:expr) => { async { async_recursive!(2, $inner) }.await };
    (2, $inner:expr) => { async { async_recursive!(1, $inner) }.await };
    (1, $inner:expr) => { async { async_recursive!(0, $inner) }.await };
    (0, $inner:expr) => { async { h19(&String::from("owo"), &0).await; $inner }.await };
}

async fn f() {
    async_recursive!(14, println!("hello"));
}

fn main() {
    let _ = f();
}
```
r? `@eddyb` requires a perf run.
2020-09-22 22:52:07 +00:00
LingMan c07890543d
Don't use an if guard to check equality with a constant
Match on it directly instead
2020-09-23 00:29:56 +02:00
Simon Vandel Sillesen b6f51d6d6a cleanup cfg after optimization 2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen f472303a93 The optimization should also apply for DropAndReplace 2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen d3338dcf4d Get LocalDefId from source instead of passing in 2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen b4bdaa14f2 Suggestion from review
Co-authored-by: Andreas Jonson <andjo403@users.noreply.github.com>
2020-09-22 23:09:07 +02:00
Simon Vandel Sillesen 290dca1781 MIR pass to remove unneeded drops on types not needing drop
This is heavily dependent on MIR inlining running to actually see the drop statement
2020-09-22 23:09:07 +02:00
Bastian Kauschke 438d229b25 dead_code: look at trait impls even if they don't contain items 2020-09-22 22:13:58 +02:00
Jonas Schievink 4b6a4821b7 Fix dest prop miscompilation around references 2020-09-22 20:19:00 +02:00
Dylan MacKenzie 186d148b4c Use correct feature gate for unsizing casts 2020-09-22 10:22:50 -07:00
Dylan MacKenzie 6044836284 Add `#![feature(const_fn_transmute)]` to `rustc_ast` 2020-09-22 10:22:21 -07:00
Dylan MacKenzie 08e3822d9a Replace missing comment 2020-09-22 10:05:58 -07:00
Dylan MacKenzie d60e204e0a Use the same name everywhere for `is_const_stable_const_fn` 2020-09-22 10:05:58 -07:00
Dylan MacKenzie 3569bb6323 Update const-checker to replicate `qualify_min_const_fn` 2020-09-22 10:05:58 -07:00
Dylan MacKenzie 5ee5429e00 Add structured errors for `qualify_min_const_fn` checks 2020-09-22 10:05:58 -07:00
Dylan MacKenzie bfc10a89c3 Allow errors to abort const checking when emitted
This is a hack for parity with `qualify_min_const_fn`, which only
emitted a single error.
2020-09-22 10:05:58 -07:00
Dylan MacKenzie 7fb9587a3c Return `true` if `check_const` emits an error 2020-09-22 10:05:58 -07:00
Dylan MacKenzie a173c5c1b3 Add const-stability helpers 2020-09-22 10:05:58 -07:00
Dylan MacKenzie 3dd28c78c3 Useful derives on `ops::Status` 2020-09-22 10:05:58 -07:00
bors c113030f6b Auto merge of #76906 - Nicholas-Baron:shorten_typeck_check, r=oli-obk
Split rustc_typeck::check into separate files

Contributing to #60302.
2020-09-22 08:11:07 +00:00
Ralf Jung 731113b8ee Miri: more informative deallocation error messages 2020-09-22 09:05:12 +02:00
Ishi Tatsuyuki 01a771a7d8 Add debug assertions against slow path reference results 2020-09-22 14:40:44 +09:00
ecstatic-morse 0863f9a965
Rollup merge of #77032 - lcnr:visit-all-the-item-likes, r=davidtwco
lint missing docs for extern items

fixes #76991
2020-09-21 20:41:01 -07:00
ecstatic-morse 359615b852
Rollup merge of #77022 - Juici:master, r=lcnr
Reduce boilerplate for BytePos and CharPos

Reduces boilerplate code for BytePos and CharPos by using a macro to implement shared traits.
2020-09-21 20:40:59 -07:00
ecstatic-morse 50d4aebc7a
Rollup merge of #76914 - lcnr:path-no-more, r=ecstatic-morse
extend `Ty` and `TyCtxt` lints to self types

blocked on #76891

r? @ecstatic-morse cc @Aaron1011
2020-09-21 20:40:57 -07:00
ecstatic-morse dcf4d1f2be
Rollup merge of #76888 - matthiaskrgr:clippy_single_match_2, r=Dylan-DPC
use if let instead of single match arm expressions

use if let instead of single match arm expressions to compact code and reduce nesting (clippy::single_match)
2020-09-21 20:40:55 -07:00
ecstatic-morse 60b99015e9
Rollup merge of #76807 - ecstatic-morse:const-checking-staged-api, r=oli-obk
Use const-checking to forbid use of unstable features in const-stable functions

First step towards #76618.

Currently this code isn't ever hit because `qualify_min_const_fn` runs first and catches pretty much everything. One exception is `const_precise_live_drops`, which does not use the newly added code since it runs as part of a separate pass.

Also contains some unrelated refactoring, which is split into separate commits.

r? @oli-obk
2020-09-21 20:40:53 -07:00
ecstatic-morse 30f1bab7e6
Rollup merge of #76581 - lcnr:bound-too-generic, r=eddyb
do not ICE on bound variables, return `TooGeneric` instead

fixes #73260, fixes #74634, fixes #76595

r? @nikomatsakis
2020-09-21 20:40:47 -07:00
ecstatic-morse ef6c3a7bca
Rollup merge of #76489 - GuillaumeGomez:add-explanation-e0756, r=jyn514
Add explanation for E0756

r? @pickfire
2020-09-21 20:40:46 -07:00
ecstatic-morse dc42aa8cd4
Rollup merge of #76131 - Aaron1011:fix/pretty-print-zip, r=lcnr
Don't use `zip` to compare iterators during pretty-print hack

If the right-hand iterator has exactly one more element than the
left-hand iterator, then both iterators will be fully consumed, but
the extra element will never be compared.

Split out from https://github.com/rust-lang/rust/pull/76130
2020-09-21 20:40:39 -07:00
bors 45198456be Auto merge of #76913 - vandenheuvel:performance_debug, r=lcnr
Fixing the performance regression of #76244

Issue https://github.com/rust-lang/rust/issues/74865 suggested that removing the `def_id` field from `ParamEnv` would improve performance. PR https://github.com/rust-lang/rust/pull/76244 implemented this change.

Generally, [results](https://perf.rust-lang.org/compare.html?start=80fc9b0ecb29050d45b17c64af004200afd3cfc2&end=5ef250dd2ad618ee339f165e9b711a1b4746887d) were as expected: an instruction count decrease of about a percent. The instruction count for the unicode crates increased by about 3%, which `@nnethercote` speculated to be caused by a quirk of inlining or codegen. As the results were generally positive, and for chalk integration, this was also a step in the right direction, the PR was r+'d regardless.

However, [wall-time performance results](https://perf.rust-lang.org/compare.html?start=a055c5a1bd95e029e9b31891db63b6dc8258b472&end=7402a394471a6738a40fea7d4f1891666e5a80c5&stat=task-clock) show a much larger performance degradation: 25%, as [mentioned](https://github.com/rust-lang/rust/pull/76244#issuecomment-694459840) by `@Mark-Simulacrum.`

This PR, for now, reverts #76244 and attempts to find out, which change caused the regression.
2020-09-22 00:22:24 +00:00
Bastian Kauschke d452744100 lint missing docs for extern items 2020-09-22 00:02:46 +02:00
Bastian Kauschke 2f893e458a review 2020-09-21 23:25:52 +02:00
Simon Vandel Sillesen 2bb3844820 Add optimization to avoid load of address 2020-09-21 22:08:27 +02:00
Aaron Hill f5d71a9b3c
Don't use `zip` to compare iterators during pretty-print hack
If the right-hand iterator has exactly one more element than the
left-hand iterator, then both iterators will be fully consumed, but
the extra element will never be compared.
2020-09-21 15:11:59 -04:00
Aaron Hill e734733a9e
Record `tcx.def_span` instead of `item.span` in crate metadata
This was missed in PR #75465. As a result, a few places have been using
the full body span of functions, instead of just the header span.
2020-09-21 15:10:16 -04:00
Guillaume Gomez 63195ecb45 Add explanation for E0756 2020-09-21 21:04:56 +02:00
Mara Bos 9e3f94dabc Don't unwrap but report a fatal error for TargetDataLayout::parse. 2020-09-21 20:43:44 +02:00
James Whaley 9a1f1777d3
Remove cast to usize for BytePos and CharPos
The case shouldn't be necessary and implicitly truncating BytePos is not
desirable.
2020-09-21 19:42:43 +01:00
Mara Bos db74e1f1e3 Add cfg(target_has_atomic_equal_alignment).
This is needed for Atomic::from_mut.
2020-09-21 20:42:25 +02:00
Bastian Kauschke 8fc782afc2 add test 2020-09-21 20:36:05 +02:00
bors b01326ab03 Auto merge of #76680 - Julian-Wollersberger:nongeneric_ensure_sufficient_stack, r=jyn514
Make `ensure_sufficient_stack()` non-generic, using cargo-llvm-lines

Inspired by [this blog post](https://blog.mozilla.org/nnethercote/2020/08/05/how-to-speed-up-the-rust-compiler-some-more-in-2020/) from `@nnethercote,` I used [cargo-llvm-lines](https://github.com/dtolnay/cargo-llvm-lines/) on the rust compiler itself, to improve it's compile time. This PR contains only one low-hanging fruit, but I also want to share some measurements.

The function `ensure_sufficient_stack()` was monomorphized 1500 times, and with it the `stacker` and `psm` crates, for a total of 1.5% of all llvm IR lines. With some trickery I convert the generic closure into a dynamic one, and thus all that code is only monomorphized once.

# Measurements
Getting these numbers took some fiddling with CLI flags and I [modified](https://github.com/Julian-Wollersberger/cargo-llvm-lines/blob/master/src/main.rs#L115) cargo-llvm-lines to read from a folder instead of invoking cargo. Commands I used:
```
./x.py clean
RUSTFLAGS="--emit=llvm-ir -C link-args=-fuse-ld=lld -Z self-profile=profile" CARGOFLAGS_BOOTSTRAP="-Ztimings" RUSTC_BOOTSTRAP=1 ./x.py build -i --stage 1 library/std

# Then manually copy all .ll files into a folder I hardcoded in cargo-llvm-lines in main.rs#L115
cd ../cargo-llvm-lines
cargo run llvm-lines
```

The result is this list (see [first 500 lines](https://github.com/Julian-Wollersberger/cargo-llvm-lines/blob/master/llvm-lines-rustc-before.txt) ), before the change:
```
  Lines            Copies        Function name
  -----            ------        -------------
  16894211 (100%)  58417 (100%)  (TOTAL)
   2223855 (13.2%)   502 (0.9%)  rustc_query_system::query::plumbing::get_query_impl::{{closure}}
   1331918 (7.9%)   1287 (2.2%)  hashbrown::raw::RawTable<T>::reserve_rehash
    774434 (4.6%)  12043 (20.6%) core::ptr::drop_in_place
    294170 (1.7%)    499 (0.9%)  rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
    245410 (1.5%)   1552 (2.7%)  psm::on_stack::with_on_stack
    210311 (1.2%)      1 (0.0%)  rustc_target::spec::load_specific
    200962 (1.2%)    513 (0.9%)  rustc_query_system::query::plumbing::get_query_impl
    190704 (1.1%)      1 (0.0%)  rustc_middle::ty::query::<impl rustc_middle::ty::context::TyCtxt>::alloc_self_profile_query_strings
    180272 (1.1%)    468 (0.8%)  rustc_query_system::query::plumbing::load_from_disk_and_cache_in_memory
    177396 (1.1%)    114 (0.2%)  rustc_query_system::query::plumbing::force_query_impl
    161134 (1.0%)    445 (0.8%)  rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
    141551 (0.8%)    186 (0.3%)  rustc_query_system::query::plumbing::incremental_verify_ich
    110191 (0.7%)      7 (0.0%)  rustc_middle::ty::context::_DERIVE_rustc_serialize_Decodable_D_FOR_TypeckResults::<impl rustc_serialize::serialize::Decodable<__D> for rustc_middle::ty::context::TypeckResults>::decode::{{closure}}
    108590 (0.6%)    420 (0.7%)  core::ops::function::FnOnce::call_once
     88488 (0.5%)     21 (0.0%)  rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
     86368 (0.5%)      1 (0.0%)  rustc_middle::ty::query::stats::query_stats
     85654 (0.5%)   3973 (6.8%)  <&T as core::fmt::Debug>::fmt
     84475 (0.5%)      1 (0.0%)  rustc_middle::ty::query::Queries::try_collect_active_jobs
     81220 (0.5%)    862 (1.5%)  <hashbrown::raw::RawIterHash<T> as core::iter::traits::iterator::Iterator>::next
     77636 (0.5%)     54 (0.1%)  core::slice::sort::recurse
     66484 (0.4%)    461 (0.8%)  <hashbrown::raw::RawIter<T> as core::iter::traits::iterator::Iterator>::next
```

All `.ll` files together had 4.4GB. After my change they had 4.2GB. So a few percent less code LLVM has to process. Hurray!
Sadly, I couldn't measure an actual wall-time improvement. Watching YouTube while compiling added to much noise...

Here is the top of the list after the change:
```
  16460866 (100%)  58341 (100%)  (TOTAL)
   1903085 (11.6%)   504 (0.9%)  rustc_query_system::query::plumbing::get_query_impl::{{closure}}
   1331918 (8.1%)   1287 (2.2%)  hashbrown::raw::RawTable<T>::reserve_rehash
    777796 (4.7%)  12031 (20.6%) core::ptr::drop_in_place
    551462 (3.4%)   1519 (2.6%)  rustc_data_structures::stack::ensure_sufficient_stack::{{closure}}
```
Note that the total was reduced by 430 000 lines and `psm::on_stack::with_on_stack` has disappeared. Instead `rustc_data_structures::stack::ensure_sufficient_stack::{{closure}}` appeared. I'm confused about that one, but it seems to consist of inlined calls to `rustc_query_system::*` stuff.

Further note the other two big culprits in this list: `rustc_query_system` and `hashbrown`. These two are monomorphized many times, the query system summing to more than 20% of all lines, not even counting code that's probably inlined elsewhere.
Assuming compile times scale linearly with llvm-lines, that means a possible 20% compile time reduction.

Reducing eg. `get_query_impl` would probably need a major refactoring of the qery system though. _Everything_ in there is generic over multiple types, has associated types and passes generic Self arguments by value. Which means you can't simply make things `dyn`.

---------------------------------------
This PR is a small step to make rustc compile faster and thus make contributing to rustc less painful. Nonetheless I love Rust and I find the work around rustc fascinating :)
2020-09-21 17:32:57 +00:00
James Whaley b4b4a2f092
Reduce boilerplate for BytePos and CharPos 2020-09-21 18:27:43 +01:00
Nicholas-Baron ccd218d04c Added back the '// ignore-file-length' with an explanation 2020-09-21 09:16:55 -07:00
bors 4eff9b0b29 Auto merge of #77013 - RalfJung:rollup-84ut0xq, r=RalfJung
Rollup of 10 pull requests

Successful merges:

 - #76439 (Add error explanation for E0755)
 - #76521 (Fix segfault if pthread_getattr_np fails)
 - #76835 (make replace_prefix only take &str as arguments )
 - #76967 (Revert adding Atomic::from_mut.)
 - #76977 (Add a regression test for copy propagation miscompilation)
 - #76981 (liballoc bench use imported path Bencher)
 - #76983 (BTreeMap: extra testing & fixed comments)
 - #76996 (Fix typo in rustc_lexer docs)
 - #77009 (Dogfood total_cmp in the test crate)
 - #77012 (update Miri for another bugfix)

Failed merges:

 - #76489 (Add explanation for E0756)

r? `@ghost`
2020-09-21 15:06:20 +00:00
Oliver Scherer f12583a330 Pacify tidy 2020-09-21 16:38:29 +02:00
Tomasz Miąsko c7e887c64a DroplessArena: Allocate objects from the end of memory chunk
Allocating from the end of memory chunk simplifies the alignment code
and reduces the number of checked arithmetic operations.
2020-09-21 15:36:45 +02:00
Ralf Jung 48fc20cc47
Rollup merge of #76996 - LingMan:patch-1, r=ecstatic-morse
Fix typo in rustc_lexer docs

Also add an Oxford comma while we're editing that line.
2020-09-21 15:30:47 +02:00
Ralf Jung 982c4a9c25
Rollup merge of #76835 - matthiaskrgr:replace_prefix, r=lcnr
make replace_prefix only take &str as arguments

included the clippy::manual strip commit to not run into merge conflicts later.

r? @lcnr
2020-09-21 15:30:39 +02:00
Ralf Jung 670e204ace
Rollup merge of #76439 - GuillaumeGomez:add-error-explanation-e0755, r=pickfire,jyn514
Add error explanation for E0755

r? @pickfire
2020-09-21 15:30:34 +02:00
bors e0bf356f9e Auto merge of #74040 - lcnr:const-occurs-check, r=nikomatsakis
fix unification of const variables

r? `@nikomatsakis` `@varkor` `@eddyb` let's just ping everyone here 😅
2020-09-21 12:52:09 +00:00
Oliver Scherer f7eceef653 Document future incompat lints 2020-09-21 14:27:14 +02:00
Ishi Tatsuyuki f95e4f3ca9 Improve code and documentation clarity 2020-09-21 20:29:12 +09:00
Bastian Kauschke 073127a04f check for cycles when unifying const variables 2020-09-21 12:27:55 +02:00
bors 956e06c6c8 Auto merge of #77004 - RalfJung:rollup-usac4nv, r=RalfJung
Rollup of 13 pull requests

Successful merges:

 - #76135 (Stabilize some Option methods as const)
 - #76628 (Add sample defaults for config.toml )
 - #76846 (Avoiding unnecesary allocations at rustc_errors)
 - #76867 (Use intra-doc links in core/src/iter when possible)
 - #76868 (Finish moving to intra doc links for std::sync)
 - #76872 (Remove DeclareMethods)
 - #76936 (Add non-`unsafe` `.get_mut()` for `Unsafecell`)
 - #76958 (Replace manual as_nanos and as_secs_f64 reimplementations)
 - #76959 (Replace write_fmt with write!)
 - #76961 (Add test for issue #34634)
 - #76962 (Use const_cstr macro in consts.rs)
 - #76963 (Remove unused static_assert macro)
 - #77000 (update Miri)

Failed merges:

r? `@ghost`
2020-09-21 10:26:59 +00:00
Bastian Kauschke 39245400c5 fix InterpCx resolve 2020-09-21 12:09:08 +02:00
Oliver Scherer c160bf3c3e Cache `eval_to_allocation_raw` on disk 2020-09-21 11:38:39 +02:00
Ralf Jung e177757a04
Rollup merge of #76963 - est31:remove_static_assert, r=oli-obk
Remove unused static_assert macro
2020-09-21 10:40:47 +02:00
Ralf Jung 9aba4962f5
Rollup merge of #76962 - est31:const_cstr, r=oli-obk
Use const_cstr macro in consts.rs
2020-09-21 10:40:45 +02:00
Ralf Jung 048866bd6b
Rollup merge of #76958 - est31:ns, r=oli-obk
Replace manual as_nanos and as_secs_f64 reimplementations
2020-09-21 10:40:39 +02:00
Ralf Jung 02d787bef8
Rollup merge of #76872 - khyperia:remove_declare_methods, r=eddyb
Remove DeclareMethods

Most of the `DeclareMethods` API was only used internally by rustc_codegen_llvm. As such, it makes no sense to require other backends to implement them.

(`get_declared_value` and `declare_cfn` were used, in one place, specific to the `main` symbol, which I've replaced with a more specialized function to allow more flexibility in implementation - the intent is that `declare_c_main` can go away once we do something more clever, e.g. @eddyb has ideas around having a MIR shim or somesuch we can explore in a follow-up PR)
2020-09-21 10:40:35 +02:00
Ralf Jung c2d9af68a0
Rollup merge of #76846 - botika:master, r=davidtwco
Avoiding unnecesary allocations at rustc_errors

Simplify the code avoiding allocations with easy alternative
2020-09-21 10:40:30 +02:00
bors 0433fdf93b Auto merge of #76843 - kornelski:longtypetofile, r=ecstatic-morse
Let user see the full type of type-length limit error

Seeing the full type of the error is sometimes essential to diagnosing the problem, but the type itself is too long to be displayed in the terminal in a useful fashion. This change solves this dilemma by writing the full offending type name to a file, and displays this filename as a note.

> note: the full type name been written to '$TEST_BUILD_DIR/issues/issue-22638/issue-22638.long-type.txt'

Closes #76777
2020-09-21 08:20:38 +00:00
Bram van den Heuvel ab83d372ed Add an unused field of type `Option<DefId>` to `ParamEnv` struct. 2020-09-21 09:39:26 +02:00
LingMan fc20b7841c
Fix typo in rustc_lexer docs
Also add an Oxford comma while we're editing that line.
2020-09-21 05:43:39 +02:00
LingMan a6ff925f8b Reduce boilerplate with the matches! macro
Replaces simple bool `match`es of the form

    match $expr {
        $pattern => true
        _ => false
    }

and their inverse with invocations of the matches! macro.
2020-09-21 05:28:40 +02:00
yuk1ty 16047d46a1 fix typo in docs and comments 2020-09-21 12:14:28 +09:00
Nicholas-Baron 99e2e7075c Moved all functions prefixed with 'check' to a separate file 2020-09-20 19:00:31 -07:00
Nicholas-Baron f896ddfc73 Moved the Expectation enum to its own file 2020-09-20 18:58:32 -07:00
Nicholas-Baron 428a8c6eae Moved the Diverges struct to its own file 2020-09-20 18:58:32 -07:00
Nicholas-Baron b1e9379679 Formatted use statements for fewer lines 2020-09-20 18:58:32 -07:00
Nicholas-Baron 7995d5cda4 Moved Inherited struct to own file 2020-09-20 18:58:30 -07:00
Nicholas-Baron 45fdf97d11 Removed util.rs
Per suggestion of @oli-obk.
This file was rather short and joining it did not cause mod.rs to become
significantly bigger.
2020-09-20 18:56:09 -07:00
Nicholas-Baron c8162c22eb Moved the FnCtxt struct to its own file 2020-09-20 18:56:01 -07:00
Nicholas-Baron c190f66060 Moved GatherLocalsVisitor to its own file 2020-09-20 18:48:31 -07:00
Nicholas-Baron 3e770645aa Moved a struct only need by util into util 2020-09-20 18:48:31 -07:00
Nicholas-Baron 6fd80e35e0 Moved another struct and used pub(super) to be explicit 2020-09-20 18:48:31 -07:00
Nicholas-Baron bfe5bc9cb9 Formatter moved one use statement 2020-09-20 18:48:31 -07:00
Nicholas-Baron 63dbfb3c30 Start of moving some functionality to separate files 2020-09-20 18:48:31 -07:00
bors 0f9f0b384a Auto merge of #76295 - mati865:remove-mmx, r=Amanieu,oli-obk
Remove MMX from Rust

Follow-up to https://github.com/rust-lang/stdarch/pull/890
This removes most of MMX from Rust (tests pass with small changes), keeping stable `is_x86_feature_detected!("mmx")` working.
2020-09-21 00:43:26 +00:00
Kornel Lesiński 34d3c7df80 Let user see the full type of type-length limit error 2020-09-21 00:39:58 +01:00
Hanif Bin Ariffin dc655b2842 Prevent stackoverflow 2020-09-21 04:20:41 +08:00
bors 2e0edc0f28 Auto merge of #75119 - simonvandel:early-otherwise, r=oli-obk
New MIR optimization pass to reduce branches on match of tuples of enums

Fixes #68867 by adding a new pass that turns something like
```rust
let x: Option<()>;
let y: Option<()>;
match (x,y) {
    (Some(_), Some(_)) => {0},
    _ => {1}
}
```
into something like
```rust
let x: Option<()>;
let y: Option<()>;
let discriminant_x = // get discriminant of x
let discriminant_y = // get discriminant of x
if discriminant_x != discriminant_y {1} else {0}
```

The opt-diffs still have the old basic blocks like
```
bb3: {
          _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early-otherwise-branch-68867.rs:21:21: 21:30
          switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early-otherwise-branch-68867.rs:21:21: 21:30
      }

      bb4: {
          _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early-otherwise-branch-68867.rs:22:23: 22:34
          switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early-otherwise-branch-68867.rs:22:23: 22:34
      }

      bb5: {
          _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early-otherwise-branch-68867.rs:23:23: 23:34
          switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early-otherwise-branch-68867.rs:23:23: 23:34
      }
```

These do get removed on later passes. I'm not sure if I should include those passes in the test to make it clear?
2020-09-20 17:54:44 +00:00
Julian Wollersberger 53aaa1e532 To avoid monomorphizing `psm::on_stack::with_on_stack` 1500 times, I made a change in `stacker` to wrap the callback in `dyn`. 2020-09-20 19:07:52 +02:00
Oliver Scherer adf98ab2dc Use precise errors during const to pat conversion instead of a catch-all on the main constant 2020-09-20 18:42:15 +02:00
Oliver Scherer aba5ea1430 Lint on function pointers used in patterns 2020-09-20 18:42:15 +02:00
Oliver Scherer 3795886f7e Split check for `PartialEq` impl into a method 2020-09-20 16:59:15 +02:00
Lzu Tao 4387480dea Add unstably const support for assume intrinsic 2020-09-20 14:00:40 +00:00
Ralf Jung fc58224b79
Rollup merge of #76940 - Aaron1011:fix/trait-on-tait, r=oli-obk
Don't allow implementing trait directly on type-alias-impl-trait

This is specifically disallowed by the RFC, but we never added a check
for it.

Fixes #76202
2020-09-20 15:52:09 +02:00
Ralf Jung 7ff17c13bc
Rollup merge of #76910 - lcnr:foreign-item-like, r=oli-obk
transmute: use diagnostic item

closes #66075, we now have no remaining uses of `match_def_path`  in the compiler while some uses still remain in `clippy`.

cc @RalfJung
2020-09-20 15:52:04 +02:00
Ralf Jung 9567b5a9f5
Rollup merge of #76891 - lcnr:less-ref, r=ecstatic-morse
don't take `TyCtxt` by reference

small cleanup
2020-09-20 15:52:03 +02:00
Ralf Jung 8405d50e12
Rollup merge of #76890 - matthiaskrgr:matches_simpl, r=lcnr
use matches!() macro for simple if let conditions
2020-09-20 15:52:01 +02:00
Ralf Jung c847eaa91d
Rollup merge of #76832 - khyperia:backend_target_override, r=eddyb
Let backends define custom targets

Add a target_override hook that takes priority over builtin targets.
2020-09-20 15:51:48 +02:00
Ralf Jung 39b9a25e60
Rollup merge of #76732 - camelid:mir-basic-block-docs, r=RalfJung
Add docs for `BasicBlock`

Fixes #76715.

---

@rustbot modify labels: A-mir T-doc C-enhancement
2020-09-20 15:51:46 +02:00
Lzu Tao 3e08354fb0 Correct file path after some restructures in compiler 2020-09-20 13:48:16 +00:00
Mateusz Mikuła 5de2c95e6e Remove MMX from Rust 2020-09-20 15:13:11 +02:00
Simon Vandel Sillesen e25738f529 enable on mir-opt-level=1 to test perf 2020-09-20 14:45:47 +02:00
Simon Vandel Sillesen 27068cbfdc add cleanup of cfg 2020-09-20 14:45:47 +02:00
Simon Vandel Sillesen 118aae2af1 insert storageDead for not equal temp 2020-09-20 14:45:47 +02:00
Simon Vandel Sillesen 2530274023 correct comment 2020-09-20 14:45:46 +02:00
Simon Vandel Sillesen 5cc93950ac Update src/librustc_mir/transform/early_otherwise_branch.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-09-20 14:45:46 +02:00
Simon Vandel Sillesen 5fb32c2e33 New MIR optimization pass to reduce branches on match of tuples of enums 2020-09-20 14:45:46 +02:00
Oliver Scherer b2532a8730 Implement destructuring for all aggregates and for references 2020-09-20 13:28:18 +02:00
bors 41507ed0d5 Auto merge of #76964 - RalfJung:rollup-ybn06fs, r=RalfJung
Rollup of 15 pull requests

Successful merges:

 - #76722 (Test and fix Send and Sync traits of BTreeMap artefacts)
 - #76766 (Extract some intrinsics out of rustc_codegen_llvm)
 - #76800 (Don't generate bootstrap usage unless it's needed)
 - #76809 (simplfy condition in ItemLowerer::with_trait_impl_ref())
 - #76815 (Fix wording in mir doc)
 - #76818 (Don't compile regex at every function call.)
 - #76821 (Remove redundant nightly features)
 - #76823 (black_box: silence unused_mut warning when building with cfg(miri))
 - #76825 (use `array_windows` instead of `windows` in the compiler)
 - #76827 (fix array_windows docs)
 - #76828 (use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip))
 - #76840 (Move to intra doc links in core/src/future)
 - #76845 (Use intra docs links in core::{ascii, option, str, pattern, hash::map})
 - #76853 (Use intra-doc links in library/core/src/task/wake.rs)
 - #76871 (support panic=abort in Miri)

Failed merges:

r? `@ghost`
2020-09-20 11:02:36 +00:00
Oliver Scherer 34c62e0abc Add a query for dereferencing constants of reference type 2020-09-20 12:42:44 +02:00
Oliver Scherer b54f122a1c Merge tuple and struct pattern generation. 2020-09-20 12:31:37 +02:00
Ralf Jung bfa1904765
Rollup merge of #76828 - matthiaskrgr:clippy_manual_strip, r=lcnr
use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip)
2020-09-20 12:08:29 +02:00
Ralf Jung 50d56bc774
Rollup merge of #76825 - lcnr:array-windows-apply, r=varkor
use `array_windows` instead of `windows` in the compiler

I do think these changes are beautiful, but do have to admit that using type inference for the window length
can easily be confusing. This seems like a general issue with const generics, where inferring constants adds an additional
complexity which users have to learn and keep in mind.
2020-09-20 12:08:26 +02:00
Ralf Jung 4322e1b92d
Rollup merge of #76821 - est31:remove_redundant_nightly_features, r=oli-obk,Mark-Simulacrum
Remove redundant nightly features

Removes a bunch of redundant/outdated nightly features. The first commit removes a `core_intrinsics` use for which a stable wrapper has been provided since. The second commit replaces the `const_generics` feature with `min_const_generics` which might get stabilized this year. The third commit is the result of a trial/error run of removing every single feature and then adding it back if compile failed. A bunch of unused features are the result that the third commit removes.
2020-09-20 12:08:22 +02:00
Ralf Jung 3268e33199
Rollup merge of #76818 - hbina:dont_compile_regex_all_the_time, r=ecstatic-morse
Don't compile regex at every function call.

Use `SyncOnceCell` to only compile it once.
I believe this still adds some kind of locking mechanism?

Related issue: https://github.com/rust-lang/rust/issues/76817
2020-09-20 12:08:20 +02:00
Ralf Jung c12feb35db
Rollup merge of #76815 - pickfire:patch-6, r=jonas-schievink
Fix wording in mir doc
2020-09-20 12:08:19 +02:00
Ralf Jung 9b9192a2d5
Rollup merge of #76809 - matthiaskrgr:simplify_cond, r=varkor
simplfy condition in ItemLowerer::with_trait_impl_ref()
2020-09-20 12:08:17 +02:00
Ralf Jung 2911b8cb30
Rollup merge of #76766 - khyperia:generic_intrinsics, r=eddyb
Extract some intrinsics out of rustc_codegen_llvm

A significant amount of intrinsics do not actually need backend-specific behaviors to be implemented, instead relying on methods already in rustc_codegen_ssa. So, extract those methods out to rustc_codegen_ssa, so that each backend doesn't need to reimplement the same code.

Almost everything should be a pretty direct translation. A notable not-direct-translation is `add_with_overflow` and friends being changed to `bx.checked_binop`, but it's pretty simple.

I could have been a lot more aggressive here and pulled out way more methods, and add a few new methods in the rustc_codegen_ssa "API". However, because this is my second rustc PR, I thought that moving those to a follow-up PR and doing more incremental changes here would be better (and I guess ask if this work is even desired in the first place). I'm hoping to eventually remove the mess of intrinsic handling in the backend entirely, which would be hecking fantastic 
2020-09-20 12:08:13 +02:00
Matthias Krüger c690c82ad4 use if let instead of single match arm expressions to compact code and reduce nesting (clippy::single_match) 2020-09-20 11:42:52 +02:00
est31 c2dad1c6b9 Remove unused static_assert macro 2020-09-20 11:40:51 +02:00
est31 812ff66803 Use const_cstr macro in consts.rs 2020-09-20 11:34:34 +02:00
bors 5e449b9adf Auto merge of #74949 - oli-obk:validate_const_eval_raw, r=RalfJung
Validate constants during `const_eval_raw`

This PR implements the groundwork for https://github.com/rust-lang/rust/issues/72396

* constants are now validated during `const_eval_raw`
* to prevent cycle errors, we do not validate references to statics anymore beyond the fact that they are not dangling
* the `const_eval` query ICEs if used on `static` items
* as a side effect promoteds are now evaluated to `ConstValue::Scalar` again (since they are just a reference to the actual promoted allocation in most cases).
2020-09-20 08:58:32 +00:00
est31 43193dcb88 Use as_secs_f64 in profiling.rs 2020-09-20 10:27:14 +02:00
est31 cebbd9fcd3 Use as_nanos in bench.rs and base.rs 2020-09-20 10:16:01 +02:00
Bastian Kauschke 6734230425 do not ICE on `ty::Bound` in Layout::compute 2020-09-20 08:22:35 +02:00
Bastian Kauschke 2a00dda902 miri: correctly deal with `ConstKind::Bound` 2020-09-20 08:22:35 +02:00
bors 10b3595ba6 Auto merge of #76411 - RalfJung:promote-in-const-fn, r=ecstatic-morse
Some promotion cleanup

Based on top of both https://github.com/rust-lang/rust/pull/75502 and https://github.com/rust-lang/rust/pull/75585, this does some cleanup of the promotion code. The last 2 commits are new.

* Remove the remaining cases where `const fn` is treated different from `fn`. This means no longer promoting ptr-to-int casts, raw ptr operations, and union field accesses in `const fn` -- or anywhere, for that matter. These are all unstable in const-context so this should not break any stable code. Fixes https://github.com/rust-lang/rust/issues/75586.
* ~~Promote references to statics even outside statics (i.e., in functions) for consistency.~~
* Promote `&mut []` everywhere, not just in non-`const` functions, for consistency.
* Explain why we do not promote deref's of statics outside statics. ~~(This is the only remaining direct user of `const_kind`.)~~

This can only land once the other two PRs land; I am mostly putting this up already because I couldn't wait ;) and to get some feedback from `@rust-lang/wg-const-eval` .
2020-09-20 06:20:16 +00:00
Bastian Kauschke bfb221b21e array pattern 2020-09-20 08:11:05 +02:00
Bastian Kauschke 3435683fd5 use `array_windows` instead of `windows` in the compiler 2020-09-20 08:11:05 +02:00
bors a3bc0e752f Auto merge of #75346 - davidtwco:issue-69925-polymorphic-instancedef-fnptrshim, r=nikomatsakis
shim: monomorphic `FnPtrShim`s during construction

Fixes #69925.

This PR adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`).

r? `@eddyb`
2020-09-20 04:15:43 +00:00
bors 255a4c58f5 Auto merge of #72632 - jonas-schievink:dest-prop, r=oli-obk
Implement a generic Destination Propagation optimization on MIR

This takes the work that was originally started by `@eddyb` in https://github.com/rust-lang/rust/pull/47954, and then explored by me in https://github.com/rust-lang/rust/pull/71003, and implements it in a general (ie. not limited to acyclic CFGs) and dataflow-driven way (so that no additional infrastructure in rustc is needed).

The pass is configured to run at `mir-opt-level=2` and higher only. To enable it by default, some followup work on it is still needed:
* Performance needs to be evaluated. I did some light optimization work and tested against `tuple-stress`, which caused trouble in my last attempt, but didn't go much in depth here.
  * We can also enable the pass only at `opt-level=2` and higher, if it is too slow to run in debug mode, but fine when optimizations run anyways.
* Debuginfo needs to be fixed after locals are merged. I did not look into what is required for this.
* Live ranges of locals (aka `StorageLive` and `StorageDead`) are currently deleted. We either need to decide that this is fine, or if not, merge the variable's live ranges (or remove these statements entirely – https://github.com/rust-lang/rust/issues/68622).

Some benchmarks of the pass were done in https://github.com/rust-lang/rust/pull/72635.
2020-09-20 01:38:26 +00:00
Simon Vandel Sillesen a875c7a1ea Add assertion for len of vecs 2020-09-19 23:22:54 +02:00
Aaron Hill 367efa86d5
Don't allow implementing trait directly on type-alias-impl-trait
This is specifically disallowed by the RFC, but we never added a check
for it.

Fixes #76202
2020-09-19 17:10:54 -04:00
Bastian Kauschke 30cbc97296 words 2020-09-19 22:27:52 +02:00
Bastian Kauschke d4039c55c9 wip emit errors during AbstractConst building 2020-09-19 22:17:52 +02:00
Ralf Jung 9216eb8258 fix some comments 2020-09-19 22:14:17 +02:00
Ralf Jung 7b99c8e1cf never promote non-const operations; revert STATIC promotion change 2020-09-19 22:14:17 +02:00
Ralf Jung 7febd5a257 fix doc comment 2020-09-19 22:14:17 +02:00
Ralf Jung 4d1ef03c9e cleanup promotion const_kind checks
in particular allow a few more promotions for consistency when they were already allowed in other contexts
2020-09-19 22:14:17 +02:00
Bastian Kauschke 1146c39da7 cache types during normalization 2020-09-19 17:27:13 +02:00
Simon Vandel Sillesen 738ed9b5ec Fix #76803
Check that the variant index matches the target value from the SwitchInt we came from
2020-09-19 15:40:15 +02:00
Bastian Kauschke bfa2030ccb update docs 2020-09-19 15:36:53 +02:00
bors b3aae050cd Auto merge of #76880 - shepmaster:cc-rs, r=Mark-Simulacrum
Update cc crate to 1.0.60 to understand aarch64-apple-darwin with clang

r? `@Mark-Simulacrum`

/cc `@alexcrichton`
2020-09-19 13:31:23 +00:00
ishitatsuyuki 7c98f6f584 Add fast path for match checking 2020-09-19 22:00:10 +09:00
bors 8e9d5db839 Auto merge of #76912 - RalfJung:rollup-q9ur56h, r=RalfJung
Rollup of 14 pull requests

Successful merges:

 - #73963 (deny(unsafe_op_in_unsafe_fn) in libstd/path.rs)
 - #75099 (lint/ty: move fns to avoid abstraction violation)
 - #75502 (Use implicit (not explicit) rules for promotability by default in `const fn`)
 - #75580 (Add test for checking duplicated branch or-patterns)
 - #76310 (Add `[T; N]: TryFrom<Vec<T>>` (insta-stable))
 - #76400 (Clean up vec benches bench_in_place style)
 - #76434 (do not inline black_box when building for Miri)
 - #76492 (Add associated constant `BITS` to all integer types)
 - #76525 (Add as_str() to string::Drain.)
 - #76636 (assert ScalarMaybeUninit size)
 - #76749 (give *even better* suggestion when matching a const range)
 - #76757 (don't convert types to the same type with try_into (clippy::useless_conversion))
 - #76796 (Give a better error message when x.py uses the wrong stage for CI)
 - #76798 (Build fixes for RISC-V 32-bit Linux support)

Failed merges:

r? `@ghost`
2020-09-19 11:29:00 +00:00
Bastian Kauschke 67f319c30b take `TyCtxt` by value 2020-09-19 12:41:12 +02:00
Bastian Kauschke a219ad64a6 extend `is_ty_or_ty_ctxt` to self types 2020-09-19 12:41:12 +02:00
Bastian Kauschke f7d5080ec3 don't take `TyCtxt` by reference 2020-09-19 12:41:12 +02:00
Ralf Jung 4831523ac4
Rollup merge of #76757 - matthiaskrgr:clippy_try_into, r=lcnr
don't convert types to the same type with try_into (clippy::useless_conversion)
2020-09-19 11:47:52 +02:00
Ralf Jung 5631b5d684
Rollup merge of #76749 - guswynn:hir_ranges, r=estebank
give *even better* suggestion when matching a const range

notice that the err already has "constant defined here"
so this is now *exceedingly clear*

extension to #76222

r? @estebank
2020-09-19 11:47:50 +02:00
Ralf Jung 8a7cb1eac1
Rollup merge of #76636 - RalfJung:miri-size-assert, r=oli-obk
assert ScalarMaybeUninit size

I noticed most low-level Miri types have such an assert but `ScalarMaybeUninit` does not, so let's add that. Good t see that the `Option`-like optimization kicks in and this is no bigger than `Scalar`. :)

r? @oli-obk
2020-09-19 11:47:49 +02:00
Ralf Jung fef3324043
Rollup merge of #76492 - fusion-engineering-forks:int-bits, r=dtolnay
Add associated constant `BITS` to all integer types

Recently I've regularly come across this snippet (in a few different crates, including `core` and `std`):
```rust
std::mem::size_of<usize>() * 8
```

I think it's time for a `usize::BITS`.
2020-09-19 11:47:45 +02:00
Ralf Jung f62ba52f5c
Rollup merge of #75502 - ecstatic-morse:implicit-promotion-in-const-fn, r=RalfJung
Use implicit (not explicit) rules for promotability by default in `const fn`

For crater run. See https://github.com/rust-lang/const-eval/pull/54#discussion_r469995552.

cc #75586
2020-09-19 11:47:35 +02:00
Ralf Jung aa25f9ebd8
Rollup merge of #75099 - davidtwco:is-zst-abstraction-violation, r=eddyb
lint/ty: move fns to avoid abstraction violation

This PR moves `transparent_newtype_field` and `is_zst` to `LateContext` where they are used, rather than being on the `VariantDef` and `TyS` types, hopefully addressing @eddyb's concern [from this comment](https://github.com/rust-lang/rust/pull/74340#discussion_r456534910).
2020-09-19 11:47:34 +02:00
Bastian Kauschke 0eecbd4f97 wording 2020-09-19 11:33:11 +02:00
Bastian Kauschke 4debbdc6b9 transmute: use diagnostic item 2020-09-19 11:33:11 +02:00
bors fd702d2919 Auto merge of #76886 - Aaron1011:fix/ensure-stack-predicate, r=Mark-Simulacrum
Wrap recursive predicate evaluation with `ensure_sufficient_stack`

I haven't been able to come up with a minimized test case for #76770,
but this fixes a stack overflow in rustc as well.
2020-09-19 09:21:22 +00:00
Oliver Scherer b8e6883a2f Reflect the "do not call this query directly" mentality in its name 2020-09-19 10:57:14 +02:00
Oliver Scherer c3c8c981a8 Rustfmt 2020-09-19 10:36:36 +02:00
Oliver Scherer 182ed8544d Address review comments 2020-09-19 10:36:36 +02:00
Oliver Scherer 888afd50d9 Unify the names of const eval queries and their return types 2020-09-19 10:36:36 +02:00
Oliver Scherer 69a6be73e6 Rename const eval queries to reflect the validation changes 2020-09-19 10:36:36 +02:00
Oliver Scherer dd9702a059 Do not call the `const_eval` query in mir interpretation except for caching of nulary intrinsics 2020-09-19 10:36:36 +02:00
Oliver Scherer 48f366fced Replace `and_then` `map_err` `and_then` chain with a match 2020-09-19 10:36:36 +02:00
Oliver Scherer b1bd34df0c `turn_into_const` is infallible 2020-09-19 10:36:36 +02:00
Oliver Scherer 4397d66d42 Document `op_to_const`'s purpose 2020-09-19 10:36:36 +02:00
Oliver Scherer 2d7ac728e4 Stop using the `const_eval` query for initializers of statics
As a side effect, we now represent most promoteds as `ConstValue::Scalar` again. This is useful because all implict promoteds are just references anyway and most explicit promoteds are numeric arguments to `asm!` or SIMD instructions.
2020-09-19 10:36:36 +02:00
Oliver Scherer 083f1d7a37 Validate constants during `const_eval_raw` 2020-09-19 10:36:36 +02:00
Mara Bos 1e2dba1e7c Use `T::BITS` instead of `size_of::<T> * 8`. 2020-09-19 06:54:42 +02:00
bors a2c82df1f5 Auto merge of #76838 - est31:dogfood_uninit_features, r=oli-obk
Dogfood new_uninit and maybe_uninit_slice in rustc_arena

Dogfoods a few cool `MaybeUninit` related features in the compiler's rustc_arena crate.

Split off from #76821

r? `@oli-obk`
2020-09-19 02:21:19 +00:00
Jonas Schievink 2f9271b14c Clarify FIXME 2020-09-18 21:23:01 +02:00
Jonas Schievink ffd9445812 Return `Place` by value 2020-09-18 21:23:01 +02:00
Jonas Schievink 682de94e31 Move inner items outside 2020-09-18 21:23:01 +02:00
Jonas Schievink cd5d7201ad Fix rebase fallout 2020-09-18 21:23:01 +02:00
Jonas Schievink 7af964fecf Limit block count 2020-09-18 21:23:01 +02:00
Jonas Schievink 5728834448 Fix rebase fallout 2020-09-18 21:23:01 +02:00
Jonas Schievink 484db5b08a Properly inherit conflicts when merging locals 2020-09-18 21:23:01 +02:00
Jonas Schievink 934634eacc More logging 2020-09-18 21:23:01 +02:00
Jonas Schievink 88538adf9a Record intra-statement/terminator conflicts
Some MIR statements and terminators have an (undocumented...) invariant
that some of their input and outputs must not overlap. This records
conflicts between locals used in these positions.
2020-09-18 21:23:01 +02:00
Jonas Schievink ddd6930b54 perf: bail out when there's >500 candidate locals 2020-09-18 21:23:01 +02:00
Jonas Schievink ab26fb140c perf: only calculate conflicts for candidates 2020-09-18 21:23:01 +02:00
Jonas Schievink 402f863d8a perf: walk liveness backwards in Conflicts::build 2020-09-18 21:23:00 +02:00
Jonas Schievink 812d4bbc8d Fix dataflow assert errors 2020-09-18 21:23:00 +02:00
Jonas Schievink 78ff69ba10 Implement a destination propagation pass 2020-09-18 21:23:00 +02:00