Commit Graph

223907 Commits

Author SHA1 Message Date
Chayim Refael Friedman
83930ecdea Give better error when collecting into &[T] 2023-05-15 21:16:35 +03:00
bors
4d941cd981 Auto merge of #111452 - matthiaskrgr:rollup-uic8dgy, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #108705 (Prevent ICE with broken borrow in closure)
 - #111292 (Fix mishandled `--check-cfg` arguments order)
 - #111382 (Isolate coverage FFI type layouts from their underlying LLVM C++ types)
 - #111385 (vec-shrink-panik: update expectations to work on LLVM 17)
 - #111389 (Add esp-idf platform-support page)
 - #111432 (Use visit_assign to detect SSA locals.)
 - #111448 (Use proper impl self type for alias impl in rustdoc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-11 05:06:09 +00:00
Matthias Krüger
07af55edd4
Rollup merge of #111448 - compiler-errors:rustdoc-alias-impl, r=notriddle
Use proper impl self type for alias impl in rustdoc

We don't want to use `type_of(type_alias)`, we want to use `type_of(impl)` -- this will give us the self type of the impl *properly substituted* in the case that it's an alias.

Fixes #111420
2023-05-11 07:05:29 +02:00
Matthias Krüger
968911dbc0
Rollup merge of #111432 - cjgillot:issue-111426, r=oli-obk
Use visit_assign to detect SSA locals.

I screwed up the logic in 3c43b61b87.

Fixes https://github.com/rust-lang/rust/issues/111426
2023-05-11 07:05:29 +02:00
Matthias Krüger
3b7c02b769
Rollup merge of #111389 - esp-rs:esp-idf-platform-support, r=jyn514
Add esp-idf platform-support page

As mentioned in https://github.com/rust-lang/rust/pull/111369#issuecomment-1539881848, the initial PR for esp-idf didn't include a platform support document which is required for the merge of  https://github.com/rust-lang/rust/pull/111369.
2023-05-11 07:05:28 +02:00
Matthias Krüger
acae72e493
Rollup merge of #111385 - durin42:vec-panik-17, r=Amanieu
vec-shrink-panik: update expectations to work on LLVM 17

For some reason, the called function is `cleanup` on LLVM 17 instead of `filter`.

r? `@Amanieu`
2023-05-11 07:05:28 +02:00
Matthias Krüger
39761b0cf9
Rollup merge of #111382 - Zalathar:ffi, r=cuviper
Isolate coverage FFI type layouts from their underlying LLVM C++ types

I noticed that several of the types used to send coverage information through FFI are not properly isolated from the layout of their corresponding C++ types in the LLVM API.

This PR adds more explicitly-defined FFI struct/enum types in `CoverageMappingWrapper.cpp`, so that Rust source files in `rustc_codegen_ssa` and `rustc_codegen_llvm` aren't directly exposed to LLVM C++ types.
2023-05-11 07:05:27 +02:00
Matthias Krüger
aa9adf457b
Rollup merge of #111292 - Urgau:check-cfg-issue-111291, r=petrochenkov
Fix mishandled `--check-cfg` arguments order

This PR fixes a bug in `--check-cfg` where the order of `--check-cfg=names(a)` and `--check-cfg=values(a,…)` would trip the compiler.

Fixes https://github.com/rust-lang/rust/issues/111291
cc `@taiki-e` `@petrochenkov`
2023-05-11 07:05:27 +02:00
Matthias Krüger
40d933a19a
Rollup merge of #108705 - clubby789:refutable-let-closure-borrow, r=cjgillot
Prevent ICE with broken borrow in closure

r? `@Nilstrieb`
Fixes #108683

This solution isn't ideal, I'm hoping to find a way to continue compilation without ICEing.
2023-05-11 07:05:26 +02:00
Michael Goulet
6509c42d16 Use proper impl self type for alias impl in rustdoc 2023-05-10 22:49:05 +00:00
bors
9a767b6b9e Auto merge of #110820 - cjgillot:faster-dcp, r=oli-obk
Optimize dataflow-const-prop place-tracking infra

Optimization opportunities found while investigating https://github.com/rust-lang/rust/pull/110719

Computing places breadth-first ensures that we create short projections before deep projections, since the former are more likely to be propagated.

The most relevant is the pre-computation of flooded places. Callgrind showed `flood_*` methods and especially `preorder_preinvoke` were especially hot. This PR attempts to pre-compute the set of `ValueIndex` that `preorder_invoke` would visit.

