about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/discriminant.rs
AgeCommit message (Collapse)AuthorLines
2025-06-27Add InterpCx::layout_of with tracing, shadowing LayoutOfStypox-1/+1
2025-06-05Update `InterpCx::project_field` to take `FieldIdx`Scott McMurray-2/+2
As suggested by Ralf in 142005.
2025-06-03Change `tag_field` to `FieldIdx` in `Variants::Multiple`Scott McMurray-4/+4
It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field.
2024-12-18make no-variant types a dedicated Variants variantRalf Jung-2/+6
2024-12-18Variants::Single: do not use invalid VariantIdx for uninhabited enumsRalf Jung-14/+9
2024-12-01fix safe-transmute handling of enumsRalf Jung-1/+1
2024-11-30report UB when the niche value refers to the untagged variantRalf Jung-19/+24
2024-11-03compiler: Directly use rustc_abi in const_evalJubilee Young-1/+1
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-1/+1
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-28compiler: Add `is_uninhabited` and use LayoutS accessorsJubilee Young-3/+3
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-01make InterpResult a dedicated type to avoid accidentally discarding the errorRalf Jung-9/+10
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-09-08interpret: remove Readable trait, we can use Projectable insteadRalf Jung-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-02chore: remove duplicate wordshattizai-1/+1
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-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-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-8/+7
2024-06-01Uplift TypeRelation and RelateMichael Goulet-1/+1
2024-05-27interpret: get rid of 'mir lifetime everywhereRalf Jung-1/+1
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_const_eval`.Nicholas Nethercote-0/+1
2024-05-21interpret: make overflowing binops just normal binopsRalf Jung-6/+2
2024-05-13Remove `extern crate rustc_middle` from `rustc_const_eval`.Nicholas Nethercote-1/+4
This requires exporting the interpreter macros so they can be used with `use crate::interpret::*`.
2024-04-19ScalarInt: add methods to assert being a (u)int of given sizeRalf Jung-2/+1
2024-03-23tag_for_variant follow-upsRalf Jung-3/+5
2024-03-22Add `tag_for_variant` queryJack Wrenn-67/+89
This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. Also moves `DummyMachine` to `rustc_const_eval`.
2024-03-08interpret: update comment about read_discriminant on uninhabited variantsRalf Jung-1/+7
2024-02-10interpret/write_discriminant: when encoding niched variant, ensure the ↵Ralf Jung-0/+8
stored value matches
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-1/+1
2023-11-14Fix some typoscui fliter-2/+2
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-25Evaluate computed values to constants.Camille GILLOT-5/+6
2023-10-20s/generator/coroutine/Oli Scherer-3/+3
2023-10-20s/Generator/Coroutine/Oli Scherer-1/+1
2023-09-21try to avoid some layout_of callsRalf Jung-1/+1
2023-09-20interpret: more consistently use ImmTy in operators and castsRalf Jung-7/+6
2023-09-11Return ImmTy in discriminant_for_variant.Camille GILLOT-3/+4
2023-07-25interpret: make read functions generic over operand typeRalf Jung-18/+13
2023-07-25interpret: make write functions generic over the place typeRalf Jung-6/+11
2023-07-25interpret: read_discriminant: only return VariantIdxRalf Jung-27/+39
2023-07-25interpret: refactor projection code to work on a common trait, and use that ↵Ralf Jung-6/+22
for visitors
2023-07-21Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"David Tolnay-14/+10
This reverts commit 557359f92512ca88b62a602ebda291f17a953002, reversing changes made to 1e6c09a803fd543a98bfbe1624d697a55300a786.
2023-07-21support non-null pointer niches in CTFEMoulins-10/+14
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-5/+3
2023-04-16Various minor Idx-related tweaksScott McMurray-8/+9
Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify.
2023-02-06interpret: move discriminant reading and writing to separate fileRalf Jung-0/+238