Commit Graph

95616 Commits

Author SHA1 Message Date
bors
8301de16da Auto merge of #61775 - nikomatsakis:issue-56238-multiple-lifetimes-async-fn-region-solver, r=MatthewJasper
generalize impl trait to permit multiple lifetime bounds

Generalizes the region solver to support "pick constraints". These have the form:

```
pick R0 from [R1..Rn]
```

where `R1..Rn` are called the "option regions". The idea is that `R0` must be equal to *some* region in the set `R1..Rn`. These constraints are then used to handle cases like this:

```rust
fn foo<'a, 'b>(...) -> impl Trait<'a, 'b> { .. }
```

The problem here is that every region R in the hidden type must be equal to *either* `'a` *or* `'b` (or `'static`) -- in the past, the only kinds of constraints we had were outlives constraints, and since `'a` and `'b` are unrelated, there was no outlives constraint we could issue that would enforce that (`R: 'a` and `R: 'b` are both too strict, for example). But now we can issue a pick constraint: `pick R from ['a, 'b]`.

In general, solving pick constraints is tricky. We integrate them into the solver as follows. In general, during the propagation phase, we are monotonically growing a set of inference regions. To handle a case like `pick R from [O...]`, where `O...` represents the option regions, we do the following:

- Look for all the *lower bounds* of the region R -- that is, every region LB such that `R: LB` must hold.
- Look for all the *upper bounds* of the region R -- that is, every region UB such that `UB: R` must hold.
- Let the *viable options* be each option region O such that `UB: O` and `O: LB` for each UB, LB bound.
- Find the *minimal viable option* M, where `O: M` holds for every option region O.

If there is such a *minimal viable option*, then we make `R: M`. (This may in turn influence other bits of inference.) If there is no minimal viable option, either because all options were eliminated or because none of the remaining options are minimal, we do nothing. Ultimately, if the pick constraint is not satisfied, an error is reported.

For this logic, we currently require that the option regions O are always lifetime parameters. To determine the bounds, we walk the various outlives edges that were otherwise introduced.

r? @matthewjasper
cc @cramertj

Fixes #56238

TODO:

- [ ] Error messages include region variable info sometimes, how to fix?
- [ ] Tests for bare `existential type`  and other impl Trait usage
2019-07-03 03:47:47 +00:00
Petr Hosek
8d2f80bab3 Use link attributes on extern "C" blocks with llvm-libuwind
When llvm-libunwind feature is enabled, we need to use link attribute on
extern "C" blocks to make sure that symbols provided by LLVM's libunwind
that's built as part of Rust's libunwind crate are re-exported.

This addresses issue #62088.
2019-07-02 16:18:06 -07:00
Julien Cretin
dd702cc653 Fix mismatching Kleene operators 2019-07-03 00:37:25 +02:00
Yuki Okushi
c004451a20 Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
Kyle Huey
db16e17212 When possible without changing semantics, implement Iterator::last in terms of DoubleEndedIterator::next_back for types in liballoc and libcore.
Provided that the iterator has finite length and does not trigger user-provided code, this is safe.

What follows is a full list of the DoubleEndedIterators in liballoc/libcore and whether this optimization is safe, and if not, why not.

src/liballoc/boxed.rs
Box: Pass through to avoid defeating optimization of the underlying DoubleIterator implementation. This has no correctness impact.

src/liballoc/collections/binary_heap.rs
Iter: Pass through to avoid defeating optimizations on slice::Iter
IntoIter: Not safe, changes Drop order
Drain: Not safe, changes Drop order

src/liballoc/collections/btree/map.rs
Iter: Safe to call next_back, invokes no user defined code.
IterMut: ditto
IntoIter: Not safe, changes Drop order
Keys: Safe to call next_back, invokes no user defined code.
Values: ditto
ValuesMut: ditto
Range: ditto
RangeMut: ditto

src/liballoc/collections/btree/set.rs
Iter: Safe to call next_back, invokes no user defined code.
IntoIter: Not safe, changes Drop order
Range: Safe to call next_back, invokes no user defined code.

src/liballoc/collections/linked_list.rs
Iter: Safe to call next_back, invokes no user defined code.
IterMut: ditto
IntoIter: Not safe, changes Drop order

src/liballoc/collections/vec_deque.rs
Iter: Safe to call next_back, invokes no user defined code.
IterMut: ditto
IntoIter: Not safe, changes Drop order
Drain: ditto

src/liballoc/string.rs
Drain: Safe because return type is a primitive (char)

src/liballoc/vec.rs
IntoIter: Not safe, changes Drop order
Drain: ditto
Splice: ditto

src/libcore/ascii.rs
EscapeDefault: Safe because return type is a primitive (u8)

src/libcore/iter/adapters/chain.rs
Chain: Not safe, invokes user defined code (Iterator impl)

