Commit Graph

544 Commits

Author SHA1 Message Date
DrMeepster
9f9c311718 Validate all fields of box instead of validating allocator specifically 2022-06-28 02:19:52 -07:00
Ralf Jung
8e73c3ed18 make AllocKind actually public 2022-06-27 10:58:30 -04:00
Ralf Jung
b094116538 interpret: refactor allocation info query
We now have an infallible function that also tells us which kind of allocation we are talking about.
Also we do longer have to distinguish between data and function allocations for liveness.
2022-06-26 22:49:40 -04:00
DrMeepster
d317988505 validate box's allocator 2022-06-26 18:54:03 -07:00
DrMeepster
6e32a16520 fix box with custom allocator in miri 2022-06-26 13:58:37 -07:00
Ralf Jung
852a111133 interpret: do not prune requires_caller_location stack frames quite so early 2022-06-26 14:42:26 -04:00
Yuki Okushi
e3ae9f5b20
Rollup merge of #98099 - RalfJung:convert_tag_add_extra, r=oli-obk
interpret: convert_tag_add_extra: allow tagger to raise errors

Needed for https://github.com/rust-lang/miri/issues/2234

r? `@oli-obk`
2022-06-22 07:03:59 +09:00
bors
a25b1315ee Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk
Remove dereferencing of Box from codegen

Through #94043, #94414, #94873, and #95328, I've been fixing issues caused by Box being treated like a pointer when it is not a pointer. However, these PRs just introduced special cases for Box. This PR removes those special cases and instead transforms a deref of Box into a deref of the pointer it contains.

Hopefully, this is the end of the Box<T, A> ICEs.
2022-06-21 11:00:39 +00:00
Michael Goulet
5373d738e8 Mention formatting macros when encountering ArgumentV1::new in const 2022-06-19 20:18:08 -07:00
Ralf Jung
1c1a60f0a3 interpret: convert_tag_add_extra, init_allocation_extra: allow tagger to raise errors 2022-06-16 09:41:07 -07:00
DrMeepster
dff1f9f6bb make sure miri ices when dereferencing a box 2022-06-15 18:39:23 -07:00
DrMeepster
cb417881a9 remove box derefs from codgen 2022-06-15 18:38:26 -07:00
Deadbeef
26ac45614b Rename impl_constness to constness
The current code is a basis for `is_const_fn_raw`, and `impl_constness`
is no longer a valid name, which is previously used for determining the
constness of impls, and not items in general.
2022-06-15 20:54:43 +10:00
b-naber
15c1c06522 rebase 2022-06-14 17:57:51 +02:00
b-naber
8093db6e2b correctly create Scalar for meta info 2022-06-14 16:11:36 +02:00
b-naber
dbef6e4507 address review 2022-06-14 16:08:18 +02:00
b-naber
705d818bd5 implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
Nicholas Nethercote
93e4b6ef06 Rename the ConstS::val field as kind.
And likewise for the `Const::val` method.

Because its type is called `ConstKind`. Also `val` is a confusing name
because `ConstKind` is an enum with seven variants, one of which is
called `Value`. Also, this gives consistency with `TyS` and `PredicateS`
which have `kind` fields.

The commit also renames a few `Const` variables from `val` to `c`, to
avoid confusion with the `ConstKind::Value` variant.
2022-06-14 13:06:44 +10:00
Matthias Krüger
9d27f2e665
Rollup merge of #98043 - TaKO8Ki:remove-unnecessary-to-string, r=davidtwco
Remove unnecessary `to_string` and `String::new`

73fa217bc1 changed the type of the `suggestion` argument to `impl ToString`. This patch removes unnecessary `to_string` and `String::new`.

cc: `````@davidtwco`````
2022-06-13 21:35:56 +02:00
Matthias Krüger
426922be40
Rollup merge of #97960 - RalfJung:offset-from, r=oli-obk
interpret: unify offset_from check with offset check

`offset` does the check with a single `check_ptr_access` call while `offset_from` used two calls. Make them both just one one call.

