Commit graph

152 commits

Author SHA1 Message Date
Tomasz Miąsko
fd47d247d8 miri: lift restriction on extern types being the only field in a struct 2021-12-15 23:44:51 +01:00
bors
195e931b02 Auto merge of #91945 - matthiaskrgr:rollup-jszf9zp, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #90939 (Tweak errors coming from `for`-loop, `?` and `.await` desugaring)
 - #91859 (Iterator::cycle() — document empty iterator special case)
 - #91868 (Use `OutputFilenames` to generate output file for `-Zllvm-time-trace`)
 - #91870 (Revert setting a default for the MACOSX_DEPLOYMENT_TARGET env var for linking)
 - #91881 (Stabilize `iter::zip`)
 - #91882 (Remove `in_band_lifetimes` from `rustc_typeck`)
 - #91940 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-15 03:28:55 +00:00
PFPoitras
304ede6bcc Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
Matthias Krüger
bae9270989
Rollup merge of #91856 - ouz-a:master, r=oli-obk
Looser check for overflowing_binary_op

Fix for issue #91636 tight check resulted in ICE, this makes the check a little looser. It seems `eq` allows comparing of `supertype` and `subtype` if `lhs = supertype` and `rhs = subtype` but not vice versa, is this intended behavior ?
2021-12-14 20:47:31 +01:00
ouz-a
a5054e3858 comment update 2021-12-14 19:29:29 +03:00
LegionMammal978
a19eaf3542 Remove in_band_lifetimes from rustc_const_eval
See #91867 for more information.
2021-12-13 22:39:00 -05:00
ouz-a
b6c80985bd Add regression test and comment 2021-12-14 00:15:50 +03:00
ouz-a
a01b13dede formatting 2021-12-13 12:59:31 +03:00
ouz-a
01948e2f45 Looser check for binary_op_overflow 2021-12-13 12:35:55 +03:00
bors
22f8bde876 Auto merge of #91549 - fee1-dead:const_env, r=spastorino
Eliminate ConstnessAnd again

Closes #91489.
Closes #89432.

Reverts #91491.
Reverts #89450.

r? `@spastorino`
2021-12-12 22:15:32 +00:00
Matthias Krüger
6d9d8de029
Rollup merge of #91815 - RalfJung:span, r=oli-obk
better span for unexpected normalization failure in CTFE engine

No reason to use `DUMMY_SP` here.
2021-12-12 07:45:31 +01:00
Matthias Krüger
955e552d31
Rollup merge of #91814 - japm48:spelling-fix, r=RalfJung
doc: fix typo in comments

`dereferencable -> dereferenceable`

Fixes #91802.
2021-12-12 07:45:30 +01:00
Deadbeef
84b1d859c8
Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"
This reverts commit ff2439b7b9, reversing
changes made to 2a9e0831d6.
2021-12-12 12:34:46 +08:00
Ralf Jung
3de60264ca better span for unexpected normalization failure in CTFE engine 2021-12-11 18:55:58 -05:00
japm48
0d7b830139 doc: fix typo in comments
dereferencable -> dereferenceable
2021-12-12 00:27:27 +01:00
Matthias Krüger
9383a49cd4
Rollup merge of #90081 - woppopo:const_write_bytes, r=oli-obk
Make `intrinsics::write_bytes` const

This is required to constify `MaybeUninit::zeroed` and `(*mut T)::write_bytes`.

Tracking issue: #86302
2021-12-11 23:31:48 +01:00
est31
15de4cbc4b Remove redundant [..]s 2021-12-09 00:01:29 +01:00
Matthias Krüger
317f750ff7
Rollup merge of #91551 - b-naber:const-eval-normalization-ice, r=oli-obk
Allow for failure of subst_normalize_erasing_regions in const_eval

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

Using associated types that cannot be normalized previously resulted in an ICE. We now allow for normalization failure and return a "TooGeneric" error in that case.

r? ```@RalfJung``` maybe?
2021-12-08 16:08:07 +01:00
Matthias Krüger
871cf2bc9e
Rollup merge of #91272 - FabianWolff:issue-90870-const-fn-eq, r=wesleywiser
Print a suggestion when comparing references to primitive types in `const fn`