src/libcore/iter/adapters/flatten.rs
FlatMap: Not safe, invokes user defined code (Iterator impl)
Flatten: ditto
FlattenCompat: ditto

src/libcore/iter/adapters/mod.rs
Rev: Not safe, invokes user defined code (Iterator impl)
Copied: ditto
Cloned: Not safe, invokes user defined code (Iterator impl and T::clone)
Map: Not safe, invokes user defined code (Iterator impl + closure)
Filter: ditto
FilterMap: ditto
Enumerate: Not safe, invokes user defined code (Iterator impl)
Skip: ditto
Fuse: ditto
Inspect: ditto

src/libcore/iter/adapters/zip.rs
Zip: Not safe, invokes user defined code (Iterator impl)

src/libcore/iter/range.rs
ops::Range: Not safe, changes Drop order, but ALREADY HAS SPECIALIZATION
ops::RangeInclusive: ditto

src/libcore/iter/sources.rs
Repeat: Not safe, calling last should iloop.
Empty: No point, iterator is at most one item long.
Once: ditto
OnceWith: ditto

src/libcore/option.rs
Item: No point, iterator is at most one item long.
Iter: ditto
IterMut: ditto
IntoIter: ditto

src/libcore/result.rs
Iter: No point, iterator is at most one item long
IterMut: ditto
IntoIter: ditto

src/libcore/slice/mod.rs
Split: Not safe, invokes user defined closure
SplitMut: ditto
RSplit: ditto
RSplitMut: ditto
Windows: Safe, already has specialization
Chunks: ditto
ChunksMut: ditto
ChunksExact: ditto
ChunksExactMut: ditto
RChunks: ditto
RChunksMut: ditto
RChunksExact: ditto
RChunksExactMut: ditto

src/libcore/str/mod.rs
Chars: Safe, already has specialization
CharIndices: ditto
Bytes: ditto
Lines: Safe to call next_back, invokes no user defined code.
LinesAny: Deprecated
Everything that is generic over P: Pattern: Not safe because Pattern invokes user defined code.
SplitWhitespace: Safe to call next_back, invokes no user defined code.
SplitAsciiWhitespace: ditto
2019-07-02 13:45:29 -07:00
bors
0beb2ba16a Auto merge of #61268 - michaelwoerister:stabilize-pgo, r=alexcrichton
Stabilize support for Profile-guided Optimization