I originally intended to actually factor this into a common function, but I am no longer sure if that makes a lot of sense... the two functions start with pretty different precondition (e.g. `offset` *knows* that the 2nd pointer has the same provenance).

I also reworded the UB messages a little. Saying it "cannot" do something is not how we usually phrase UB (as far as I know). Instead it's not *allowed* to do that.

r? ``````@oli-obk``````
2022-06-13 21:35:55 +02:00
Takayuki Maeda
77d6176e69 remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
Scott McMurray
a6c6fa0e33 Try out yeet in the MIR interpreter 2022-06-11 23:08:06 -07:00
Dylan DPC
11d8ae2c71
Rollup merge of #97761 - RalfJung:vtable-validation, r=cjgillot
validating the vtable can lead to Stacked Borrows errors

Fixes https://github.com/rust-lang/miri/issues/2123
2022-06-11 12:59:26 +02:00
Ralf Jung
e5245ef1eb interpret: unify offset_from check with offset check 2022-06-09 20:47:06 -04:00
bors
282445a288 Auto merge of #97740 - RalfJung:ctfe-cycle-spans, r=lcnr
use precise spans for recursive const evaluation

This fixes https://github.com/rust-lang/rust/issues/73283 by using a `TyCtxtAt` with a more precise span when the interpreter recursively calls itself. Hopefully such calls are sufficiently rare that this does not cost us too much performance.