Using this information, we make some `PlaceIndex` inaccessible when they contain no `ValueIndex`, allowing to skip computations for those places.

cc `@jachris` as original author
2023-05-10 20:54:31 +00:00
Camille GILLOT
6ad0497cc0 Use visit_assign to detect SSA locals. 2023-05-10 15:26:51 +00:00
Augie Fackler
fbe479558c vec-shrink-panik: update expectations to work on LLVM 17
For some reason, the called function is `cleanup` on LLVM 17 instead of
`filter`.

r? @Amanieu
2023-05-10 09:31:33 -04:00
bors
cba14074bb Auto merge of #111401 - ChrisDenton:no-windows-allowed, r=workingjubilee
Don't force include Windows goop when documenting

Why do we need to include all the windows bits on non-windows platforms? Let's try not doing that.

Possible alternative to #111394, if it works.
2023-05-10 10:28:38 +00:00
bors
25444e5a2e Auto merge of #111414 - matthiaskrgr:rollup-q0qoc47, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #110673 (Make alias bounds sound in the new solver (take 2))
 - #110747 (Encode types in SMIR)
 - #111095 (Correctly handle associated items of a trait inside a `#[doc(hidden)]` item)
 - #111381 (Keep encoding attributes for closures)
 - #111408 (Fix incorrect implication of transmuting slices)
 - #111410 (Switch to `EarlyBinder` for `thir_abstract_const` query)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-10 06:53:47 +00:00
Matthias Krüger
70d5bf7fae
Rollup merge of #111410 - kylematsuda:earlybinder-abstract-const, r=BoxyUwU
Switch to `EarlyBinder` for `thir_abstract_const` query

Part of the work to finish https://github.com/rust-lang/rust/issues/105779.

This PR adds `EarlyBinder` to the return type of the `thir_abstract_const` query and removes `bound_abstract_const`.

r? `@compiler-errors`
2023-05-10 06:12:15 +02:00
Matthias Krüger
f60a174c2d
Rollup merge of #111408 - TomMD:patch-1, r=workingjubilee
Fix incorrect implication of transmuting slices

transmute<&[u8]> would be useful and as a beginner it is confusing to see documents casually confuse the types of &[u8] and [u8; SZ]
2023-05-10 06:12:15 +02:00
Matthias Krüger
3d4d6703a9
Rollup merge of #111381 - oli-obk:closure_attr, r=petrochenkov
Keep encoding attributes for closures

see https://github.com/model-checking/kani/pull/2406#issuecomment-1539630332 for some context.

We stopped encoding attributes for closures, but some tools need them
2023-05-10 06:12:14 +02:00
Matthias Krüger
d117b41409
Rollup merge of #111095 - GuillaumeGomez:fix-assoc-item-trait-inside-hidden, r=notriddle
Correctly handle associated items of a trait inside a `#[doc(hidden)]` item

Fixes https://github.com/rust-lang/rust/issues/111064.

cc `@compiler-errors`
r? `@notriddle`
2023-05-10 06:12:14 +02:00
Matthias Krüger
f1922275b7
Rollup merge of #110747 - oli-obk:smirty, r=spastorino
Encode types in SMIR

The first commit makes sure we can actually store a Ty<'tcx> (with the lifetime) in the thread local and get it back out. The second commit then introduces types.

r? `@spastorino`
2023-05-10 06:12:13 +02:00
Matthias Krüger
c14d912cd2
Rollup merge of #110673 - compiler-errors:alias-bounds-2, r=lcnr
Make alias bounds sound in the new solver (take 2)

Make alias bounds sound in the new solver (in a way that does not require coinduction) by only considering them for projection types whose corresponding trait refs come from a param-env candidate.

That is, given `<T as Trait>::Assoc: Bound`, we only *really* need to consider the alias bound if `T: Trait` is satisfied via a param-env candidate. If it's instead satisfied, e.g., via an user provided impl candidate or a , then that impl should have a concrete type to which we could otherwise normalize `<T as Trait>::Assoc`, and that concrete type is then responsible to prove the `Bound` on it.

Similar consideration is given to opaque types, since we only need to consider alias bounds if we're *not* in reveal-all mode, since similarly we'd be able to reveal the opaque types and prove any bounds that way.

