First iteration of simplify match branches
This is a simple MIR pass that attempts to convert
```
bb0: {
StorageLive(_2);
_3 = discriminant(_1);
switchInt(move _3) -> [0isize: bb2, otherwise: bb1];
}
bb1: {
_2 = const false;
goto -> bb3;
}
bb2: {
_2 = const true;
goto -> bb3;
}
```
into
```
bb0: {
StorageLive(_2);
_3 = discriminant(_1);
_2 = _3 == 0;
goto -> bb3;
}
```
There are still missing components(like checking if the assignments are bools).
Was hoping that this could get some review though.
Handles #75141
r? @oli-obk
We already have builders which built standard library *test*s without
optimizations, but we previously did not have builders which built the standard
library itself without optimizations and then tested that.
This adds those builds for i686 and x86_64 linux.
Link sanitizers when creating dynamic libraries on macOS
Link sanitizer runtime when creating dynamic libraries on macOS
to resolve sanitizer runtime symbols and avoid failure at link time.
Closes#74571.
Configure CMAKE_SYSTEM_NAME when cross-compiling in `configure_cmake`,
to tell CMake about target system. Previously this was done only for
LLVM step and now applies more generally to steps using cmake.
Add `array` lang item and `[T; N]::map(f: FnMut(T) -> S)`
This introduces an `array` lang item so functions can be defined on top of `[T; N]`. This was previously not done because const-generics was not complete enough to allow for this. Now it is in a state that is usable enough to start adding functions.
The function added is a monadic (I think?) map from `[T; N] -> [S; N]`. Until transmute can function on arrays, it also allocates an extra temporary array, but this can be removed at some point.
r? @lcnr
Add a bunch of const-generic revisions for `min_const_generics`
This adds a bunch of revisions to `const-generic` tests which is part of #75279, but doesn't cover everything.
r? @lcnr
Move platform support to the rustc book.
This moves the [Platform Support](https://forge.rust-lang.org/release/platform-support.html) page from the forge to the rustc book. There are several reasons for doing this:
* The forge is not really oriented towards end-users (it mostly contains infrastructure, governance and policy, internal team pages, etc.). This platform support page is useful to user to know which targets are supported.
* This page can now be updated in-sync with any PRs that add or remove a target, or change its status.
* This is now automatically checked on CI to verify the list does not get out of sync. Currently it only checks the presence/absence of an entry, but more sophisticated checks could be added in the future.
I'm not 100% certain this is the best location, but I think it fits. I'd like to see the rustc guide continue to grow, including things like linking information and more platform-specific details.
Update cargo
7 commits in 1653f354644834073d6d2541e27fae94588e685e..ab32ee88dade1b50c77347599e82ca2de3fb8a51
2020-08-04 23:14:37 +0000 to 2020-08-10 17:44:43 +0000
- Build manpage archive deterministically (rust-lang/cargo#8600)
- doc: Qualify GNU licenses in example license field (rust-lang/cargo#8604)
- Fix jobserver_exists test on single-cpu systems (rust-lang/cargo#8598)
- Fix small typo in reference/profiles.md (rust-lang/cargo#8605)
- Default cargo publish to the alt registry if it's the only allowed one (rust-lang/cargo#8571)
- cargo install with specific yanked version gives confusing "not found" error (rust-lang/cargo#8565)
- Fix typo (rust-lang/cargo#8589)
Add basic test
And also run fmt which is where the other changes are from
Fix mut issues
These only appear when running tests, so resolved by adding mut
Swap order of forget
Add pub and rm guard impl
Add explicit type to guard
Add safety note
Change guard type from T to S
It should never have been T, as it guards over [MaybeUninit<S>; N]
Also add feature to test
This creates the language item for arrays, and adds the map fn which is like map in options or
iterators. It currently allocates an extra array, unfortunately.
Added fixme for transmuting
Fix typo
Add drop guard
Fix suggestion to use lifetime in type and in assoc const
_Do not merge until #75363 has landed, as it has the test case for this._
* Account for associated types
* Associated `const`s can't have generics (fix#74264)
* Do not suggest duplicate lifetimes and suggest `for<'a>` more (fix#72404)
While debugging a codegen issue, I tried adding LLVM options with
the rustc -Cllvm-args option, and was confused by the error and usage
messaging.
The LLVM "program name" argument is set to "rustc", and command line
error messages make it look like invalid arguments are "rustc"
arguments, not LLVM.
I changed this argument so error messages and the "-help" usage feedback
is easier to understand and react to. (Clang does something similar.)
Miri: improve spans of required_const failures
In https://github.com/rust-lang/rust/pull/75339 I added a loop evaluating all consts required by a function body. Unfortunately, if one of their evaluations fails, then the span used for that was that of the first statement in the function body, which happened to work form some existing test but is not sensible in general.
This PR changes it to point to the whole function instead, which is at least not wrong.
r? @oli-obk
Handle projection predicates in the param env for auto-trait docs
Fixes#72213
Any predicates in the param env are guaranteed to hold, so we don't need
to do any additional processing of them if we come across them as
sub-obligations of a different predicate. This allows us to avoid adding
the same predicate to the computed ParamEnv multiple times (but with
different regions each time), which causes an ambiguity error during
fulfillment.
Rollup of 9 pull requests
Successful merges:
- #74521 (older toolchains not valid anymore)
- #74960 (Fix regionck failure when converting Index to IndexMut)
- #75234 (Update asm! documentation in unstable book)
- #75368 (Move to doc links inside the prelude)
- #75371 (Move to doc links inside std/time.rs)
- #75394 (Add a function to `TyCtxt` for computing an `Allocation` for a `static` item's initializer)
- #75395 (Switch to intra-doc links in library/std/src/os/*/fs.rs)
- #75422 (Accept more safety comments)
- #75424 (fix wrong word in documentation)
Failed merges:
r? @ghost
Accept more safety comments
This accepts more `// SAFETY:` comments from `tidy`.
This is done after the current behaviour of requiring text one the same line (because spaces are stripped so the last space never pass if there is no text on the same line) bit me once more in #75066
This could potentially accept empty `// SAFETY:` comments but `tidy` is an internal tool used only here so my reasoning is reviews will catch those.
Fix regionck failure when converting Index to IndexMut
Fixes#74933
Consider an overloaded index expression `base[index]`. Without knowing whether it will be mutated, this will initially be desugared into `<U as Index<T>>::index(&base, index)` for some `U` and `T`. Let `V` be the `expr_ty_adjusted` of `index`.
If this expression ends up being used in any mutable context (or used in a function call with `&mut self` receiver before #72280), we will need to fix it up. The current code will rewrite it to `<U as IndexMut<V>>::index_mut(&mut base, index)`. In most cases this is fine as `V` will be equal to `T`, however this is not always true when `V/T` are references, as they may have different region.
This issue is quite subtle before #72280 as this code path is only used to fixup function receivers, but after #72280 we've made this a common path.
The solution is basically just rewrite it to `<U as IndexMut<T>>::index_mut(&mut base, index)`. `T` can retrieved in the fixup path using `node_substs`.
A few updates:
- Some minor wording and formatting changes.
- Remove the `cargo` column.
- Explain the columns up-front.
- Add no-wrap on the target-triple, which looks better to me.
- Minor mention on how to install support for a built-in target via rustup.
Reland #74069
Investigation in #74716 has concluded that this PR is indeed not a regression (and in fact the rollup itself is not either).
This reverts the revert in #74611.
r? @nnethercote cc @eddyb
This reverts commit 25670749b4.
This commit does not actually fix the problem. It merely removes the name of
the argument from the LLVM output. Even without the name, Rust codegen still
spills the (nameless) variable onto the stack which is the root cause. The root
cause is solved in the next commit.
move Deaggregate pass to post_borrowck_cleanup
Reopen of #71946
Only the second commit is from this PR, the other commit is a bugfix that's in the process of getting merged. I'll rebase once that's done
In #70073 MIR pass handling got reorganized, but with the goal of not changing behavior (except for disabling some optimizations on opt-level = 0). But there we realized that the Deaggregator pass, while conceptually more of a "cleanup" pass (and one that should be run before optimizations), was run in the middle of the optimization chain. Likely this is an accident of history, so I suggest we try and clean that up by making it a proper cleanup pass.
This does change mir-opt output, because deaggregation now runs before const-prop instead of after.
r? @wesleywiser @rust-lang/wg-mir-opt
cc @RalfJung
Add sample fix for E0749
Even though the description is clear but the solution may not be as straightforward.
Adding a suggested fix from documentation side.
r? @GuillaumeGomez
However, this suggestion should be shown in rustc itself for easy fix, the documentation should also reflect on the changes in rustc. Currently,
```
error[E0749]: negative impls cannot have any items
--> test.rs:6:5
|
6 | type Foo = i32; // error!
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0749`.
```
rustc should tell the user to remove it.
Tweak conditions for E0026 and E0769
When we have a tuple struct used with struct we don't want to suggest using the (valid) struct syntax with numeric field names. Instead we want to suggest the expected syntax.
Given
```rust
fn main() {
match MyOption::MySome(42) {
MyOption::MySome { x: 42 } => (),
_ => (),
}
}
```
We now emit E0769 "tuple variant `MyOption::MySome` written as struct variant" instead of E0026 "variant `MyOption::MySome` does not have a field named `x`".
move stack size check to const_eval machine
This is consistent with how we enforce the step limit. In particular, we do not want this limit checked for Miri-the-tool.
polymorphize: constrain unevaluated const handling
This PR constrains the support added for handling unevaluated consts in polymorphization (introduced in #75260) by:
- Skipping associated constants as this causes cycle errors.
- Skipping promoted constants when they contain `Self` as this ensures `T` is used in constants of the form `<Self as Foo<T>>`.
Due to an oversight on my part, when landing #75260 and #75255, some tests started failing when polymorphization was enabled that I didn't notice until after landing - this PR fixes the regressions from #75260.
r? @lcnr
Miri: Renamed "undef" to "uninit"
Renamed remaining references to "undef" to "uninit" when referring to Miri.
Impacted directories are:
- `src/librustc_codegen_llvm/consts.rs`
- `src/librustc_middle/mir/interpret/`
- `src/librustc_middle/ty/print/pretty.rs`
- `src/librustc_mir/`
- `src/tools/clippy/clippy_lints/src/consts.rs`
Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project.
Related issue #71193
Use existing `infcx` when emitting trait impl diagnostic
Fixes#75361Fixes#74918
Previously, we were creating a new `InferCtxt`, which caused an ICE when
used with type variables from the existing `InferCtxt`
instance: only polymorphize upvar substs
This PR restricts the substitution polymorphization added in #75255 to only apply to the tupled upvar substitution, rather than all substitutions, fixing a bunch of regressions when polymorphization is
enabled.
Due to an oversight on my part, when landing #75260 and #75255, some tests started failing when polymorphization was enabled that I didn't notice until after landing - this PR fixes the regressions from #75255. #75336 has been filed to make sure that we don't forget to try make this change again in future, as it does enable some optimisations.
r? @lcnr
Don't try to use wasm intrinsics on vectors
This commit fixes an issue with #74695 where the fptosi and fptoui
specializations on wasm were accidentally used on vector types by the
`simd_cast` intrinsic. This issue showed up as broken CI for the stdsimd
crate. Here this commit simply skips the specialization on vector kinds
flowing into `fpto{s,u}i`.
Avoid deleting temporary files on error
Previously if the compiler error'd, fatally, then temporary directories which
should be preserved by -Csave-temps would be deleted due to fatal compiler
errors being implemented as panics.
cc @infinity0
(Hopefully) fixes#75275, but I haven't tested
Clean up errors in typeck and resolve
* Tweak ordering of suggestions
* Do not suggest similarly named enclosing item
* Point at item definition in foreign crates
* Add missing primary label
CC #34255.
Remove restriction on type parameters preceding consts w/ feature const-generics
Removed the restriction on type parameters preceding const parameters when the feature const-generics is enabled.
Builds on #74676, which deals with unsorted generic parameters. This just lifts the check in lowering the AST to HIR that permits consts and types to be reordered with respect to each other. Lifetimes still must precede both
This change is not intended for min-const-generics, and is gated behind the `#![feature(const_generics)]`.
One thing is that it also permits type parameters without a default to come after consts, which I expected to not work, and was hoping to get more guidance on whether that should be permitted or how to prevent it otherwise.
I did not go through the RFC process for this pull request because there was prior work to get this feature added. In the previous PR that was cited, work was done to enable this change.
r? @lcnr
This commit constrains the support added for handling unevaluated consts
in polymorphization (introduced in #75260) by:
- Skipping associated constants as this causes cycle errors.
- Skipping promoted constants when they contain `Self` as this ensures
`T` is used in constants of the form `<Self as Foo<T>>`.
Signed-off-by: David Wood <david@davidtw.co>
Upgrade the FreeBSD toolchain to version 11.4
FreeBSD 10 reached its end-of-life in October 2018, and that toolchain
caused issues in the LLVM 11 upgrade (#73526) that are resolved with the
toolchain from FreeBSD 11.
Closes#72390.
MinGW: disable self-contained mode when cross compiling
When cross compiling users have to provide own linker and libraries anyway.
Using rust provided MinGW crt objects is harmful here and has no benefits.
cc https://github.com/rust-lang/rust/issues/68887
When we have a tuple struct used with struct we don't want to suggest using
the (valid) struct syntax with numeric field names. Instead we want to
suggest the expected syntax.
Given
```rust
fn main() {
match MyOption::MySome(42) {
MyOption::MySome { x: 42 } => (),
_ => (),
}
}
```
We now emit E0769 "tuple variant `MyOption::MySome` written as struct variant"
instead of E0026 "variant `MyOption::MySome` does not have a field named `x`".
Rollup of 8 pull requests
Successful merges:
- #74200 (Std panicking unsafe block in unsafe fn)
- #75286 (Add additional case for Path starts with)
- #75318 (Resolve `char` as a primitive even if there is a module in scope)
- #75320 (Detect likely `for foo of bar` JS syntax)
- #75328 (Cleanup E0749)
- #75344 (Rename "Important traits" to "Notable traits")
- #75348 (Move to intra-doc links in library/core/src/time.rs)
- #75350 (Do not ICE when lowering invalid extern fn with bodies)
Failed merges:
r? @ghost
Remove normalization of `Span` debug output in proc-macro tests
Fixes#74800
The definition of `is_x86_feature_detected!` (and similar macros)
depends on the platform - it is produced by a `cfg_if!` invocation on
x86, and a plain `#[cfg]` on other platforms. Since it is part of the
prelude, we will end up importing different hygiene information
depending on the platform. This previously required us to avoid printing raw
`SyntaxContext` ids in any tests that uses the standard library, since
the captured output will be platform-dependent.
Previously, we replaced all `SyntaxContext` ids with "#CTXT", and the
raw `Span` lo/hi bytes with "LO..HI".
This commit adds `#![no_std]` and `extern crate std` to all proc-macro
tests that print spans. This suppresses the prelude import, while
still using lang items from `std` (which gives us a buildable binary).
With this apporach, we will only load hygiene information for things
which we explicitly import. This lets us re-add
`-Z unpretty=expanded,hygiene`, since its output can now be made stable
across all platforms.
Additionally, we use `-Z span-debug` in more places, which lets us avoid
the "LO..HI" normalization hack.
`CowBoxSymStr` is a type that either holds a `SymbolStr` (which is much
the same as a `Symbol`), or an owned string. When computing skeletons,
a `SymbolStr` is stored if the skeleton is the same as the original
string, otherwise an owned string is stored.
So, basically, `CowBoxSymStr` is a type for string interning. But we
already have one of those: `Symbol` itself. This PR removes
`CowBoxSymStr`, using `Symbol` instead. A good thing about this is that
it avoids storing `SymbolStr` values in `skeleton_map`, something that
is discouraged.
The PR also inlines and removes the `calc_skeleton()` function because
that simplifies the code.
Confusable idents detection uses a type `BTreeMap<Symbol, Span>`. This is
highly dubious given that `Symbol` doesn't guarantee a meaningful order. (In
practice, it currently gives an order that mostly matches source code order.)
As a result, changes in `Symbol` representation make the
`lint-confusable-idents.rs` test fail, because this error message:
> identifier pair considered confusable between `s` and `s`
is changed to this:
> identifier pair considered confusable between `s` and `s`
and the corresponding span pointers get swapped erroneously, leading to
an incorrect "previous identifier" label.
This commit sorts the relevant symbols by span before doing the checking,
which ensures that the ident that appears first in the code will be mentioned
first in the message. The commit also extends the test slightly to be more
thorough.
The old implementation only looks at numbers at the end, but not in
other places in a name: "u8" and "u16" got sorted properly, but "u8_bla"
and "u16_bla" did not.
Upgrade indexmap and use it more
First this upgrades `indexmap` to 1.5.1, which is now based on `hashbrown::raw::RawTable`. This means it shares a lot of the same performance characteristics for insert, lookup, etc., while keeping items in insertion order.
Then across various rustc crates, this replaces a lot of `Vec`+`HashMap` pairs with a single `IndexMap` or `IndexSet`.
Closes#60608.
r? @eddyb
Fixes#74800
The definition of `is_x86_feature_detected!` (and similar macros)
depends on the platform - it is produced by a `cfg_if!` invocation on
x86, and a plain `#[cfg]` on other platforms. Since it is part of the
prelude, we will end up importing different hygiene information
depending on the platform. This previously required us to avoid printing raw
`SyntaxContext` ids in any tests that uses the standard library, since
the captured output will be platform-dependent.
Previously, we replaced all `SyntaxContext` ids with "#CTXT", and the
raw `Span` lo/hi bytes with "LO..HI".
This commit adds `#![no_std]` and `extern crate std` to all proc-macro
tests that print spans. This suppresses the prelude import, while
still using lang items from `std` (which gives us a buildable binary).
With this apporach, we will only load hygiene information for things
which we explicitly import. This lets us re-add
`-Z unpretty=expanded,hygiene`, since its output can now be made stable
across all platforms.
Additionally, we use `-Z span-debug` in more places, which lets us avoid
the "LO..HI" normalization hack.
Don't serialize ExpnData for foreign crates
When we encode an ExpnId into the crate metadata, we write out the
CrateNum of the crate that 'owns' the corresponding `ExpnData`, which
is later used to decode the `ExpnData` from its owning crate.
However, we current serialize the `ExpnData` for all `ExpnIds` that we
serialize, even if the `ExpnData` was already serialized into a foreign
crate. This commit skips encoding this kind of `ExpnData`, which should
hopefully speed up metadata encoding and reduce the total metadata size.
FreeBSD 10 reached its end-of-life in October 2018, and that toolchain
caused issues in the LLVM 11 upgrade (#73526) that are resolved with the
toolchain from FreeBSD 11.
This commit restricts the substitution polymorphization added in #75255
to only apply to the tupled upvar substitution, rather than all
substitutions, fixing a bunch of regressions when polymorphization is
enabled.
Signed-off-by: David Wood <david@davidtw.co>
Previously if the compiler error'd, fatally, then temporary directories which
should be preserved by -Csave-temps would be deleted due to fatal compiler
errors being implemented as panics.
Updated tests and error msgs
Update stderr from test
Update w/ lcnr comments
Change some tests around, and also updated Ord implementation for ParamKindOrd
Update w/ nits from lcnr
Added this test to ensure that reordering the parameters only works with the feature const
generics enabled.
Fixed nits
Also added another test to verify that intermixed lifetimes are forbidden
This commit fixes an issue with #74695 where the fptosi and fptoui
specializations on wasm were accidentally used on vector types by the
`simd_cast` intrinsic. This issue showed up as broken CI for the stdsimd
crate. Here this commit simply skips the specialization on vector kinds
flowing into `fpto{s,u}i`.
polymorphize: unevaluated constants
This PR makes polymorphization visit the promoted MIR of unevaluated constants with available promoted MIR instead of visiting the substitutions of that constant - which will mark all of the generic parameters as used; in addition polymorphization will now visit non-promoted unevaluated constants rather than visit their substs.
r? @lcnr
Renamed remaining references to "undef" to "uninit" when referring to Miri.
Impacted directories are:
- src/librustc_codegen_llvm/consts.rs
- src/librustc_middle/mir/interpret/
- src/librustc_middle/ty/print/pretty.rs
- src/librustc_mir/
- src/tools/clippy/clippy_lints/src/consts.rs
Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project.
Related issue #71193
Emit == null instead of <= null for niche check
When the niche maximum is zero, emit a "== zero" check instead of a "<= zero" check. In particular, this avoids the awkward case of "<= null". While LLVM does canonicalize this to "== null", this apparently doesn't happen for constant expressions, leading to the issue in #74425. While that can be addressed on the LLVM side, it still seems prudent to emit sensible IR here, because this will allow null checks to be optimized earlier in the pipeline.
Fixes#74425.
When the niche maximum is zero, emit a "== zero" check instead of
a "<= zero" check. In particular, this avoid the awkward case of
"<= null". While LLVM does canonicalize this to "!= null", this
appently doesn't happen for constant expressions, leading to the
issue in #74425. While that can be addressed on the LLVM side, it
still seems prudent to emit sensible IR here, because this will
allow null checks to be optimized earlier in the pipeline.
Fixes#74425.
Display elided lifetime for non-reference type in doc
In edition 2018 we encourage writing `<'_>` explicitly, so rustdoc should display like such as well.
Fixes#75225
~~Somehow when I run the compiled rustdoc using `cargo +stage2 doc` on other crates, it correctly produces `<'_>`, but I couldn't get the std doc to do the same with `./x.py doc --stage 2`. Might this be related to the recent change to x.py about how the doc is built?~~
Don't call a function in function-arguments-naked.rs
Fixes#75096
It's U.B. to use anything other than inline assmebling in a naked
function. Fortunately, the `#break` directive works fine without
anything in the function body.
By moving `{known,used}_attrs` from `SessionGlobals` to `Session`. This
means they are accessed via the `Session`, rather than via TLS. A few
`Attr` methods and `librustc_ast` functions are now methods of
`Session`.
All of this required passing a `Session` to lots of functions that didn't
already have one. Some of these functions also had arguments removed, because
those arguments could be accessed directly via the `Session` argument.
`contains_feature_attr()` was dead, and is removed.
Some functions were moved from `librustc_ast` elsewhere because they now need
to access `Session`, which isn't available in that crate.
- `entry_point_type()` --> `librustc_builtin_macros`
- `global_allocator_spans()` --> `librustc_metadata`
- `is_proc_macro_attr()` --> `Session`
Implement the `min_const_generics` feature gate
Implements both https://github.com/rust-lang/lang-team/issues/37 and https://github.com/rust-lang/compiler-team/issues/332.
Adds the new feature gate `#![feature(min_const_generics)]`.
This feature gate adds the following limitations to using const generics:
- generic parameters must only be used in types if they are trivial. (either `N` or `{ N }`)
- generic parameters must be either integers, `bool` or `char`.
We do allow arbitrary expressions in associated consts though, meaning that the following is allowed,
even if `<[u8; 0] as Foo>::ASSOC` is not const evaluatable.
```rust
trait Foo {
const ASSOC: usize;
}
impl<const N: usize> Foo for [u8; N] {
const ASSOC: usize = 64 / N;
}
```
r? @varkor cc @eddyb @withoutboats
This runs _just_ enough of typeck that later queries don't panic.
Because this is in the same part of the compiler that errors on `impl
Trait`, this special-cases impl Trait for rustdoc and no one else.
Everything is fine.
Prevent `__rust_begin_short_backtrace` frames from being tail-call optimised away
I've stumbled across some situations where there (unexpectedly) was no `__rust_begin_short_backtrace` frame on the stack during unwinding.
On closer examination, it appeared that the calls to that function had been tail-call optimised away.
This PR follows [@bjorn3's suggestion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Disabling.20tail.20call.20optimisation.3F/near/205699133), by adding calls to `black_box` that hint to rustc not to perform TCO.
Fixes#47429