(In theory, cycles can also arise through layout computation, as layout can depend on consts -- but layout computation happens all the time so we'd have to do something to not make this terrible for performance.)
2022-06-09 01:52:15 +00:00
Dylan DPC
29c6f5f603
Rollup merge of #97763 - RalfJung:fallible-cast, r=lcnr
Allow ptr_from_addr_cast to fail

This is needed for https://github.com/rust-lang/miri/issues/2133: I would like to have an option in Miri to error when a int2ptr cast is executed.
2022-06-08 13:43:18 +02:00
bors
64a7aa7016 Auto merge of #97447 - nnethercote:improve-folding, r=jackh726
Folding revamp

r? `@ghost`
2022-06-08 05:36:40 +00:00
Nicholas Nethercote
90db033955 Folding revamp.
This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.
2022-06-08 09:24:03 +10:00
Tomasz Miąsko
631d767fee Remove AlwaysLiveLocals wrapper struct
It is just a wrapper around a `BitSet` and
doesn't have any functionality of its own.
2022-06-07 16:54:00 +02:00
bors
357bc27904 Auto merge of #97795 - Dylan-DPC:rollup-dxilagr, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97312 (Compute lifetimes in scope at diagnostic time)
 - #97495 (Add E0788 for improper #[no_coverage] usage)
 - #97579 (Avoid creating `SmallVec`s in `global_llvm_features`)
 - #97767 (interpret: do not claim UB until we looked more into variadic functions)
 - #97787 (E0432: rust 2018 -> rust 2018 or later    in --explain message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-06 16:09:54 +00:00
bors
9d20fd1098 Auto merge of #97684 - RalfJung:better-provenance-control, r=oli-obk
interpret: better control over whether we read data with provenance

The resolution in https://github.com/rust-lang/unsafe-code-guidelines/issues/286 seems to be that when we load data at integer type, we implicitly strip provenance. So let's implement that in Miri at least for scalar loads. This makes use of the fact that `Scalar` layouts distinguish pointer-sized integers and pointers -- so I was expecting some wild bugs where layouts set this incorrectly, but so far that does not seem to happen.

This does not entirely implement the solution to https://github.com/rust-lang/unsafe-code-guidelines/issues/286; we still do the wrong thing for integers in larger types: we will `copy_op` them and then do validation, and validation will complain about the provenance. To fix that we need mutating validation; validation needs to strip the provenance rather than complaining about it. This is a larger undertaking (but will also help resolve https://github.com/rust-lang/miri/issues/845 since we can reset padding to `Uninit`).

The reason this is useful is that we can now implement `addr` as a `transmute` from a pointer to an integer, and actually get the desired behavior of stripping provenance without exposing it!
2022-06-06 13:28:58 +00:00
Ralf Jung
a6207ec975 interpret: do not claim UB until we looked more into variadic functions 2022-06-05 13:24:24 -04:00
Ralf Jung
67ec96955f validating the vtable can lead to Stacked Borrows errors 2022-06-05 12:27:08 -04:00
Ralf Jung
e1f0736927 Allow ptr_from_addr_cast to fail 2022-06-05 10:53:35 -04:00
Ralf Jung
d208f80039 reduce code duplication 2022-06-05 10:13:34 -04:00
Ralf Jung
47d11a8483 interpret: better control over whether we read data with provenance, and implicit provenance stripping where possible 2022-06-05 10:13:34 -04:00
Ralf Jung
467e0f4446 use precise spans for recursive const evaluation 2022-06-04 16:18:03 -04:00
Ralf Jung
9ab4f876a1 const_prop_lint: ensure we have up-to-date cur_span() 2022-06-04 15:59:24 -04:00
Ralf Jung
7892e1cedb Move statement_index increment out of statement() function
That function is called by const_prop, where updating the index like that is totally meaningless.
2022-06-04 15:59:24 -04:00
Ralf Jung
9e00fb0d89 tweak some bug!s 2022-06-04 11:15:36 -04:00
Dylan DPC
a6d7939855
Rollup merge of #97663 - RalfJung:keine-halben-sachen, r=oli-obk
take back half-baked noaliasing check in Assignment

Doing an aliasing check in `copy_op` does not make a ton of sense. We have to eventually do something in the `Assignment` statement handling instead.
2022-06-03 11:18:25 +02:00
Ralf Jung
7676f07d0e take back half-baked noaliasing check in Assignment 2022-06-02 15:14:35 -04:00
Ralf Jung
d5a590f537 comment
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-02 11:12:12 -04:00
Ralf Jung
fafccdced3 add cast kind of from_exposed_addr (int-to-ptr casts) 2022-06-02 10:46:13 -04:00
Yuki Okushi
b78c118b09
Rollup merge of #97626 - RalfJung:expose, r=tmiasko
rename PointerAddress → PointerExposeAddress

`PointerAddress` sounds a bit too much like `ptr.addr()`, but this corresponds to `ptr.expose_addr()`.

r? `@tmiasko`
2022-06-02 06:44:29 +09:00
Ralf Jung
4dc5d457d8 rename PointerAddress → PointerExposeAddress 2022-06-01 14:08:17 -04:00
Yuki Okushi
2ab919ad9c
Rollup merge of #97216 - RalfJung:null-ptr-check, r=oli-obk
Ensure we never consider the null pointer dereferencable

This replaces the checks that are being removed in https://github.com/rust-lang/rust/pull/97188. Those checks were too early and hence incorrect.
2022-06-01 23:36:46 +09:00
Tomasz Miąsko
dff602fc18 Add a pointer to address cast kind
A pointer to address cast are often special-cased.
Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-31 00:00:00 +00:00
Michael Goulet
12ba87b996
Rollup merge of #97395 - RalfJung:call-abi, r=oli-obk
Miri call ABI check: ensure type size+align stay the same

We should almost certainly not accept calls where caller and callee disagree on the size or alignment of the type.

The checks we do *almost* imply that, except that `ScalarPair` types can have `repr(align)` and thus differ in size/align even when they are pairs of the same primitive type.

r? ``@oli-obk``
2022-05-30 15:57:28 -07:00
bors
c35035cefc Auto merge of #97025 - ouz-a:mini-derefer-generator, r=davidtwco
Add validation layer for Derefer

_Follow up work to #96549 #96116 #95857 #95649_

This adds validation for Derefer making sure it is always the first projection.

r? rust-lang/mir-opt
2022-05-30 20:06:25 +00:00
ouz-a
e71913e847 validate derefer, run derefer inside generator 2022-05-30 18:36:14 +03:00
bors
5c780b98d1 Auto merge of #96964 - oli-obk:const_trait_mvp, r=compiler-errors
Replace `#[default_method_body_is_const]` with `#[const_trait]`

pulled out of #96077

related issues:  #67792 and #92158

cc `@fee1-dead`

This is groundwork to only allowing `impl const Trait` for traits that are marked with `#[const_trait]`. This is necessary to prevent adding a new default method from becoming a breaking change (as it could be a non-const fn).
2022-05-30 09:19:03 +00:00
Oli Scherer
ecaf7b7cee Reduce the scope of a mutable variable 2022-05-30 08:52:25 +00:00
Oli Scherer
4d390de4a3 Add a helper function for checking whether a default function in a trait can be treated as const 2022-05-30 08:52:25 +00:00
Deadbeef
257f06587c Remove #[default..] and add #[const_trait] 2022-05-30 08:52:24 +00:00
Michael Goulet
34e05812e0 Fix TyKind lint, make consts no longer fn, etc 2022-05-28 11:38:22 -07:00
Michael Goulet
a056a953f0 Initial fixes on top of type interner commit 2022-05-28 11:38:22 -07:00
Wilco Kusee
a7015fe816 Move things to rustc_type_ir 2022-05-28 11:38:22 -07:00
bors
56fd680cf9 Auto merge of #96046 - oli-obk:const_typeck, r=cjgillot
Move various checks to typeck so them failing causes the typeck result to get tainted

Fixes #69487
fixes #79047

cc `@RalfJung` this gets rid of the `Transmute` invalid program error variant
2022-05-27 11:31:37 +00:00
Matthias Krüger
5fc8a8e227 clippy::complexity fixes
clone_on_copy
useless_format
bind_instead_of_map
filter_map_identity
useless_conversion
map_flatten
unnecessary_unwrap
2022-05-26 13:14:24 +02:00
Ralf Jung
d7a2d9ae0e Miri call ABI check: ensure type size+align stay the same 2022-05-25 15:08:07 +02:00
Oli Scherer
ac6b7083c8 Remove outdated comment 2022-05-24 16:28:57 +00:00
Oli Scherer
0d88631059 Add the transmute and asm checks to typeck as deferred checks 2022-05-24 16:28:57 +00:00
5225225
dd9f31d000 Add flag for stricter checks on uninit/zeroed 2022-05-24 14:26:52 +01:00
Jakob Degen
09b0936db2 Refactor call terminator to always hold a destination place 2022-05-23 17:49:04 -04:00
Michael Goulet
1784634a39 Lifetime variance fixes for rustc 2022-05-22 14:29:32 -07:00
bors
acfd327fd4 Auto merge of #97177 - oli-obk:const-stability, r=davidtwco
Implement proper stability check for const impl Trait, fall back to unstable const when undeclared

Continuation of #93960

`@jhpratt` it looks to me like the test was simply not testing for the failure you were looking for? Your checks actually do the right thing for const traits?
2022-05-22 06:47:36 +00:00
Jacob Pratt
49c82f31a8
Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
Ralf Jung
0b781b04cb Ensure we never consider the null pointer dereferencable 2022-05-20 15:55:55 +02:00
Guillaume Gomez
9098f05b26
Rollup merge of #97188 - carbotaniuman:remove-null-assert, r=RalfJung
Remove unneeded null pointer asserts in ptr2int casts

This removes an assert that a pointer with address 0 has no provenance. This change is needed to support permissive provenance work in Miri, and seems justified by `ptr.with_addr(0)` working and a discussion on Zulip regarding LLVM semantics.

r? `@RalfJung`
2022-05-20 14:03:04 +02:00
Guillaume Gomez
706aa59efa
Rollup merge of #97185 - RalfJung:number-validity, r=oli-obk
interpret/validity: separately control checking numbers for being init and non-ptr

This lets Miri control this in a more fine-grained way.

r? `@oli-obk`
2022-05-20 14:03:03 +02:00
carbotaniuman
e24673502f Remove unneeded asserts 2022-05-19 13:51:53 -05:00
Ralf Jung
4bb152c4bc fmt 2022-05-19 20:34:37 +02:00
Ralf Jung
5514b1176f interpret/validity: separately control checking numbers for being init and non-ptr 2022-05-19 20:16:25 +02:00
Jacob Pratt
f0620c9503 Proper const stability check, default to unstable
Rather than deferring to const eval for checking if a trait is const, we
now check up-front. This allows the error to be emitted earlier, notably
at the same time as other stability checks.

Also included in this commit is a change of the default const stability
level to UNstable. Previously, an item that was `const` but did not
explicitly state it was unstable was implicitly stable.
2022-05-19 12:21:45 +00:00
Jacob Pratt
a9dd4cfa6b Add and use stability helper methods
This avoids an ambiguity (when reading) where `.level.is_stable()` is
not immediately clear whether it is general stability or const
stability.
2022-05-19 12:21:45 +00:00
Jacob Pratt
f53fc41cfc Fall back to being const-unstable when undeclared 2022-05-19 12:21:45 +00:00
bors
cd282d7f75 Auto merge of #97019 - b-naber:transition-to-valtrees-pt1, r=oli-obk
Transition to valtrees pt1

Compartmentalising https://github.com/rust-lang/rust/pull/96591 as much as possible.

r? `@oli-obk`
2022-05-18 20:12:07 +00:00
Yuki Okushi
248890c32e
Rollup merge of #97116 - RalfJung:ref-validity, r=oli-obk
interpret/validity: reject references to uninhabited types

According to https://doc.rust-lang.org/reference/behavior-considered-undefined.html, this is definitely UB. And we can check this without actually looking up anything in memory, we just need the reference value and its type, making this a great candidate for a validity invariant IMO and my favorite resolution of https://github.com/rust-lang/unsafe-code-guidelines/issues/77.

With this PR, Miri with `-Zmiri-check-number-validity` implements all my preferred options for what the validity invariants of our types could be. :)

