Commit graph

377 commits

Author SHA1 Message Date
Oliver Scherer
b2532a8730 Implement destructuring for all aggregates and for references 2020-09-20 13:28:18 +02: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
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
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
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
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
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
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
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
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
bors
9f8ac718f4 Auto merge of #76575 - lcnr:abstract-const, r=oli-obk
compare generic constants using `AbstractConst`s

This is a MVP of rust-lang/compiler-team#340. The changes in this PR should only be relevant if `feature(const_evaluatable_checked)` is enabled.

~~currently based on top of #76559, so blocked on that.~~

r? `@oli-obk` cc `@varkor` `@eddyb`
2020-09-18 16:59:50 +00:00
Aaron Hill
6a96aea36a
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-18 12:24:42 -04:00
Bastian Kauschke
b7641209d7 add const-evaluatable_checked check back in 2020-09-18 17:36:11 +02:00
Bastian Kauschke
09e6254496 review, small cleanup 2020-09-18 17:11:34 +02:00
Bastian Kauschke
1b275d08ad document const_evaluatable 2020-09-18 17:11:34 +02:00
Bastian Kauschke
7fff155d2a remove allow(warnings) 2020-09-18 17:11:34 +02:00
Bastian Kauschke
30ff1ef3d0 support const_evaluatable_checked across crate boundaries 2020-09-18 17:11:34 +02:00
Bastian Kauschke
82ebbd7d6b add test for let-bindings 2020-09-18 17:11:34 +02:00
Bastian Kauschke
c7d16df1d8 add function calls 2020-09-18 17:11:34 +02:00
Bastian Kauschke
d1294e0ce2 allow unary operations and ignore StorageLive/Dead stmts 2020-09-18 17:11:34 +02:00
Bastian Kauschke
5a277822a5 use newtype_index for abstract_const::NodeId 2020-09-18 17:11:34 +02:00
Bastian Kauschke
f24d532749 refactor AbstractConstBuilder 2020-09-18 17:11:34 +02:00
Bastian Kauschke
c3a772f55f use abstract consts when unifying ConstKind::Unevaluated 2020-09-18 17:11:34 +02:00
Bastian Kauschke
d327fa112b initial working state 2020-09-18 16:25:25 +02:00
bors
fdc3405c20 Auto merge of #72412 - VFLashM:issue-72408-nested-closures-exponential, r=tmandry
Issue 72408 nested closures exponential

This fixes #72408.

Nested closures were resulting in exponential compilation time.

This PR is enhancing asymptotic complexity, but also increasing the constant, so I would love to see perf run results.
2020-09-18 14:08:39 +00:00