about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
2022-03-26interpret: mark a dead match arm as deadRalf Jung-1/+2
2022-03-23Rollup merge of #95221 - RalfJung:check_and_deref_ptr, r=oli-obkMatthias Krüger-15/+5
interpret/memory: simplify check_and_deref_ptr *Finally* I saw a way to make this code simpler. The odd preprocessing in `let ptr_or_addr =` has bothered me since forever, but it actually became unnecessary in the last provenance refactoring. :) This also leads to slightly more explicit error messages as a nice side-effect. :tada: r? `@oli-obk`
2022-03-22interpret/memory: simplify check_and_deref_ptrRalf Jung-15/+5
2022-03-22interpret/validity: improve clarityRalf Jung-3/+2
2022-03-21rename LocalState::Uninitialized to UnallocatedRalf Jung-12/+10
2022-03-20Auto merge of #95071 - RalfJung:arbitrary-self-dyn, r=oli-obkbors-15/+40
Miri: implement arbitrary-self dyn receivers Roughly follows the [codegen logic](https://github.com/rust-lang/rust/blob/851fcc7a54262748b1aa9e16de91453998d896f3/compiler/rustc_codegen_ssa/src/mir/block.rs#L809). Fixes https://github.com/rust-lang/miri/issues/1038 r? `@oli-obk` Cc `@eddyb`
2022-03-18Miri: implement arbitrary-self dyn receiversRalf Jung-15/+40
2022-03-16rustc_error: make ErrorReported impossible to constructmark-5/+9
There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name.
2022-03-12Auto merge of #94733 - nnethercote:fix-AdtDef-interning, r=fee1-deadbors-7/+10
Improve `AdtDef` interning. This commit makes `AdtDef` use `Interned`. Much of the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`. r? `@fee1-dead`
2022-03-11Rollup merge of #94827 - RalfJung:offset-from-ub, r=oli-obkDylan DPC-41/+45
CTFE/Miri: detect out-of-bounds pointers in offset_from Also I became uneasy with aggressively doing `try_to_int` here -- this will always succeed on Miri, leading to the wrong codepath being taken. We should rather try to convert them both to pointers, and use the integer path as a fallback, so that's what I implemented now. Hiding whitespaces helps with the diff. Fixes https://github.com/rust-lang/miri/issues/1950 r? ``@oli-obk``
2022-03-11Improve `AdtDef` interning.Nicholas Nethercote-7/+10
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
2022-03-10adjust offset_from logic: check that both pointers are in-boundsRalf Jung-41/+45
2022-03-09normalization change and rebaseb-naber-1/+12
2022-03-07Rollup merge of #94685 - RalfJung:saturating, r=oli-obkMatthias Krüger-39/+45
interpret: move saturating_add/sub into (pub) helper method I plan to use them for `simd_saturating_add/sub`. The first commit just moves code, the 2nd simplifies it a bit with some helper methods that did not exist yet when the code was originally written.
2022-03-07Rollup merge of #94681 - RalfJung:miri-cast, r=oli-obkMatthias Krüger-8/+13
CTFE engine: expose misc_cast to Miri We need that to implement `simd_cast`/`simd_as` in Miri. While at it, also change other code outside `cast.rs` to use `misc_cast` instead of lower-level methods. r? `@oli-obk`
2022-03-06use singed_int_max/min helper methodsRalf Jung-7/+4
2022-03-06move saturating_add/sub into (pub) helper methodRalf Jung-39/+48
2022-03-06Auto merge of #94597 - nnethercote:ConstAllocation, r=fee1-deadbors-13/+17
Introduce `ConstAllocation`. Currently some `Allocation`s are interned, some are not, and it's very hard to tell at a use point which is which. This commit introduces `ConstAllocation` for the known-interned ones, which makes the division much clearer. `ConstAllocation::inner()` is used to get the underlying `Allocation`. In some places it's natural to use an `Allocation`, in some it's natural to use a `ConstAllocation`, and in some places there's no clear choice. I've tried to make things look as nice as possible, while generally favouring `ConstAllocation`, which is the type that embodies more information. This does require quite a few calls to `inner()`. The commit also tweaks how `PartialOrd` works for `Interned`. The previous code was too clever by half, building on `T: Ord` to make the code shorter. That caused problems with deriving `PartialOrd` and `Ord` for `ConstAllocation`, so I changed it to build on `T: PartialOrd`, which is slightly more verbose but much more standard and avoided the problems. r? `@fee1-dead`
2022-03-07Introduce `ConstAllocation`.Nicholas Nethercote-13/+17
Currently some `Allocation`s are interned, some are not, and it's very hard to tell at a use point which is which. This commit introduces `ConstAllocation` for the known-interned ones, which makes the division much clearer. `ConstAllocation::inner()` is used to get the underlying `Allocation`. In some places it's natural to use an `Allocation`, in some it's natural to use a `ConstAllocation`, and in some places there's no clear choice. I've tried to make things look as nice as possible, while generally favouring `ConstAllocation`, which is the type that embodies more information. This does require quite a few calls to `inner()`. The commit also tweaks how `PartialOrd` works for `Interned`. The previous code was too clever by half, building on `T: Ord` to make the code shorter. That caused problems with deriving `PartialOrd` and `Ord` for `ConstAllocation`, so I changed it to build on `T: PartialOrd`, which is slightly more verbose but much more standard and avoided the problems.
2022-03-06CTFE engine: expose misc_cast to MiriRalf Jung-8/+13
2022-03-06explain why shift with signed offset works the way it doesRalf Jung-3/+15
2022-03-04Rollup merge of #94575 - RalfJung:switchint-comment, r=oli-obkDylan DPC-1/+2
CTFE SwitchInt: update comment I just wondered why this doesn't use `binary_op`. r? ```@oli-obk```
2022-03-03CTFE SwitchInt: update commentRalf Jung-1/+2
2022-03-03Rollup merge of #94555 - cuishuang:master, r=oli-obkMatthias Krüger-1/+1
all: fix some typos Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-03Auto merge of #94512 - RalfJung:sdiv-ub, r=oli-obkbors-16/+14
Miri/CTFE: properly treat overflow in (signed) division/rem as UB To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine. r? `@oli-obk`
2022-03-03all: fix some typoscuishuang-1/+1
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-5/+5
2022-03-01Miri/CTFE: properly treat overflow in (signed) division/rem as UBRalf Jung-16/+14
2022-02-25Rollup merge of #94343 - RalfJung:fn-ptr, r=oli-obkMatthias Krüger-28/+38
Miri fn ptr check: don't use conservative null check In https://github.com/rust-lang/rust/pull/94270 I used the wrong NULL check for function pointers: `memory.ptr_may_be_null` is conservative even on machines that support ptr-to-int casts, leading to false errors in Miri. This fixes that problem, and also replaces that foot-fun of a method with `scalar_may_be_null` which is never unnecessarily conservative. r? `@oli-obk`
2022-02-24Miri fn ptr check: don't use conservative null checkRalf Jung-28/+38
2022-02-24Auto merge of #94131 - Mark-Simulacrum:fmt-string, r=oli-obkbors-5/+5
Always format to internal String in FmtPrinter This avoids monomorphizing for different parameters, decreasing generic code instantiated downstream from rustc_middle -- locally seeing 7% unoptimized LLVM IR line wins on rustc_borrowck, for example. We likely can't/shouldn't get rid of the Result-ness on most functions, though some further cleanup avoiding fmt::Error where we now know it won't occur may be possible, though somewhat painful -- fmt::Write is a pretty annoying API to work with in practice when you're trying to use it infallibly.
2022-02-24Rollup merge of #94270 - RalfJung:fn-ptrs, r=oli-obkMatthias Krüger-13/+18
Miri: relax fn ptr check As discussed in https://github.com/rust-lang/unsafe-code-guidelines/issues/72#issuecomment-1025407536, the function pointer check done by Miri is currently overeager: contrary to our usual principle of only checking rather uncontroversial validity invariants, we actually check that the pointer points to a real function. So, this relaxes the check to what the validity invariant probably will be (and what the reference already says it is): the function pointer must be non-null, and that's it. The check that CTFE does on the final value of a constant is unchanged -- CTFE recurses through references, so it makes some sense to also recurse through function pointers. We might still want to relax this in the future, but that would be a separate change. r? `@oli-obk`
2022-02-23Miri: relax fn ptr checkRalf Jung-13/+18
2022-02-23Rollup merge of #94280 - tmiasko:should-print-region, r=oli-obkMatthias Krüger-1/+1
Rename `region_should_not_be_omitted` to `should_print_region` to avoid double negation
2022-02-23Rename `region_should_not_be_omitted` to `should_print_region`Tomasz Miąsko-1/+1
to avoid double negation
2022-02-22Miri: extend comments on downcast operationRalf Jung-2/+6
2022-02-21ScalarMaybeUninit is explicitly hexadecimal in its formattingRalf Jung-7/+7
2022-02-21Rollup merge of #94189 - GuillaumeGomez:scalar-lower-hex, r=RalfJungMatthias Krüger-1/+1
Implement LowerHex on Scalar to clean up their display in rustdoc Follow-up of https://github.com/rust-lang/rust/pull/94091. r? ````@RalfJung````
2022-02-21Rollup merge of #94143 - est31:let_else_const_eval, r=lcnrMatthias Krüger-91/+67
rustc_const_eval: adopt let else in more places Continuation of #89933, #91018, #91481, #93046, #93590, #94011. I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This PR handles rustc_const_eval.
2022-02-21Fix typoest31-1/+1
Co-authored-by: lcnr <rust@lcnr.de>
2022-02-20Always format to internal String in FmtPrinterMark Rousskov-5/+5
This avoids monomorphizing for different parameters, decreasing generic code instantiated downstream from rustc_middle.
2022-02-20Implement LowerHex on Scalar to clean up their display in rustdocGuillaume Gomez-1/+1
2022-02-19rustc_const_eval: adopt let else in more placesest31-91/+67
2022-02-16Move ty::print methods to Drop-based scope guardsMark Rousskov-1/+1
2022-02-15Overhaul `Const`.Nicholas Nethercote-8/+8
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
2022-02-15Overhaul `TyS` and `Ty`.Nicholas Nethercote-6/+6
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
2022-02-11use body.tainted_by_error to skip loading MIRMichael Goulet-17/+9
2022-02-11rework borrowck errors so that it's harder to not set taintedMichael Goulet-2/+4
2022-02-11skip const eval if we have an error in borrowckMichael Goulet-1/+5
2022-01-20update commentslcnr-1/+5