CTFE has been doing recursive checking anyway, so this is backwards compatible but might change the error output. I will submit a PR with the new Miri tests soon.

r? `@oli-obk`
2022-05-18 07:41:01 +09:00
Ralf Jung
501f5d09a0 interpret/validity: reject references to uninhabited types 2022-05-17 17:32:36 +02:00
bors
3655175a75 Auto merge of #97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #96329 (Add a couple tests for #90887 fixes)
 - #97009 (Allow `unused_macro_rules` in path tests)
 - #97075 (Add regression test for #81804)
 - #97079 (Change `Successors` to `impl Iterator<Item = BasicBlock>`)
 - #97080 (remove the `RelateResultCompare` trait)
 - #97093 (Migrate `maybe_recover_from_bad_type_plus` diagnostic)
 - #97102 (Update function pointer call error message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-17 12:01:12 +00:00
bors
735efc0c70 Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwco
Add a query for checking whether a function is an intrinsic.

work towards #93145

This will reduce churn when we add more ways to declare intrinsics

r? `@scottmcm`
2022-05-17 09:39:26 +00:00
mbartlett21
56649bb844 Update function pointer call error message
It now uses the type of context. (issue 97082)
2022-05-17 04:13:20 +00:00
b-naber
96b36d6eb2 use GlobalId in eval_to_valtree query and introduce query for valtree_to_const_val 2022-05-16 15:58:15 +02:00
Oli Scherer
0a6b69106e Add a query for checking whether a function is an intrinsic. 2022-05-16 07:07:44 +00:00
bors
2a8a0fc423 Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk
Add EarlyBinder

