about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
2021-12-12Rollup merge of #91815 - RalfJung:span, r=oli-obkMatthias Krüger-2/+2
better span for unexpected normalization failure in CTFE engine No reason to use `DUMMY_SP` here.
2021-12-12Rollup merge of #91814 - japm48:spelling-fix, r=RalfJungMatthias Krüger-2/+2
doc: fix typo in comments `dereferencable -> dereferenceable` Fixes #91802.
2021-12-12Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"Deadbeef-4/+6
This reverts commit ff2439b7b9bafcfdff86b7847128014699df8442, reversing changes made to 2a9e0831d6603d87220cedd1b1293e2eb82ef55c.
2021-12-11better span for unexpected normalization failure in CTFE engineRalf Jung-2/+2
2021-12-12doc: fix typo in commentsjapm48-2/+2
dereferencable -> dereferenceable
2021-12-11Rollup merge of #90081 - woppopo:const_write_bytes, r=oli-obkMatthias Krüger-0/+24
Make `intrinsics::write_bytes` const This is required to constify `MaybeUninit::zeroed` and `(*mut T)::write_bytes`. Tracking issue: #86302
2021-12-09Remove redundant [..]sest31-1/+1
2021-12-08Rollup merge of #91551 - b-naber:const-eval-normalization-ice, r=oli-obkMatthias Krüger-11/+23
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-08Rollup merge of #91272 - FabianWolff:issue-90870-const-fn-eq, r=wesleywiserMatthias Krüger-10/+66
Print a suggestion when comparing references to primitive types in `const fn` Fixes #90870.
2021-12-05allow for failure of subst_normalize_erasing_regions in const_evalb-naber-11/+23
2021-12-05Auto merge of #91475 - ecstatic-morse:mir-pass-manager3, r=oli-obkbors-0/+4
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 :cry: (it spits out a bunch of errors). cc `@oli-obk` `@wesleywiser` r? rust-lang/wg-mir-opt
2021-12-03Add initial AST and MIR support for unwinding from inline assemblyAmanieu d'Antras-17/+19
2021-12-03Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"Santiago Pastorino-6/+4
This reverts commit 18bb8c61a975fff6424cda831ace5b0404277145, reversing changes made to d9baa361902b172be716f96619b909f340802dea.
2021-12-02Update passes with new interfaceDylan MacKenzie-0/+4
2021-12-02Auto merge of #91469 - matthiaskrgr:rollup-xom3j55, r=matthiaskrgrbors-6/+2
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-02Rollup merge of #91410 - ecstatic-morse:const-precise-live-drops-take-2, ↵Matthias Krüger-6/+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-02Reduce boilerplate around infallible foldersAlan Egerton-3/+1
2021-12-02Auto merge of #91354 - fee1-dead:const_env, r=spastorinobors-4/+6
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-11-30Handle `DropAndReplace` in const-checkingDylan MacKenzie-6/+2
It runs before the real drop elaboration pass.
2021-11-30Rollup merge of #91368 - ecstatic-morse:mir-pass-reexport, r=cjgillotYuki Okushi-6/+2
Don't re-export `MirPass` `rust-analyzer` wants to use the `rustc_const_eval` one by default, which is weird. r? ``@cjgillot``
2021-11-30Rollup merge of #91323 - RalfJung:assert-type, r=oli-obkYuki Okushi-1/+25
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-29Don't re-export `MirPass`Dylan MacKenzie-6/+2
2021-11-29CTFE: support assert_zero_valid and assert_uninit_validRalf Jung-1/+25
2021-11-29Always use const param envs for const eval.Oli Scherer-0/+4
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-29Use the constness from the param env instead of having a separate dimension ↵Oli Scherer-4/+2
for it This breaks a ~const test that will be fixed in a follow up commit of this PR
2021-11-28Rollup merge of #91251 - oli-obk:wf_sync_statics, r=matthewjasperMatthias Krüger-27/+2
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-28Auto merge of #91230 - eggyal:fallible-type-fold, r=jackh726bors-1/+3
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-27Miri: fix alignment check in array initializationRalf Jung-1/+5
2021-11-26Print a suggestion when comparing references to primitive types in constant ↵Fabian Wolff-10/+66
functions
2021-11-26Perform Sync check on static items in wf-check instead of during const checksOli Scherer-27/+2
2021-11-26Unwrap the results of type foldersLeSeulArtichaut-1/+3
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-25Rollup merge of #91162 - RalfJung:miri-shift-truncation, r=oli-obkMatthias Krüger-1/+6
explain why CTFE/Miri perform truncation on shift offset Closes https://github.com/rust-lang/miri/issues/1920
2021-11-24DebugDeadbeef-4/+5
2021-11-24Make `intrinsics::write_bytes` constwoppopo-0/+24
2021-11-23explain why CTFE/Miri perform truncation on shift offsetRalf Jung-1/+6
2021-11-20Revert "require full validity when determining the discriminant of a value"Ralf Jung-12/+0
This reverts commit 0a2b7d71d96a22126cce57f0dab5890d060f2259, reversing changes made to 47c1bd1bcc50b25d133f8be3d49825491c1df249. 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-20Auto merge of #90535 - tmiasko:clone-from, r=oli-obkbors-1/+14
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-20Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obkMatthias Krüger-32/+55
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-19Rollup merge of #90633 - tmiasko:candidate-struct, r=nagisaYuki Okushi-101/+82
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-19Rollup merge of #90895 - RalfJung:read-discriminant-valid, r=oli-obkYuki Okushi-0/+12
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](https://github.com/rust-lang/rust/blob/81117ff930fbf3792b4f9504e3c6bccc87b10823/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-18fix CTFE/Miri simd_insert/extract on array-style repr(simd) typesRalf Jung-32/+55
2021-11-16Rollup merge of #90892 - RalfJung:miri-partial-ptr-copy, r=oli-obkYuki Okushi-7/+6
fix ICE on Miri/CTFE copy of half a pointer Fixes https://github.com/rust-lang/miri/issues/1910 r? `````@oli-obk`````
2021-11-14require full validity when determining the discriminant of a valueRalf Jung-0/+12
2021-11-13fix ICE on Miri/CTFE copy of half a pointerRalf Jung-7/+6
2021-11-13Auto merge of #89551 - jhpratt:stabilize-const_raw_ptr_deref, r=oli-obkbors-7/+13
Stabilize `const_raw_ptr_deref` for `*const T` This stabilizes dereferencing immutable raw pointers in const contexts. It does not stabilize `*mut T` dereferencing. This is behind the same feature gate as mutable references. closes https://github.com/rust-lang/rust/issues/51911
2021-11-10Auto merge of #88670 - camelid:miri-uninit-num, r=RalfJungbors-5/+12
miri: Detect uninitialized integers and floats Part of rust-lang/miri#1340. Companion Miri PR: rust-lang/miri#1904 r? `@RalfJung`
2021-11-09miri: Detect uninitialized integers and floatsNoah Lev-5/+12
Change the Miri engine to allow configuring whether to check initialization of integers and floats. This allows the Miri tool to optionally check for initialization if requested by the user.
2021-11-09Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakisMatthias Krüger-0/+1
Type inference for inline consts Fixes #78132 Fixes #78174 Fixes #81857 Fixes #89964 Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure. Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts. The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure. With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME. Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck). cc `````@spastorino````` `````@lcnr````` r? `````@nikomatsakis````` `````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-08Make select_* methods return Vec for TraitEngineDeadbeef-2/+3
2021-11-07Give inline const separate DefKindGary Guo-0/+1