about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/interpret
AgeCommit message (Collapse)AuthorLines
2022-03-17Rollup merge of #94960 - codehorseman:master, r=oli-obkDylan DPC-1/+1
Fix many spelling mistakes Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-16rustc_error: make ErrorReported impossible to constructmark-2/+2
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-16resolve the conflict in compiler/rustc_session/src/parse.rscodehorseman-1/+1
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-15Support other types of pluralization in pluralize macroest31-1/+1
2022-03-10adjust offset_from logic: check that both pointers are in-boundsRalf Jung-0/+6
2022-03-07Introduce `ConstAllocation`.Nicholas Nethercote-18/+50
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-03Auto merge of #94512 - RalfJung:sdiv-ub, r=oli-obkbors-0/+6
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-02rename ErrorReported -> ErrorGuaranteedmark-10/+10
2022-03-01Miri/CTFE: properly treat overflow in (signed) division/rem as UBRalf Jung-0/+6
2022-02-25Auto merge of #94130 - erikdesjardins:partially, r=nikicbors-0/+1
Use undef for (some) partially-uninit constants There needs to be some limit to avoid perf regressions on large arrays with undef in each element (see comment in the code). Fixes: #84565 Original PR: #83698 Depends on LLVM 14: #93577
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-1/+4
2022-02-21ScalarMaybeUninit is explicitly hexadecimal in its formattingRalf Jung-1/+1
2022-02-21Rollup merge of #94203 - RalfJung:to_sized_int, r=oli-obkMatthias Krüger-21/+25
CTFE engine: Scalar: expose size-generic to_(u)int methods This matches the size-generic constructors `Scalar::from_(u)int`, and it would have helped in https://github.com/rust-lang/miri/pull/1978. r? `@oli-obk`
2022-02-21Rollup merge of #94189 - GuillaumeGomez:scalar-lower-hex, r=RalfJungMatthias Krüger-8/+12
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-20CTFE engine: Scalar: expose size-generic to_(u)int methodsRalf Jung-21/+25
2022-02-20Auto merge of #94062 - Mark-Simulacrum:drop-print-cfg, r=oli-obkbors-1/+1
Move ty::print methods to Drop-based scope guards Primary goal is reducing codegen of the TLS access for each closure, which shaves ~3 seconds of bootstrap time over rustc as a whole.
2022-02-20Implement LowerHex on Scalar to clean up their display in rustdocGuillaume Gomez-8/+12
2022-02-20Rollup merge of #94091 - GuillaumeGomez:rustdoc-const-computed-value, r=oli-obkMatthias Krüger-0/+5
Fix rustdoc const computed value Fixes #85088. It looks like this now (instead of hexadecimal): ![Screenshot from 2022-02-17 17-55-39](https://user-images.githubusercontent.com/3050060/154532115-0f9861a0-406f-4c9c-957f-32bedd8aca7d.png) r? ````@oli-obk````
2022-02-19Don't render Const computed values in hexadecimal for DisplayGuillaume Gomez-0/+5
2022-02-19switch to limiting the number of init/uninit chunksErik Desjardins-0/+1
2022-02-16Move ty::print methods to Drop-based scope guardsMark Rousskov-1/+1
2022-02-16Support pretty printing of invalid constantsTomasz Miąsko-0/+8
Make it possible to pretty print invalid constants by introducing a fallible variant of `destructure_const` and falling back to debug formatting when it fails.
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-15/+15
`Decoder` has two impls: - opaque: this impl is already partly infallible, i.e. in some places it currently panics on failure (e.g. if the input is too short, or on a bad `Result` discriminant), and in some places it returns an error (e.g. on a bad `Option` discriminant). The number of places where either happens is surprisingly small, just because the binary representation has very little redundancy and a lot of input reading can occur even on malformed data. - json: this impl is fully fallible, but it's only used (a) for the `.rlink` file production, and there's a `FIXME` comment suggesting it should change to a binary format, and (b) in a few tests in non-fundamental ways. Indeed #85993 is open to remove it entirely. And the top-level places in the compiler that call into decoding just abort on error anyway. So the fallibility is providing little value, and getting rid of it leads to some non-trivial performance improvements. Much of this commit is pretty boring and mechanical. Some notes about a few interesting parts: - The commit removes `Decoder::{Error,error}`. - `InternIteratorElement::intern_with`: the impl for `T` now has the same optimization for small counts that the impl for `Result<T, E>` has, because it's now much hotter. - Decodable impls for SmallVec, LinkedList, VecDeque now all use `collect`, which is nice; the one for `Vec` uses unsafe code, because that gave better perf on some benchmarks.
2022-01-15initial revertEllen-1/+1
2021-12-20better name for AdjustForForeignAbiError error variant in InterpErrorRalf Jung-4/+5
2021-12-20CTFE eval_fn_call: use FnAbi to determine argument skipping and compatibilityRalf Jung-1/+5
2021-12-15Remove `in_band_lifetimes` from `rustc_middle`Aaron Hill-4/+4
See #91867 This was mostly straightforward. In several places, I take advantage of the fact that lifetimes are non-hygenic: a macro declares the 'tcx' lifetime, which is then used in types passed in as macro arguments.
2021-12-12Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"Deadbeef-0/+2
This reverts commit ff2439b7b9bafcfdff86b7847128014699df8442, reversing changes made to 2a9e0831d6603d87220cedd1b1293e2eb82ef55c.
2021-12-03Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"Santiago Pastorino-2/+0
This reverts commit 18bb8c61a975fff6424cda831ace5b0404277145, reversing changes made to d9baa361902b172be716f96619b909f340802dea.
2021-12-02Auto merge of #91354 - fee1-dead:const_env, r=spastorinobors-0/+2
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-12-01remove static_assert_size on InterpErrorb-naber-3/+0
2021-12-01implement version of normalize_erasing_regions that doesn't assume value is ↵b-naber-1/+1
normalizable
2021-11-29Always use const param envs for const eval.Oli Scherer-0/+2
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-06use matches!() macro in more placesMatthias Krüger-5/+5
2021-10-16clippy::complexity changesMatthias Krüger-3/+3
2021-10-14add dedicated error variant for writing the discriminant of an uninhabited ↵Ralf Jung-0/+5
enum variant
2021-09-11interpreter PointerArithmetic: use new Size helper methodsRalf Jung-8/+6
2021-08-26Auto merge of #87280 - lcnr:lazy-anon-const-default-substs, r=nikomatsakisbors-1/+1
lazily "compute" anon const default substs Continuing the work of #83086, this implements the discussed solution for the [unused substs problem](https://github.com/rust-lang/project-const-generics/blob/master/design-docs/anon-const-substs.md#unused-substs). As of now, anonymous constants inherit all of their parents generics, even if they do not use them, e.g. in `fn foo<T, const N: usize>() -> [T; N + 1]`, the array length has `T` as a generic parameter even though it doesn't use it. These *unused substs* cause some backwards incompatible, and imo incorrect behavior, e.g. #78369. --- We do not actually filter any generic parameters here and the `default_anon_const_substs` query still a dummy which only checks that - we now prevent the previously existing query cycles and are able to call `predicates_of(parent)` when computing the substs of anonymous constants - the default anon consts substs only include the typeflags we assume it does. Implementing that filtering will be left as future work. --- The idea of this PR is to delay the creation of the anon const substs until after we've computed `predicates_of` for the parent of the anon const. As the predicates of the parent can however contain the anon const we still have to create a `ty::Const` for it. We do this by changing the substs field of `ty::Unevaluated` to an option and modifying accesses to instead call the method `unevaluated.substs(tcx)` which returns the substs as before. If the substs - now `substs_` - of `ty::Unevaluated` are `None`, it means that the anon const currently has its default substs, i.e. the substs it has when first constructed, which are the generic parameters it has available. To be able to call `unevaluated.substs(tcx)` in a `TypeVisitor`, we add the non-defaulted method `fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>>`. In case `tcx_for_anon_const_substs` returns `None`, unknown anon const default substs are skipped entirely. Even when `substs_` is `None` we still have to treat the constant as if it has its default substs. To do this, `TypeFlags` are modified so that it is clear whether they can still change when *exposing* any anon const default substs. A new flag, `HAS_UNKNOWN_DEFAULT_CONST_SUBSTS`, is added in case some default flags are missing. The rest of this PR are some smaller changes to either not cause cycles by trying to access the default anon const substs too early or to be able to access the `tcx` in previously unused locations. cc `@rust-lang/project-const-generics` r? `@nikomatsakis`
2021-08-26make unevaluated const substs optionallcnr-1/+1
2021-08-25use a peekable iterator to check the first chunkErik Desjardins-3/+14
2021-08-25yet more comment improvementsErik Desjardins-2/+7
2021-08-25improve commentsErik Desjardins-9/+14
2021-08-25put code in a more logical orderErik Desjardins-345/+350
2021-08-25add commentsErik Desjardins-19/+119
2021-08-25implement InitMaskCompressed using InitChunkIter, cleanupErik Desjardins-23/+33
2021-08-25optimize initialization checksErik Desjardins-9/+102
2021-08-25use undef for uninitialized bytes in constantsErik Desjardins-6/+55
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-5/+5
same search
2021-08-22Fix typos “a”→“an”Frank Steffahn-3/+3
2021-08-05replace Vec<u8> with Box<[u8]>The8472-5/+4