about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
2024-07-02Miscellaneous renamingMichael Goulet-3/+2
2024-07-02Miri function identity hack: account for possible inliningRalf Jung-7/+9
2024-07-02chore: remove duplicate wordshattizai-1/+1
2024-06-27Enable const casting for `f16` and `f128`Trevor Gross-10/+17
2024-06-22don't ICE when encountering an extern type field during validationRalf Jung-7/+9
2024-06-21Rollup merge of #126787 - Strophox:get-bytes, r=RalfJungJubilee-0/+17
Add direct accessors for memory addresses in `Machine` (for Miri) The purpose of this PR is to enable direct (immutable) access to memory addresses in `Machine`, which will be needed for further extension of Miri. This is done by adding (/completing missings pairs of) accessor functions, with the relevant signatures as follows: ```rust /* rust/compiler/rustc_middle/src/mir/interpret/allocation.rs */ pub trait AllocBytes { // .. fn as_ptr(&self) -> *const u8; /*fn as_mut_ptr(&mut self) -> *mut u8; -- Already in the compiler*/ } impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes> { // .. pub fn get_bytes_unchecked_raw(&self) -> *const u8; /*pub fn get_bytes_unchecked_raw_mut(&mut self) -> *mut u8; -- Already in the compiler*/ } ``` ```rust /* rust/compiler/rustc_const_eval/src/interpret/memory.rs */ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // .. pub fn get_alloc_bytes_unchecked_raw(&self, id: AllocId) -> InterpResult<'tcx, *const u8>; pub fn get_alloc_bytes_unchecked_raw_mut(&mut self, id: AllocId) -> InterpResult<'tcx, *mut u8>; } ``` r? ``@RalfJung``
2024-06-21Auto merge of #125853 - tesuji:promote-fail-fast, r=cjgillotbors-6/+6
promote_consts: some clean-up after experimenting This is some clean-up after experimenting in #125916, Prefer to review commit-by-commit.
2024-06-21interpret: use trace to reduce noiceLzu Tao-6/+6
2024-06-21add as_ptr to trait AllocBytes, fix 2 impls; add pub fn ↵Strophox-0/+17
get_bytes_unchecked_raw in allocation.rs; add pub fn get_alloc_bytes_unchecked_raw[_mut] in memory.rs
2024-06-20More GVN for PtrMetadataScott McMurray-1/+1
`PtrMetadata` doesn't care about `*const`/`*mut`/`&`/`&mut`, so GVN away those casts in its argument. This includes updating MIR to allow calling PtrMetadata on references too, not just raw pointers. That means that `[T]::len` can be just `_0 = PtrMetadata(_1)`, for example. # Conflicts: # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
2024-06-19`bug!` more uses of these in runtime stuffScott McMurray-3/+1
2024-06-19Rollup merge of #126154 - RalfJung:storage-live, r=compiler-errorsLeón Orell Valerian Liehr-5/+3
StorageLive: refresh storage (instead of UB) when local is already live Blocked on [this FCP](https://github.com/rust-lang/rust/issues/99160#issuecomment-2155924538), which also contains the motivation. Fixes https://github.com/rust-lang/rust/issues/99160 Fixes https://github.com/rust-lang/rust/issues/98896 (by declaring it not-a-bug) Fixes https://github.com/rust-lang/rust/issues/119366 Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/129
2024-06-19Rollup merge of #126493 - jswrenn:fix-126460, r=compiler-errors许杰友 Jieyou Xu (Joe)-1/+10
safe transmute: support non-ZST, variantful, uninhabited enums Previously, `Tree::from_enum`'s implementation branched into three disjoint cases: 1. enums that uninhabited 2. enums for which all but one variant is uninhabited 3. enums with multiple variants This branching (incorrectly) did not differentiate between variantful and variantless uninhabited enums. In both cases, we assumed (and asserted) that uninhabited enums are zero-sized types. This assumption is false for enums like: enum Uninhabited { A(!, u128) } ...which, currently, has the same size as `u128`. This faulty assumption manifested as the ICE reported in #126460. In this PR, we revise the first case of `Tree::from_enum` to consider only the narrow category of "enums that are uninhabited ZSTs". These enums, whose layouts are described with `Variants::Single { index }`, are special in their layouts otherwise resemble the `!` type and cannot be descended into like typical enums. This first case captures uninhabited enums like: enum Uninhabited { A(!, !), B(!) } The second case is revised to consider the broader category of "enums that defer their layout to one of their variants"; i.e., enums whose layouts are described with `Variants::Single { index }` and that do have a variant at `index`. This second case captures uninhabited enums that are not ZSTs, like: enum Uninhabited { A(!, u128) } ...which represent their variants with `Variants::Single`. Finally, the third case is revised to cover the broader category of "enums with multiple variants", which captures uninhabited enums like: enum Uninhabited { A(u8, !), B(!, u32) } ...which represent their variants with `Variants::Multiple`. This PR also adds a comment requested by ````@RalfJung```` in his review of #126358 to `compiler/rustc_const_eval/src/interpret/discriminant.rs`. Fixes #126460 r? ````@compiler-errors````
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-2/+2
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-16Rename InstanceDef -> InstanceKindMichael Goulet-21/+21
2024-06-15Auto merge of #126518 - matthiaskrgr:rollup-wb70rzq, r=matthiaskrgrbors-6/+15
Rollup of 9 pull requests Successful merges: - #125829 (rustc_span: Add conveniences for working with span formats) - #126361 (Unify intrinsics body handling in StableMIR) - #126417 (Add `f16` and `f128` inline ASM support for `x86` and `x86-64`) - #126424 ( Also sort `crt-static` in `--print target-features` output) - #126428 (Polish `std::path::absolute` documentation.) - #126429 (Add `f16` and `f128` const eval for binary and unary operationations) - #126448 (End support for Python 3.8 in tidy) - #126488 (Use `std::path::absolute` in bootstrap) - #126511 (.mailmap: Associate both my work and my private email with me) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-15Rollup merge of #126429 - tgross35:f16-f128-const-eval, r=RalfJungMatthias Krüger-6/+15
Add `f16` and `f128` const eval for binary and unary operationations Add const evaluation and Miri support for f16 and f128, including unary and binary operations. Casts are not yet included. Fixes https://github.com/rust-lang/rust/issues/124583 r? ``@RalfJung``
2024-06-15Rollup merge of #126469 - RalfJung:mir-shifts, r=scottmcmMatthias Krüger-12/+7
MIR Shl/Shr: the offset can be computed with rem_euclid r? ````@scottmcm````
2024-06-14safe transmute: support non-ZST, variantful, uninhabited enumsJack Wrenn-1/+10
Previously, `Tree::from_enum`'s implementation branched into three disjoint cases: 1. enums that uninhabited 2. enums for which all but one variant is uninhabited 3. enums with multiple inhabited variants This branching (incorrectly) did not differentiate between variantful and variantless uninhabited enums. In both cases, we assumed (and asserted) that uninhabited enums are zero-sized types. This assumption is false for enums like: enum Uninhabited { A(!, u128) } ...which, currently, has the same size as `u128`. This faulty assumption manifested as the ICE reported in #126460. In this PR, we revise the first case of `Tree::from_enum` to consider only the narrow category of "enums that are uninhabited ZSTs". These enums, whose layouts are described with `Variants::Single { index }`, are special in their layouts otherwise resemble the `!` type and cannot be descended into like typical enums. This first case captures uninhabited enums like: enum Uninhabited { A(!, !), B(!) } The second case is revised to consider the broader category of "enums that defer their layout to one of their variants"; i.e., enums whose layouts are described with `Variants::Single { index }` and that do have a variant at `index`. This second case captures uninhabited enums that are not ZSTs, like: enum Uninhabited { A(!, u128) } ...which represent their variants with `Variants::Single`. Finally, the third case is revised to cover the broader category of "enums with multiple variants", which captures uninhabited, non-ZST enums like: enum Uninhabited { A(u8, !), B(!, u32) } ...which represent their variants with `Variants::Multiple`. This PR also adds a comment requested by RalfJung in his review of #126358 to `compiler/rustc_const_eval/src/interpret/discriminant.rs`. Fixes #126460
2024-06-14Make the unary operator `FloatTy` check exhaustiveTrevor Gross-6/+9
Add a spot that was missed in <https://github.com/rust-lang/rust/pull/121997>.
2024-06-14Enable const evaluation for `f16` and `f128`Trevor Gross-2/+8
This excludes casting, which needs more tests.
2024-06-14Rollup merge of #126426 - RalfJung:dangling-zst-ice, r=oli-obkMatthias Krüger-5/+11
const validation: fix ICE on dangling ZST reference Fixes https://github.com/rust-lang/rust/issues/126393 I'm not super happy with this fix but I can't think of a better one. r? `@oli-obk`
2024-06-14MIR Shl/Shr: the offset can be computed with rem_euclidRalf Jung-12/+7
2024-06-14const validation: fix ICE on dangling ZST referenceRalf Jung-5/+11
2024-06-13const-eval: make lint scope computation consistentRalf Jung-17/+10
2024-06-13rename CompileTimeInterpreter -> CompileTimeMachine, CompileTimeEvalContext ↵Ralf Jung-4/+4
-> CompileTimeInterpCx to match the terms used in the shared interpreter infrastructure
2024-06-13Rollup merge of #126379 - RalfJung:find_closest_untracked_caller_location, ↵León Orell Valerian Liehr-3/+7
r=oli-obk interpret: update doc comment for find_closest_untracked_caller_location Also add a doc comment to cur_span. r? `@compiler-errors`
2024-06-13interpret: update doc comment for find_closest_untracked_caller_locationRalf Jung-3/+7
2024-06-12Rollup merge of #126358 - jswrenn:fix-125811, r=compiler-errorsJubilee-4/+1
safe transmute: support `Single` enums Previously, the implementation of `Tree::from_enum` incorrectly treated enums with `Variants::Single` and `Variants::Multiple` identically. This is incorrect for `Variants::Single` enums, which delegate their layout to that of a variant with a particular index (or no variant at all if the enum is empty). This flaw manifested first as an ICE. `Tree::from_enum` attempted to compute the tag of variants other than the one at `Variants::Single`'s `index`, and fell afoul of a sanity-checking assertion in `compiler/rustc_const_eval/src/interpret/discriminant.rs`. This assertion is non-load-bearing, and can be removed; the routine its in is well-behaved even without it. With the assertion removed, the proximate issue becomes apparent: calling `Tree::from_variant` on a variant that does not exist is ill-defined. A sanity check the given variant has `FieldShapes::Arbitrary` fails, and the analysis is (correctly) aborted with `Err::NotYetSupported`. This commit corrects this chain of failures by ensuring that `Tree::from_variant` is not called on variants that are, as far as layout is concerned, nonexistent. Specifically, the implementation of `Tree::from_enum` is now partitioned into three cases: 1. enums that are uninhabited 2. enums for which all but one variant is uninhabited 3. enums with multiple inhabited variants `Tree::from_variant` is now only invoked in the third case. In the first case, `Tree::uninhabited()` is produced. In the second case, the layout is delegated to `Variants::Single`'s index. Fixes #125811
2024-06-12Rollup merge of #126328 - RalfJung:is_none_or, r=workingjubileeJubilee-3/+3
Add Option::is_none_or ACP: https://github.com/rust-lang/libs-team/issues/212
2024-06-13safe transmute: support `Variants::Single` enumsJack Wrenn-4/+1
Previously, the implementation of `Tree::from_enum` incorrectly treated enums with `Variants::Single` and `Variants::Multiple` identically. This is incorrect for `Variants::Single` enums, which delegate their layout to that of a variant with a particular index (or no variant at all if the enum is empty). This flaw manifested first as an ICE. `Tree::from_enum` attempted to compute the tag of variants other than the one at `Variants::Single`'s `index`, and fell afoul of a sanity-checking assertion in `compiler/rustc_const_eval/src/interpret/discriminant.rs`. This assertion is non-load-bearing, and can be removed; the routine its in is well-behaved even without it. With the assertion removed, the proximate issue becomes apparent: calling `Tree::from_variant` on a variant that does not exist is ill-defined. A sanity check the given variant has `FieldShapes::Arbitrary` fails, and the analysis is (correctly) aborted with `Err::NotYetSupported`. This commit corrects this chain of failures by ensuring that `Tree::from_variant` is not called on variants that are, as far as layout is concerned, nonexistent. Specifically, the implementation of `Tree::from_enum` is now partitioned into three cases: 1. enums that are uninhabited 2. enums for which all but one variant is uninhabited 3. enums with multiple inhabited variants `Tree::from_variant` is now only invoked in the third case. In the first case, `Tree::uninhabited()` is produced. In the second case, the layout is delegated to `Variants::Single`'s index. Fixes #125811
2024-06-12use is_none_or in some places in the compilerRalf Jung-3/+3
2024-06-12Rollup merge of #126232 - RalfJung:dyn-trait-equality, r=oli-obkGuillaume Gomez-116/+129
interpret: dyn trait metadata check: equate traits in a proper way Hopefully fixes https://github.com/rust-lang/miri/issues/3541... unfortunately we don't have a testcase. The first commit is just a refactor without functional change. r? `@oli-obk`
2024-06-11interpret: ensure we check bool/char for validity when they are used in a castRalf Jung-26/+29
2024-06-11interpret: dyn trait metadata check: equate traits in a proper wayRalf Jung-4/+36
2024-06-11check for correct trait in size_and_align_ofRalf Jung-5/+8
2024-06-10Rollup merge of #126184 - RalfJung:interpret-simd-nonpow2, r=oli-obkMatthias Krüger-6/+9
interpret: do not ICE on padded non-pow2 SIMD vectors Fixes https://github.com/rust-lang/miri/issues/3458 r? ``@oli-obk``
2024-06-10interpret: refactor dyn trait handlingRalf Jung-112/+90
We can check that the vtable is for the right trait very early, and then just pass the type around.
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-25/+23
2024-06-09interpret: do not ICE on padded non-pow2 SIMD vectorsRalf Jung-6/+9
2024-06-08offset_of: allow (unstably) taking the offset of slice tail fieldsRalf Jung-1/+4
2024-06-08StorageLive: refresh storage (instead of UB) when local is already liveRalf Jung-5/+3
2024-06-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-2/+4
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-05Update the interpreter to handle the new casesBen Kimock-9/+22
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-2/+4
2024-06-01Uplift TypeRelation and RelateMichael Goulet-1/+1
2024-05-29Rollup merge of #125633 - RalfJung:miri-no-copy, r=saethlin许杰友 Jieyou Xu (Joe)-24/+50
miri: avoid making a full copy of all new allocations Hopefully fixes https://github.com/rust-lang/miri/issues/3637 r? ``@saethlin``
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-5/+25
2024-05-27miri: avoid making a full copy of all new allocationsRalf Jung-24/+50
2024-05-27interpret: get rid of 'mir lifetime everywhereRalf Jung-191/+162