This does not remove that hacky "eager projection replacement" logic from object bounds, which are somewhat like alias bounds. But removing this eager normalization behavior (added in #108333) would require full coinduction to be enabled. Compare to #110628, which does remove this object-bound custom logic but requires coinduction to be sound.

r? `@lcnr`
2023-05-10 06:12:13 +02:00
bors
63fc57b98e Auto merge of #106560 - bjorn3:support_staticlib_dylib_linking, r=pnkfelix
Support linking to rust dylib with --crate-type staticlib

This allows for example dynamically linking libstd, while statically linking the user crate into an executable or C dynamic library. For this two unstable flags (`-Z staticlib-allow-rdylib-deps` and `-Z staticlib-prefer-dynamic`) are introduced. Without the former you get an error. The latter is the equivalent to `-C prefer-dynamic` for the staticlib crate type to indicate that dynamically linking is preferred when both options are available, like for libstd. Care must be taken to ensure that no crate ends up being merged into two distinct staticlibs that are linked together. Doing so will cause a linker error at best and undefined behavior at worst. In addition two distinct staticlibs compiled by different rustc may not be combined under any circumstances due to some rustc private symbols not being mangled.

To successfully link a staticlib, `--print native-static-libs` can be used while compiling to ask rustc for the linker flags necessary when linking the staticlib. This is an existing flag which previously only listed native libraries. It has been extended to list rust dylibs too. Trying to locate libstd yourself to link against it is not supported and may break if for example the libstd of multiple rustc versions are put in the same directory.

For an example on how to use this see the `src/test/run-make-fulldeps/staticlib-dylib-linkage/` test.
2023-05-10 03:40:40 +00:00
bors
65dfca8488 Auto merge of #111409 - weihanglo:update-cargo, r=weihanglo
Update cargo

10 commits in 569b648b5831ae8a515e90c80843a5287c3304ef..26b73d15a68fb94579f6d3590585ec0e9d81d3d5
2023-05-05 15:49:44 +0000 to 2023-05-09 20:28:03 +0000
- Update the semver-check script to be able to run in any directory. (rust-lang/cargo#12117)
- Semver: Note that it is not a breaking change to make an unsafe function safe (rust-lang/cargo#12116)
- Add more documentation for artifact-dependencies. (rust-lang/cargo#12110)
- changelog: move registry query fixes to the right place (rust-lang/cargo#12086)
- Disallow RUSTUP_TOOLCHAIN in the [env] table. (rust-lang/cargo#12107)
- Disallow RUSTUP_HOME in the [env] table. (rust-lang/cargo#12101)
- Fix redacting tokens in http debug. (rust-lang/cargo#12095)
- Fix self_signed_should_fail for macOS. (rust-lang/cargo#12097)
- Update git2 (rust-lang/cargo#12096)
- do not try an exponential number of package names (rust-lang/cargo#12083)

r? `@ghost`
2023-05-10 00:41:09 +00:00
Kyle Matsuda
26dc139b37 add EarlyBinder to thir_abstract_const; remove tcx.bound_abstract_const 2023-05-09 16:22:50 -06:00
Weihang Lo
05ffb2f7ec
Update cargo 2023-05-09 23:04:06 +01:00
bors
50dff955a9 Auto merge of #106285 - cjgillot:refprop-ssa, r=JakobDegen
Implement SSA-based reference propagation

Rust has a tendency to create a lot of short-lived borrows, in particular for method calls. This PR aims to remove those short-lived borrows with a const-propagation dedicated to pointers to local places.

This pass aims to transform the following pattern:
```
  _1 = &raw? mut? PLACE;
  _3 = *_1;
  _4 = &raw? mut? *_1;
```

Into
```
  _1 = &raw? mut? PLACE;
  _3 = PLACE;
  _4 = &raw? mut? PLACE;
```

where `PLACE` is a direct or an indirect place expression.

By removing indirection, this pass should help both dest-prop and const-prop to handle more cases.
This optimization is distinct from const-prop and dataflow const-prop since the borrow-reborrow patterns needs to preserve borrowck invariants, especially the uniqueness property of mutable references.

The pointed-to places are computed using a SSA analysis. We suppose that removable borrows are typically temporaries from autoref, so they are by construction assigned only once, and a SSA analysis is enough to catch them. For each local, we store both where and how it is used, in order to efficiently compute the all-or-nothing property. Thanks to `Derefer`, we only have to track locals, not places in general.

---

There are 3 properties that need to be upheld for this transformation to be legal:
- place constness: `PLACE` must refer to the same memory wherever it appears;
- pointer liveness: we must not introduce dereferences of dangling pointers;
- `&mut` borrow uniqueness.

## Constness

If `PLACE` is an indirect projection, if its of the form `(*LOCAL).PROJECTIONS` where:
- `LOCAL` is SSA;
- all projections in `PROJECTIONS` are constant (no dereference and no indexing).

If `PLACE` is a direct projection of a local, we consider it as constant if:
- the local is always live, or it has a single `StorageLive` that dominates all uses;
- all projections are constant.

# Liveness

When performing a substitution, we must take care not to introduce uses of dangling locals.

Using a dangling borrow is UB. Therefore, we assume that for any use of `*x`, where `x` is a borrow, the pointed-to memory is live.

Limitations:
- occurrences of `*x` in an `&raw mut? *x` are accepted;
- raw pointers are allowed to be dangling.

In those 2 case, we do not substitute anything, to be on the safe side.

**Open question:** we do not differentiate borrows of ZST and non-ZST. The UB rules may be
different depending on the layout. Having a different treatment would effectively prevent this
pass from running on polymorphic MIR, which defeats the purpose of MIR opts.

## Uniqueness

For `&mut` borrows, we also need to preserve the uniqueness property:
we must avoid creating a state where we interleave uses of `*_1` and `_2`.
To do it, we only perform full substitution of mutable borrows:
we replace either all or none of the occurrences of `*_1`.

Some care has to be taken when `_1` is copied in other locals.
```
   _1 = &raw? mut? _2;
   _3 = *_1;
   _4 = _1
   _5 = *_4
```
In such cases, fully substituting `_1` means fully substituting all of the copies.

For immutable borrows, we do not need to preserve such uniqueness property,
so we perform all the possible substitutions without removing the `_1 = &_2` statement.
2023-05-09 21:54:34 +00:00
Thomas M. DuBuisson
55d86b9da8
Fix incorrect implication of transmuting slices
transmute<&[u8]> would be useful and as a beginner it is confusing to see documents casually confuse the types of &[u8] and [u8; SZ]
2023-05-09 14:08:13 -07:00
Michael Goulet
3a863e534b Consolidate the 'match assumption' type methods in GoalKind 2023-05-09 20:37:50 +00:00
Michael Goulet
0dbaae4165 Make alias bounds sound in the new solver 2023-05-09 20:37:50 +00:00
Camille GILLOT
bde213cfe5 Add needs-unwind. 2023-05-09 19:39:46 +00:00
bors
2f6bc5d259 Auto merge of #111402 - matthiaskrgr:rollup-28cqfz5, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #97320 (Stabilize const_ptr_read)
 - #110770 (Limit lifetime of format_args!() with inlined args.)
 - #111021 (Move some tests)
 - #111215 (Various changes to name resolution of anon consts)
 - #111242 (support set `rpath` option  for each target independently)
 - #111282 (Remove some `assume`s from slice iterators that don't do anything)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-09 19:10:05 +00:00
Matthias Krüger
273fbf47ab
Rollup merge of #111282 - scottmcm:remove-unneeded-assumes, r=workingjubilee
Remove some `assume`s from slice iterators that don't do anything

Because the start pointer is iterators is already a `NonNull`, we emit the appropriate `!nonnull` metadata when loading the pointer to tell LLVM that it's non-null.

Probably the best way to see that it's the metadata that's important (and not the `assume`) is to observe that LLVM actually *removes* the `assume` from the optimized IR: <https://rust.godbolt.org/z/KhE6G963n>.

(I also checked that, yes, the if-not-ZST `assume` on `end` is still doing something: it's how there's a `!nonnull` metadata on its load, even though it's an ordinary raw pointer.  The codegen test added in this PR fails if the other `assume` is  removed.)
2023-05-09 20:49:33 +02:00
Matthias Krüger
efe697e133
Rollup merge of #111242 - wangkirin:support_rpath_independent_config, r=albertlarsan68
support set `rpath` option  for each target independently

Currently  the `rpath` option is a global config and it's effect on all targets.
But sometimes when developers edit the rustc code and try to release rust toolchains themselves, they may not want to add `rpath` in all targets  to avoid dynamically linked shared object library privilege escalation attack.
This PR supports set `rpath` option  for each target independently .
Common developers are not aware of the existence of this configuration  option and do not affect the existing development process. This configuration option takes effect only after developers explicitly sets .

r? ``@albertlarsan68``
2023-05-09 20:49:32 +02:00
Matthias Krüger
363d158cd8
Rollup merge of #111215 - BoxyUwU:resolve_anon_consts_differently, r=cjgillot
Various changes to name resolution of anon consts

Sorry this PR is kind of all over the place ^^'

Fixes #111012

- Rewrites anon const nameres to all go through `fn resolve_anon_const` explicitly instead of `visit_anon_const` to ensure that we do not accidentally resolve anon consts as if they are allowed to use generics when they aren't. Also means that we dont have bits of code for resolving anon consts that will get out of sync (i.e. legacy const generics and resolving path consts that were parsed as type arguments)
- Renames two of the `LifetimeRibKind`, `AnonConst -> ConcreteAnonConst` and `ConstGeneric -> ConstParamTy`
- Noticed while doing this that under `generic_const_exprs` all lifetimes currently get resolved to errors without any error being emitted which was causing a bunch of tests to pass without their bugs having been fixed, incidentally fixed that in this PR and marked those tests as `// known-bug:`. I'm fine to break those since `generic_const_exprs` is a very unstable incomplete feature and this PR _does_ make generic_const_exprs "less broken" as a whole, also I can't be assed to figure out what the underlying causes of all of them are. This PR reopens #77357 #83993
- Changed `generics_of` to stop providing generics and predicates to enum variant discriminant anon consts since those are not allowed to use generic parameters
- Updated the error for non 'static lifetime in const arguments and the error for non 'static lifetime in const param tys to use `derive(Diagnostic)`

I have a vague idea why const-arg-in-const-arg.rs, in-closure.rs and simple.rs have started failing which is unfortunate since these were deliberately made to work, I think lifetime resolution being broken just means this regressed at some point and nobody noticed because the tests were not testing anything :( I'm fine breaking these too for the same reason as the tests for #77357 #83993. I couldn't get `// known-bug` to work for these ICEs and just kept getting different stderr between CI and local `--bless` so I just removed them and will create an issue to track re-adding (and fixing) the bugs if this PR lands.

r? `@cjgillot` cc `@compiler-errors`
2023-05-09 20:49:32 +02:00
Matthias Krüger
985ea22489
Rollup merge of #111021 - c410-f3r:dqewdas, r=petrochenkov
Move some tests

r? ``@petrochenkov``
2023-05-09 20:49:31 +02:00
Matthias Krüger
e4c82501c2
Rollup merge of #110770 - m-ou-se:fmt-temp-lifetime, r=oli-obk
Limit lifetime of format_args!() with inlined args.

Fixes #110769
2023-05-09 20:49:31 +02:00
Matthias Krüger
88fbfafe9e
Rollup merge of #97320 - usbalbin:stabilize_const_ptr_read, r=m-ou-se
Stabilize const_ptr_read

Stabilizes const_ptr_read, with tracking issue #80377
2023-05-09 20:49:30 +02:00
Chris Denton
d076607983
Don't force include Windows goop when documenting 2023-05-09 19:34:01 +01:00
Camille GILLOT
8e5910fdf2 Separate test cases into bbs. 2023-05-09 17:59:35 +00:00
Camille GILLOT
c17e878fb8 Correct StorageLive comment. 2023-05-09 17:59:35 +00:00
Camille GILLOT
a67bf08ed7 Only check storage liveness for direct projections. 2023-05-09 17:59:35 +00:00
Camille GILLOT
3b4e1fe104 Do not check StorageLive dominates address-taking. 2023-05-09 17:59:35 +00:00
Camille GILLOT
3268f2e61d Only check that StorageLive dominates address-taking. 2023-05-09 17:59:35 +00:00
Camille GILLOT
0bd9bd6b8a Explicit performance concern. 2023-05-09 17:59:35 +00:00
Camille GILLOT
38612f5ec7 Explicitly skip arguments. 2023-05-09 17:59:35 +00:00
Camille GILLOT
3c43b61b87 Do not consider borrowed Freeze locals as SSA. 2023-05-09 17:59:35 +00:00
Camille GILLOT
3490375570 Implement SSA-based reference propagation. 2023-05-09 17:59:34 +00:00
Camille GILLOT
ccc1da247b Prevent stack overflow. 2023-05-09 17:27:58 +00:00
Camille GILLOT
2aa1c23fed Add a few comments. 2023-05-09 17:27:58 +00:00
Camille GILLOT
79c073746b Do not flood on copy_nonoverlapping. 2023-05-09 17:27:58 +00:00