Fixes #90870.
2021-12-08 11:08:57 +01:00
b-naber
61cab770bd allow for failure of subst_normalize_erasing_regions in const_eval 2021-12-05 12:43:39 +01:00
bors
bdaa901049 Auto merge of #91475 - ecstatic-morse:mir-pass-manager3, r=oli-obk
Add a MIR pass manager (Taylor's Version)

The final draft of #91386 and #77665.

While the compile-time constraints in #91386 are cool, I decided on a more minimal approach for now. I want to explore phase constraints and maybe relative-ordering constraints in the future, though. This should preserve existing behavior **exactly** (please let me know if it doesn't) while making the following changes to the way we organize things today:

- Each `MirPhase` now corresponds to a single MIR pass. `run_passes` is not responsible for listing the correct MIR phase.
- `run_passes` no longer silently skips passes if the declared MIR phase is greater than or equal to the body's. This has bitten me multiple times. If you want this behavior, you can always branch on `body.phase` yourself.
- If your pass is solely to emit errors, you can use the `MirLint` interface instead, which gets a shared reference to `Body` instead of a mutable one. By differentiating the two, I hope to make it clearer in the short term where lints belong in the pipeline. In the long term perhaps we could enforce this at compile-time?
- MIR is no longer dumped for passes that aren't enabled, or for lints.

I tried to check that `-Zvalidate` still works correctly, since the MIR phase is now updated as soon as the associated pass is done, instead of at the end of all the passes in `run_passes`. However, it looks like `-Zvalidate` is broken with current nightlies anyways 😢 (it spits out a bunch of errors).

cc `@oli-obk` `@wesleywiser`

r? rust-lang/wg-mir-opt
2021-12-05 03:41:18 +00:00
Amanieu d'Antras
940b2eabad Add initial AST and MIR support for unwinding from inline assembly 2021-12-03 23:51:46 +01:00
Santiago Pastorino
85b723c4e6
Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"
This reverts commit 18bb8c61a9, reversing
changes made to d9baa36190.
2021-12-03 10:11:21 -03:00
Dylan MacKenzie
fd18b45e11 Update passes with new interface 2021-12-02 17:31:38 -08:00
bors
ff23ad3179 Auto merge of #91469 - matthiaskrgr:rollup-xom3j55, r=matthiaskrgr
Rollup of 12 pull requests

Successful merges:

 - #89954 (Fix legacy_const_generic doc arguments display)
 - #91321 (Handle placeholder regions in NLL type outlive constraints)
 - #91329 (Fix incorrect usage of `EvaluatedToOk` when evaluating `TypeOutlives`)
 - #91364 (Improve error message for incorrect field accesses through raw pointers)
 - #91387 (Clarify and tidy up explanation of E0038)
 - #91410 (Move `#![feature(const_precise_live_drops)]` checks earlier in the pipeline)
 - #91435 (Improve diagnostic for missing half of binary operator in `if` condition)
 - #91444 (disable tests in Miri that take too long)
 - #91457 (Add additional test from rust issue number 91068)
 - #91460 (Document how `last_os_error` should be used)
 - #91464 (Document file path case sensitivity)
 - #91466 (Improve the comments in `Symbol::interner`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-02 21:58:48 +00:00
Matthias Krüger
39641319ad
Rollup merge of #91410 - ecstatic-morse:const-precise-live-drops-take-2, r=oli-obk
Move `#![feature(const_precise_live_drops)]` checks earlier in the pipeline

Should mitigate the issues found during MCP on #73255.

Once this is done, we should clean up the queries a bit, since I think `mir_drops_elaborated_and_const_checked` can be merged back into `mir_promoted`.

Fixes #90770.

cc ``@rust-lang/wg-const-eval``
r? ``@nikomatsakis`` (since they reviewed #71824)
2021-12-02 22:16:13 +01:00
Alan Egerton
bfc434b6d0
Reduce boilerplate around infallible folders 2021-12-02 16:14:16 +00:00
bors
18bb8c61a9 Auto merge of #91354 - fee1-dead:const_env, r=spastorino
Cleanup: Eliminate ConstnessAnd

This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature.

We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`.

This is a continuation of https://github.com/rust-lang/rust/pull/90274.

r? `@oli-obk`

cc `@spastorino` `@ecstatic-morse`
2021-12-02 11:48:58 +00:00
Dylan MacKenzie
3e0e8be037 Handle DropAndReplace in const-checking
It runs before the real drop elaboration pass.
2021-11-30 17:25:30 -08:00
Yuki Okushi
898f1e4717
Rollup merge of #91368 - ecstatic-morse:mir-pass-reexport, r=cjgillot
Don't re-export `MirPass`

`rust-analyzer` wants to use the `rustc_const_eval` one by default, which is weird.

r? ``@cjgillot``
2021-11-30 17:29:12 +09:00
Yuki Okushi
a940c68035
Rollup merge of #91323 - RalfJung:assert-type, r=oli-obk
CTFE: support assert_zero_valid and assert_uninit_valid

This ensures the implementation of all three type-based assert_ intrinsics remains consistent in Miri.

`assert_inhabited` recently got stabilized in https://github.com/rust-lang/rust/pull/90896 (meaning stable `const fn` can call it), so do the same with these other intrinsics.

Cc ```@rust-lang/wg-const-eval```
2021-11-30 17:29:09 +09:00
Dylan MacKenzie
188d670125 Don't re-export MirPass 2021-11-29 12:58:15 -08:00
Ralf Jung
6c3c3e0952 CTFE: support assert_zero_valid and assert_uninit_valid 2021-11-29 11:49:31 -05:00
Oli Scherer
f394bb57bb
Always use const param envs for const eval.
Nothing else makes sense, and there is no "danger" in doing so, as it only does something if there are const bounds, which are unstable. This used to happen implicitly via the inferctxt before, which was much more fragile.
2021-11-29 21:19:50 +08:00
Oli Scherer
d51068ca28
Use the constness from the param env instead of having a separate dimension for it
This breaks a ~const test that will be fixed in a follow up commit of this PR
2021-11-29 21:19:47 +08:00
Matthias Krüger
233c50e79e
Rollup merge of #91251 - oli-obk:wf_sync_statics, r=matthewjasper
Perform Sync check on static items in wf-check instead of during const checks

r? `@RalfJung`

This check is solely happening on the signature of the static item and not on its body, therefor it belongs into wf-checking instead of const checking.
2021-11-28 17:11:10 +01:00
bors
e6d2de9483 Auto merge of #91230 - eggyal:fallible-type-fold, r=jackh726
Make `TypeFolder::fold_*` return `Result`

Implements rust-lang/compiler-team#432.

Initially this is just a rebase of `@LeSeulArtichaut's` work in #85469 (abandoned; see https://github.com/rust-lang/rust/pull/85485#issuecomment-908781112).  At that time, it caused a regression in performance that required some further exploration... with this rebased PR bors can hopefully report some perf analysis from which we can investigate further (if the regression is indeed still present).

r? `@jackh726` cc `@nikomatsakis`
2021-11-28 13:04:27 +00:00
Ralf Jung
f8e3b31858 Miri: fix alignment check in array initialization 2021-11-27 18:18:48 -05:00
Fabian Wolff
b38a54049e Print a suggestion when comparing references to primitive types in constant functions 2021-11-26 23:10:46 +01:00
Oli Scherer
18694126b1 Perform Sync check on static items in wf-check instead of during const checks 2021-11-26 14:22:45 +00:00
LeSeulArtichaut
30bf20a692
Unwrap the results of type folders
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:38:25 +00:00
Matthias Krüger
5fff1d77e7
Rollup merge of #91162 - RalfJung:miri-shift-truncation, r=oli-obk
explain why CTFE/Miri perform truncation on shift offset

Closes https://github.com/rust-lang/miri/issues/1920
2021-11-25 15:05:39 +01:00
Deadbeef
3b25e92a8f
Debug 2021-11-24 15:55:21 +08:00
woppopo
89b2e0c9d5 Make intrinsics::write_bytes const 2021-11-24 13:05:26 +09:00
Ralf Jung
94c9c22b39 explain why CTFE/Miri perform truncation on shift offset 2021-11-23 14:12:14 -05:00
Ralf Jung
70d418c315 Revert "require full validity when determining the discriminant of a value"
This reverts commit 0a2b7d71d9, reversing
changes made to 47c1bd1bcc.
This caused several unforeseen problems:
- https://github.com/rust-lang/rust/issues/91029
- https://github.com/rust-lang/rust/pull/89764#issuecomment-973588007
2021-11-20 12:33:04 -05:00
bors
50f2c29200 Auto merge of #90535 - tmiasko:clone-from, r=oli-obk
Implement `clone_from` for `State`

Data flow engine uses `clone_from` for domain values.  Providing an
implementation of `clone_from` will avoid some intermediate memory
allocations.

Extracted from #90413.

r? `@oli-obk`
2021-11-20 04:12:03 +00:00
Matthias Krüger
cf69f9e220
Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obk
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types

The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do.

The new helper methods will also be needed for https://github.com/rust-lang/miri/issues/1912.

r? ``````@oli-obk``````
2021-11-20 01:09:41 +01:00
Yuki Okushi
48947eafda
Rollup merge of #90633 - tmiasko:candidate-struct, r=nagisa
Refactor single variant `Candidate` enum into a struct

`Candidate` enum has only a single `Ref` variant.  Refactor it into a
struct and reduce overall indentation of the code by two levels.

No functional changes.
2021-11-19 13:06:34 +09:00
Yuki Okushi
0a2b7d71d9
Rollup merge of #90895 - RalfJung:read-discriminant-valid, r=oli-obk
require full validity when determining the discriminant of a value

This resolves (for now) the semantic question that came up in https://github.com/rust-lang/rust/pull/89764: arguably, reading the discriminant of a value is 'using' that value, so we are in our right to demand full validity. Reading a discriminant is somewhat special in that it works for values of *arbitrary* type; all the other primitive MIR operations work on specific types (e.g. `bool` or an integer) and basically implicitly require validity as part of just "doing their job".

The alternative would be to just require that the discriminant itself is valid, if any -- but then what do we do for types that do not have a discriminant, which kind of validity do we check? [This code](81117ff930/compiler/rustc_codegen_ssa/src/mir/place.rs (L206-L215)) means we have to at least reject uninhabited types, but I would rather not special case that.

I don't think this can be tested in CTFE (since validity is not enforced there), I will add a compile-fail test to Miri:
```rust
#[allow(enum_intrinsics_non_enums)]
fn main() {
    let i = 2u8;
    std::mem::discriminant(unsafe { &*(&i as *const _ as *const bool) }); // UB
}
```

(I tried running the check even on the CTFE machines, but then it runs during ConstProp and that causes all sorts of problems. We could run it for ConstEval but not ConstProp, but that simply does not seem worth the effort currently.)

r? ``@oli-obk``
2021-11-19 02:22:58 +09:00