about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2022-07-01use const instead of function and make it privateTakayuki Maeda-5/+3
2022-06-30Recover when failing to normalize closure signature.Camille GILLOT-1/+2
2022-06-30Don't assert polymorphization has taken effect in const evalWesley Wiser-16/+4
Const eval no longer runs MIR optimizations so unless this is getting run as part of a MIR optimization like const-prop, there can be unused type parameters even if polymorphization is enabled.
2022-06-30Rollup merge of #98688 - RalfJung:from-mplace, r=oli-obkMatthias Krüger-8/+29
interpret: add From<&MplaceTy> for PlaceTy We have a similar instance for `&MPlaceTy` to `OpTy`. Also add the same for `&mut`. This avoids having to write `&(*place).into()`, which we have a few times here and at least twice in Miri (and it comes up again in my current patch). r? ```@oli-obk```
2022-06-30Change enum->int casts to not go through MIR casts.Oli Scherer-27/+30
Instead we generate a discriminant rvalue and cast the result of that.
2022-06-29interpret: add From<&MplaceTy> for PlaceTyRalf Jung-8/+29
2022-06-29Rollup merge of #98643 - voidc:valtree-ref-pretty, r=lcnrMatthias Krüger-79/+0
Improve pretty printing of valtrees for references This implements the changes outlined in https://github.com/rust-lang/rust/issues/66451#issuecomment-1168859638. r? `@lcnr` Fixes #66451
2022-06-29Rollup merge of #98554 - DrMeepster:box_unsizing_is_not_special, r=RalfJungDylan DPC-17/+7
Fix box with custom allocator in miri This should fix the failures in https://github.com/rust-lang/miri/pull/2072 and https://github.com/rust-lang/rust/pull/98510. cc ```@RalfJung```
2022-06-29Rollup merge of #98549 - RalfJung:interpret-stacktraces, r=oli-obkDylan DPC-18/+13
interpret: do not prune requires_caller_location stack frames quite so early https://github.com/rust-lang/rust/pull/87000 made the interpreter skip `caller_location` frames for its stacktraces and `cur_span`. However, those functions are used for much more than just panic reporting, and e.g. when Miri reports UB somewhere, it probably wants to point inside `caller_location` frames. (And if it did not, it would want to have its own logic to decide that, not be forced into it by the core interpreter engine.) This fixes some rare ICEs in Miri that say "we should never pop more than one frame at once". So let's remove all `caller_location` logic from the core interpreter, and instead move it to CTFE error reporting. This does not change user-visible behavior. That's the first commit. We might additionally want to change CTFE error reporting to treat panics differently from other errors: only prune `caller_location` frames for panics. The second commit does that. But honestly I am not sure if this is an improvement. r? ``@oli-obk``
2022-06-29avoid walk when `get_ptr_alloc` returns no `AllocRef`Rémy Rakic-0/+3
2022-06-29fix commentsRémy Rakic-5/+5
2022-06-28fix silly mistakeDrMeepster-1/+1
you should always run x.py check before pushing
2022-06-28Improve pretty printing of valtrees for referencesDominik Stolz-79/+0
2022-06-28const alloc interning: only check for references for arrays/slicesRémy Rakic-14/+18
Checking the size/alignment of an mplace may be costly, so we only do it on the types where the walk we want to avoid could be expensive: the larger types like arrays and slices, rather than on all aggregates being interned.
2022-06-28ctfe: clarify skipping the interning walkRémy Rakic-11/+30
Reorganizes the previous commits to have a single exit-point to avoid doing the potentially costly walk. Also moves the relocations tests before the interior mutability test: only references are important when checking for `UnsafeCell`s and we're checking if there are any to decide to avoid the walk anyways.
2022-06-28make `get_relocations` privateRémy Rakic-1/+1
This limits access to the relocations data a bit (instead of increasing it just for the purposes of interning).
2022-06-28ctfe interning: don't walk allocations that don't need itRémy Rakic-3/+25
The interning of const allocations visits the mplace looking for references to intern. Walking big aggregates like big static arrays can be costly, so we only do it if the allocation we're interning contains references or interior mutability. Walking ZSTs was avoided before, and this optimization is now applied to cases where there are no references/relocations either.
2022-06-28Validate all fields of box instead of validating allocator specificallyDrMeepster-2/+2
2022-06-27make AllocKind actually publicRalf Jung-1/+1
2022-06-26interpret: refactor allocation info queryRalf Jung-51/+34
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-26validate box's allocatorDrMeepster-0/+3
2022-06-26fix box with custom allocator in miriDrMeepster-17/+4
2022-06-26interpret: do not prune requires_caller_location stack frames quite so earlyRalf Jung-18/+13
2022-06-22Rollup merge of #98099 - RalfJung:convert_tag_add_extra, r=oli-obkYuki Okushi-11/+15
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-21Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obkbors-50/+69
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-19Mention formatting macros when encountering ArgumentV1::new in constMichael Goulet-1/+11
2022-06-16interpret: convert_tag_add_extra, init_allocation_extra: allow tagger to ↵Ralf Jung-11/+15
raise errors
2022-06-15make sure miri ices when dereferencing a boxDrMeepster-0/+5
2022-06-15remove box derefs from codgenDrMeepster-50/+64
2022-06-15Rename `impl_constness` to `constness`Deadbeef-7/+8
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-14rebaseb-naber-3/+3
2022-06-14correctly create Scalar for meta infob-naber-3/+7
2022-06-14address reviewb-naber-17/+54
2022-06-14implement valtrees as the type-system representation for constant valuesb-naber-169/+132
2022-06-14Rename the `ConstS::val` field as `kind`.Nicholas Nethercote-9/+10
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-13Rollup merge of #98043 - TaKO8Ki:remove-unnecessary-to-string, r=davidtwcoMatthias Krüger-1/+1
Remove unnecessary `to_string` and `String::new` https://github.com/rust-lang/rust/pull/96468/commits/73fa217bc11fbac76f730223f6766c8e03513b5e changed the type of the `suggestion` argument to `impl ToString`. This patch removes unnecessary `to_string` and `String::new`. cc: `````@davidtwco`````
2022-06-13Rollup merge of #97960 - RalfJung:offset-from, r=oli-obkMatthias Krüger-67/+70
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-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-1/+1
2022-06-11Try out `yeet` in the MIR interpreterScott McMurray-0/+1
2022-06-11Rollup merge of #97761 - RalfJung:vtable-validation, r=cjgillotDylan DPC-0/+8
validating the vtable can lead to Stacked Borrows errors Fixes https://github.com/rust-lang/miri/issues/2123
2022-06-09interpret: unify offset_from check with offset checkRalf Jung-67/+70
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-4/+4
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