This PR makes profile-guided optimization available via the `-C profile-generate` / `-C profile-use` pair of commandline flags and adds end-user documentation for the feature to the [rustc book](https://doc.rust-lang.org/rustc/). The PR thus ticks the last two remaining checkboxes of the [stabilization tracking issue](https://github.com/rust-lang/rust/issues/59913).

From the tracking issue:
> Profile-guided optimization (PGO) is a common optimization technique for ahead-of-time compilers. It works by collecting data about a program's typical execution (e.g. probability of branches taken, typical runtime values of variables, etc) and then uses this information during program optimization for things like inlining decisions, machine code layout, or indirect call promotion.

If you are curious about how this can be used, there is a rendered version of the documentation this PR adds available [here](
https://github.com/michaelwoerister/rust/blob/stabilize-pgo/src/doc/rustc/src/profile-guided-optimization.md).

r? @alexcrichton
cc @rust-lang/compiler
2019-07-02 20:00:29 +00:00
Niko Matsakis
f7e00a55bb fix ICE with delay-span-bug 2019-07-02 14:23:38 -04:00
Niko Matsakis
0c2c2416bf address nits 2019-07-02 12:25:23 -04:00
Niko Matsakis
7f319a7a41 Update src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-no-fg.rs
Co-Authored-By: matthewjasper <mjjasper1@gmail.com>
2019-07-02 12:25:23 -04:00
Niko Matsakis
f130e9a64d Update src/test/ui/async-await/multiple-lifetimes/elided.rs
Co-Authored-By: matthewjasper <mjjasper1@gmail.com>
2019-07-02 12:25:23 -04:00
Niko Matsakis
1d93e3cef9 Update src/test/ui/async-await/multiple-lifetimes/fn-ptr.rs
Co-Authored-By: matthewjasper <mjjasper1@gmail.com>
2019-07-02 12:25:23 -04:00
Niko Matsakis
8f9a3aff8b Update src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs
Co-Authored-By: matthewjasper <mjjasper1@gmail.com>
2019-07-02 12:25:23 -04:00
Niko Matsakis
5bd423a7ca introduce more tests covering async fn surface 2019-07-02 12:25:23 -04:00
Niko Matsakis
076b0d0f5c more nits + typos 2019-07-02 12:25:23 -04:00
Niko Matsakis
9217909518 pass a parameter to enable impl Trait instead of a vec 2019-07-02 12:25:23 -04:00
Niko Matsakis
0dd074e854 more centril nits 2019-07-02 12:25:23 -04:00
Niko Matsakis
d9f4d2ad1a region_constraints: nits 2019-07-02 12:25:23 -04:00
Niko Matsakis
3ba1e19a87 opaque_types: more nits 2019-07-02 12:25:23 -04:00
Niko Matsakis
0c8ebea227 s/abstract_type_generics/opaque_type_generics/ 2019-07-02 12:25:22 -04:00
Niko Matsakis
6234aed6c7 opaque_types: various nits 2019-07-02 12:25:22 -04:00
Niko Matsakis
6cab003fd1 cleanup formatting of comment and add attribution 2019-07-02 12:25:22 -04:00
Niko Matsakis
9588f7fe74 rewrite dup_vec to use IndexVec instead of u32 2019-07-02 12:25:22 -04:00
Niko Matsakis
b4a3753cfb various centril nits 2019-07-02 12:25:22 -04:00
Niko Matsakis
d2772e8989 explain why the code is the way it is 2019-07-02 12:25:22 -04:00
Niko Matsakis
56ae0bfc79 Update src/librustc/infer/lexical_region_resolve/mod.rs
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-02 12:25:22 -04:00
Niko Matsakis
cf721c5c73 Update src/doc/unstable-book/src/language-features/member-constraints.md
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-02 12:25:22 -04:00
Niko Matsakis
74a6efbf00 feature-gate member constraints outside of async-await
Minimizes risk.
2019-07-02 12:25:22 -04:00
Niko Matsakis
cbc75c699c implement TypeFoldable for Arc 2019-07-02 12:25:22 -04:00
Niko Matsakis
134fc4a929 rename pick_constraints.rs to member_constraints.rs 2019-07-02 12:25:22 -04:00
Niko Matsakis
eca55b58d6 rename to "member constraints" 2019-07-02 12:25:22 -04:00
Niko Matsakis
e39f66a859 implement Lift for Arc 2019-07-02 12:25:22 -04:00
Niko Matsakis
e6b6873525 switch to Lrc 2019-07-02 12:25:22 -04:00
Niko Matsakis
fb2c997d4e fix silly bugs in binary_search_util test 2019-07-02 12:25:22 -04:00
Niko Matsakis
5d44bebb32 bless test output 2019-07-02 12:25:21 -04:00
Niko Matsakis
adba6a8f90 address nits by mattewjasper 2019-07-02 12:25:21 -04:00
Niko Matsakis
0b15a66a80 account for the pick-constraint edges when reporting errors
Also, thread through better span info to improve the error message to
something tolerable.
2019-07-02 12:25:21 -04:00
Niko Matsakis
3e01c7416a just create a binary search slice helper fn 2019-07-02 12:25:16 -04:00
Niko Matsakis
89a205bf44 add a VecMap data structure 2019-07-02 12:15:21 -04:00
Niko Matsakis
e9de08a5ea test with explicit existential type 2019-07-02 12:15:21 -04:00
Niko Matsakis
b170c0f1c4 add a preliminary existential test; not really enough 2019-07-02 12:15:21 -04:00
Niko Matsakis
a18c779fa2 pacify the mercilous tidy
long lines, trailing newlines
2019-07-02 12:15:21 -04:00
Niko Matsakis
4831146afa remove outdated TODO markers
These were left behind to remind me to cleanup the code -- but the
relevant cleanups were already done.
2019-07-02 12:15:21 -04:00
Niko Matsakis
2ea6094938 explain why pick-constraints can be an empty vector 2019-07-02 12:15:21 -04:00
Niko Matsakis
4de99600b0 add a FIXME related to the non-free-region case
I don't think it would actually be harmful to just ignore such cases
but I'm inclined not to take chances.
2019-07-02 12:15:21 -04:00
Niko Matsakis
2057136326 update the async-fn-multiple-lifetimes test 2019-07-02 12:15:20 -04:00
Niko Matsakis
b5fb906766 fix tests and remove outdated stderr files 2019-07-02 12:15:20 -04:00
Niko Matsakis
8d39bdd5f9 integrate reverse graph and upper-bound computation 2019-07-02 12:15:20 -04:00
Niko Matsakis
7fd0db7dd3 add a depth_first_search helper function 2019-07-02 12:15:20 -04:00
Niko Matsakis
4c91bb9571 introduce a VecGraph abstraction that cheaply stores graphs
This is perhaps better than the linked list approach I was using
before. Lower memory overhead, Theta(N+E) storage. Does require a
sort. =)
2019-07-02 12:15:20 -04:00
Niko Matsakis
4e85665e08 implement the graph traits for SCC 2019-07-02 12:15:20 -04:00