about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
2022-06-09Auto merge of #97740 - RalfJung:ctfe-cycle-spans, r=lcnrbors-19/+23
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-08Rollup merge of #97763 - RalfJung:fallible-cast, r=lcnrDylan DPC-6/+7
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-08Auto merge of #97447 - nnethercote:improve-folding, r=jackh726bors-2/+2
Folding revamp r? `@ghost`
2022-06-08Folding revamp.Nicholas Nethercote-2/+2
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-07Remove `AlwaysLiveLocals` wrapper structTomasz Miąsko-2/+2
It is just a wrapper around a `BitSet` and doesn't have any functionality of its own.
2022-06-06Auto merge of #97795 - Dylan-DPC:rollup-dxilagr, r=Dylan-DPCbors-6/+1
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-06Auto merge of #97684 - RalfJung:better-provenance-control, r=oli-obkbors-18/+45
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-05interpret: do not claim UB until we looked more into variadic functionsRalf Jung-6/+1
2022-06-05validating the vtable can lead to Stacked Borrows errorsRalf Jung-0/+8
2022-06-05Allow ptr_from_addr_cast to failRalf Jung-6/+7
2022-06-05reduce code duplicationRalf Jung-13/+12
2022-06-05interpret: better control over whether we read data with provenance, and ↵Ralf Jung-18/+46
implicit provenance stripping where possible
2022-06-04use precise spans for recursive const evaluationRalf Jung-3/+4
2022-06-04const_prop_lint: ensure we have up-to-date cur_span()Ralf Jung-1/+4
2022-06-04Move statement_index increment out of statement() functionRalf Jung-9/+9
That function is called by const_prop, where updating the index like that is totally meaningless.
2022-06-04tweak some bug!sRalf Jung-6/+6
2022-06-03Rollup merge of #97663 - RalfJung:keine-halben-sachen, r=oli-obkDylan DPC-3/+3
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-02take back half-baked noaliasing check in AssignmentRalf Jung-3/+3
2022-06-02add cast kind of from_exposed_addr (int-to-ptr casts)Ralf Jung-10/+24
2022-06-02Rollup merge of #97626 - RalfJung:expose, r=tmiaskoYuki Okushi-3/+3
rename PointerAddress → PointerExposeAddress `PointerAddress` sounds a bit too much like `ptr.addr()`, but this corresponds to `ptr.expose_addr()`. r? `@tmiasko`
2022-06-01rename PointerAddress → PointerExposeAddressRalf Jung-3/+3
2022-06-01Rollup merge of #97216 - RalfJung:null-ptr-check, r=oli-obkYuki Okushi-0/+4
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-05-31Add a pointer to address cast kindTomasz Miąsko-15/+22
A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-30Rollup merge of #97395 - RalfJung:call-abi, r=oli-obkMichael Goulet-1/+8
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-28Fix TyKind lint, make consts no longer fn, etcMichael Goulet-5/+5
2022-05-28Initial fixes on top of type interner commitMichael Goulet-4/+4
2022-05-28Move things to rustc_type_irWilco Kusee-3/+3
2022-05-27Auto merge of #96046 - oli-obk:const_typeck, r=cjgillotbors-8/+4
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-26clippy::complexity fixesMatthias Krüger-7/+3
clone_on_copy useless_format bind_instead_of_map filter_map_identity useless_conversion map_flatten unnecessary_unwrap
2022-05-25Miri call ABI check: ensure type size+align stay the sameRalf Jung-1/+8
2022-05-24Remove outdated commentOli Scherer-4/+0
2022-05-24Add the transmute and asm checks to typeck as deferred checksOli Scherer-4/+4
2022-05-24Add flag for stricter checks on uninit/zeroed5225225-3/+11
2022-05-23Refactor call terminator to always hold a destination placeJakob Degen-36/+49
2022-05-22Lifetime variance fixes for rustcMichael Goulet-4/+4
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-8/+8
2022-05-20Ensure we never consider the null pointer dereferencableRalf Jung-0/+4
2022-05-20Rollup merge of #97188 - carbotaniuman:remove-null-assert, r=RalfJungGuillaume Gomez-8/+1
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-20Rollup merge of #97185 - RalfJung:number-validity, r=oli-obkGuillaume Gomez-15/+33
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-19Remove unneeded assertscarbotaniuman-8/+1
2022-05-19fmtRalf Jung-2/+1
2022-05-19interpret/validity: separately control checking numbers for being init and ↵Ralf Jung-15/+34
non-ptr
2022-05-18Auto merge of #97019 - b-naber:transition-to-valtrees-pt1, r=oli-obkbors-7/+13
Transition to valtrees pt1 Compartmentalising https://github.com/rust-lang/rust/pull/96591 as much as possible. r? `@oli-obk`
2022-05-17interpret/validity: reject references to uninhabited typesRalf Jung-6/+11
2022-05-17Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwcobors-2/+2
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-16use GlobalId in eval_to_valtree query and introduce query for ↵b-naber-7/+13
valtree_to_const_val
2022-05-16Add a query for checking whether a function is an intrinsic.Oli Scherer-2/+2
2022-05-14Auto merge of #96883 - jackh726:early-binder-2, r=oli-obkbors-1/+1
Add EarlyBinder Chalk has no concept of `Param` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L579) or `ReEarlyBound` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/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-14Auto merge of #95826 - carbotaniuman:miri-permissive-provenance, r=RalfJungbors-34/+103
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-13Add bound_type_ofJack Huey-5/+4