Chalk has no concept of `Param` (e0ade19d13/chalk-ir/src/lib.rs (L579)) or `ReEarlyBound` (e0ade19d13/chalk-ir/src/lib.rs (L1308)). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`
2022-05-14 23:53:11 +00:00
bors
8019fa0dc0 Auto merge of #95826 - carbotaniuman:miri-permissive-provenance, r=RalfJung
Initial work on Miri permissive-exposed-provenance

Rustc portion of the changes for portions of a permissive ptr-to-int model for Miri. The main changes here are changing `ptr_get_alloc` and `get_alloc_id` to return an Option, and also making ptr-to-int casts have an expose side effect.
2022-05-14 10:36:47 +00:00
Jack Huey
c92248ab9f Add bound_type_of 2022-05-13 18:27:18 -04:00
carbotaniuman
bd5fce65c6 Rustc changes for permissive provenance 2022-05-13 12:30:25 -05:00
klensy
7f318256c9 fix clippy expect_fun_call 2022-05-12 19:26:52 +03:00
bors
481db40311 Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco
don't encode only locally used attrs

Part of https://github.com/rust-lang/compiler-team/issues/505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
2022-05-12 12:48:30 +00:00
bors
3a08bd7873 Auto merge of #96889 - Aaron1011:place-ref-remove, r=compiler-errors
Remove `PartialOrd`/`Ord` impl for `PlaceRef`

This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
2022-05-12 05:03:48 +00:00
Scott McMurray
003b954a43 Apply CR suggestions; add real tracking issue 2022-05-11 17:16:25 -07:00
Scott McMurray
4bb15b3797 Add a debug check for ordering, and check for isize overflow in CTFE 2022-05-11 17:16:25 -07:00
Scott McMurray
89a18cb600 Add unsigned_offset_from on pointers
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`.  Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`.

As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives.  That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change.

This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE.  It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2022-05-11 17:16:25 -07:00
Aaron Hill
6b747aa397
Remove PartialOrd/Ord impl for PlaceRef
This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
2022-05-11 16:22:23 -04:00
bors
6dd68402c5 Auto merge of #96220 - RalfJung:scalar-no-padding, r=oli-obk
tighten sanity checks around Scalar and ScalarPair

While investigating https://github.com/rust-lang/rust/issues/96185 I noticed codegen has tighter sanity checks here than Miri does, so I added some more assertions. Strangely, some of them fail, so I also needed to add a HACK... that is probably worth looking into.

This does not fix that issue, but it changes the ICE messages, making it quite clear that we have a scalar whose size is not the same as that of the surrounding layout.

r? `@oli-obk`
2022-05-11 18:34:14 +00:00
Dylan DPC
0c2cee2e9d
Rollup merge of #95281 - pierwill:fix-85513, r=Dylan-DPC
Fix inaccurate function name in `rustc_const_eval` docs

Looks to me like this fixes #85513. I had trouble making a intra-docs link to `eval_place_to_op` work, though...
2022-05-11 13:49:28 +02:00
Ralf Jung
14f6daf935 avoid computing Scalar size/align in debug builds 2022-05-11 13:32:19 +02:00
Jack Huey
319575ae8c Introduce EarlyBinder 2022-05-10 22:47:18 -04:00
Ralf Jung
761077e19e fmt 2022-05-10 14:38:00 +02:00
Ralf Jung
aef8a9306d update/remove some old comments 2022-05-10 14:23:32 +02:00
Ralf Jung
600d960261 even tighter checks for layouts on immediate field projections 2022-05-10 14:23:32 +02:00
Ralf Jung
79c169d5cf disable one check for now until #96185 is fixed 2022-05-10 14:23:32 +02:00
Ralf Jung
719655658a tighten sanity checks around Scalar and ScalarPair 2022-05-10 13:32:20 +02:00
lcnr
6c8265dc56 only_local: always check for misuse 2022-05-10 12:07:35 +02:00
bors
e013f9e0ca Auto merge of #96815 - SparrowLii:promote_const, r=oli-obk
optimize `promote_consts` by caching the results of `validate_local`

From the FIXME in the impl of `promote_consts`. Early return the `validate_local` should save some compile time.

`qualif_local` is similar to this, but requires futher changing because there are different types of qualif checks. If this PR is effective, I will do it as well.
2022-05-09 11:49:09 +00:00
SparrowLii
b890037af3 use Result<(),()> instead of Validity enum 2022-05-09 17:13:30 +08:00
SparrowLii
cb7f116c04 optimize promote_consts by cache the validate check 2022-05-07 21:02:25 +08:00
Jakob Degen
c4168fdb50 Check that field projections have the correct type 2022-05-06 16:43:09 -04:00
pierwill
f1f0734718 Fix inaccurate function name in rustc_const_eval docs 2022-05-06 14:52:42 -05:00
Jakob Degen
5289bbece3 Expand validator to be more precise on checked binary ops 2022-05-06 15:40:32 -04:00
Matthias Krüger
68048199c9
Rollup merge of #96714 - RalfJung:scalar-pair-debug, r=oli-obk
interpret/validity: debug-check ScalarPair layout information

This would have caught https://github.com/rust-lang/rust/issues/96158.
I ran the Miri test suite and it still passes.

r? `@oli-obk`
2022-05-05 15:43:07 +02:00
Ralf Jung
e47d6c7a6b give it a scary name 2022-05-05 09:55:38 +02:00
Ralf Jung
5b20da8180 interpret: debug-check ScalarPair layout information 2022-05-04 22:52:02 +02:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
Vadim Petrochenkov
5b5964f569 rustc: Panic by default in DefIdTree::parent
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 01:56:50 +03:00
bors
9a98c63b30 Auto merge of #96500 - SparrowLii:rpo, r=tmiasko
Reduce duplication of RPO calculation of mir

Computing the RPO of mir is not a low-cost thing, but it is duplicate in many places. In particular the `iterate_to_fixpoint` method which is called multiple times when computing the data flow.
This PR reduces the number of times the RPO is recalculated as much as possible, which should save some compile time.
2022-04-30 05:06:47 +00:00
SparrowLii
7149bbcdc5 Eliminate duplication of RPO calculation for mir
add `postorder_cache` to mir Body

add `ReversePostorderCache` struct

correct struct name and comments
2022-04-30 03:42:57 +08:00
bors
b2c2a32870 Auto merge of #95976 - b-naber:valtree-constval-conversion, r=oli-obk
Implement Valtree to ConstValue conversion

Once we start to use `ValTree`s in the type system we will need to be able to convert them into `ConstValue` instances, which we want to continue to use after MIR construction.

r? `@oli-obk`

cc `@RalfJung`
2022-04-28 13:18:22 +00:00
b-naber
ef5f07256c combine all unsized types and add another recursive call to process nested unsized types correctly 2022-04-27 16:58:16 +02:00
b-naber
bfefb4d74c account for custom DSTs in valtree -> constvalue conversion 2022-04-26 18:40:15 +02:00
b-naber
f7eae4e580 include valtree creation and valtree -> constvalue conversion in debug assertions check 2022-04-24 10:59:21 +02:00
Jakob Degen
ae7d6facda Relax restrictions for copy operands 2022-04-22 16:45:15 -04:00
b-naber
bc698c73e9 deduplicate a lot of code 2022-04-21 23:11:06 +02:00
b-naber
28af967bb9 implement (as of now still unused) query for valtree -> constvalue conversion 2022-04-21 16:37:24 +02:00
b-naber
1157dc7167 implement valtree -> constvalue conversion 2022-04-21 15:53:26 +02:00
Dylan DPC
72cb094611
Rollup merge of #96160 - RalfJung:interpret-debug, r=oli-obk
Miri/interpreter debugging tweaks

Some changes I made to make debugging Miri with trace logging less terrible.

r? ``@oli-obk``
2022-04-20 18:26:02 +02:00
Dylan DPC
9d9d5910af
Rollup merge of #96165 - RalfJung:miri-provenance-cleanup, r=oli-obk
Miri provenance cleanup

Reviewing https://github.com/rust-lang/rust/pull/95826 by ``@carbotaniuman`` made me realize that we could clean things up a little here.

``@carbotaniuman`` please let me know if you're okay with landing this (it will create a lot of conflicts with your PR), or if you'd prefer incorporating the ideas from this PR into yours. I think we want to end up in a situation where the function you called `ptr_reify_alloc` returns just two things, a concrete tag and an offset. Getting an `AllocId` from a concrete tag should be infallible like now. However a concrete tag and `Tag` don't have to be the same type.

r? ``@oli-obk``
2022-04-19 22:57:43 +02:00
Ralf Jung
55f0977a6b remove an unnecessary use of loc_place.ptr.into_pointer_or_addr 2022-04-18 12:47:38 -04:00
Ralf Jung
c83241a7f9 avoid an unnecessary call to Pointer::into_parts, and caution against into_pointer_or_addr 2022-04-18 12:30:17 -04:00
Ralf Jung
3236092503 add method to get absolute address of a pointer (useful only for Miri) 2022-04-18 12:30:17 -04:00
Ralf Jung
c9e568f72e avoid pairing up AllocId and PointerTag, which is redundant 2022-04-18 10:14:06 -04:00
Ralf Jung
54ab357a5b ptr_get_alloc_id: don't return an actual Pointer 2022-04-17 22:27:14 -04:00
Ralf Jung
f3bdcfb8b0 downgrade really verbose logging to trace 2022-04-17 20:52:33 -04:00
Ralf Jung
989e7479d9 interpret: more debug logging for read_scalar and write_scalar 2022-04-17 20:52:30 -04:00
Ralf Jung
3ec1febbf5 add caution to some comments 2022-04-17 19:32:13 -04:00
Ralf Jung
85ee04c44a when writing uninit to an allocation, also clear relocations like other writes do 2022-04-17 19:16:54 -04:00
Dylan DPC
1dc672a766
Rollup merge of #95426 - b-naber:valtrees-slice, r=RalfJung,oli-obk
Include Refs in Valtree Creation

This adds references to `const_to_valtree`, which isn't used in the compiler yet, but after the previous changes we made to the thir and mir representations and this change we should be able to finally introduce them in the next PR.

I wasn't able to properly test this code, except indirectly by including a call of `const_to_valtree` in the code that currently creates constants (`turn_into_const_value`).

r? `@lcnr`

cc `@oli-obk` `@RalfJung`
2022-04-16 19:42:03 +02:00
Dylan DPC
ab7fb29878
Rollup merge of #96050 - oli-obk:deaggregator_cleanup, r=RalfJung
Remove some now-dead code that was only relevant before deaggregation.

The code was broken anyway, if the deaggregator is disabled, it would have ICEd on any non-enum Adt

r? ```@RalfJung```
2022-04-16 07:12:47 +02:00
b-naber
d8205cd3fe handle arrays and slices uniformly in valtree creation 2022-04-14 22:01:40 +02:00
Oli Scherer
48029aba2c Remove some now-dead code that was only relevant before deaggregation.
The code was broken anyway, if the deaggregator is disabled, it would have ICE on any non-enum Adt
2022-04-14 13:31:21 +00:00
Jakob Degen
d5f3863204 Consider lifetimes when comparing types for equality in MIR validator 2022-04-13 05:51:08 -04:00
b-naber
4b126b805b use len on mplace instead of reading immediate, remove dead code 2022-04-12 16:08:59 +02:00
Jakob Degen
8732bf5db3 Remove rule that place loads may not happen with variant index set 2022-04-11 15:56:04 -04:00
Jakob Degen
411ae6f5ad Address various comments and change some details around place to value conversions 2022-04-11 15:22:32 -04:00
Jakob Degen
f2d7908ff7 Adjust MIR validator to check a few more things for terminators 2022-04-11 15:22:32 -04:00
Jakob Degen
9ac5e986ed Extend the MIR validator to check many more things around rvalues. 2022-04-11 15:18:54 -04:00
Jakob Degen
2f4a7a0742 Adjust computation of place types to detect more invalid places 2022-04-11 15:18:53 -04:00
Jakob Degen
9b6b1a625b Add new Deinit statement kind 2022-04-11 08:55:03 -04:00