about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2024-07-03Auto merge of #125507 - compiler-errors:type-length-limit, r=lcnrbors-5/+6
Re-implement a type-size based limit r? lcnr This PR reintroduces the type length limit added in #37789, which was accidentally made practically useless by the caching changes to `Ty::walk` in #72412, which caused the `walk` function to no longer walk over identical elements. Hitting this length limit is not fatal unless we are in codegen -- so it shouldn't affect passes like the mir inliner which creates potentially very large types (which we observed, for example, when the new trait solver compiles `itertools` in `--release` mode). This also increases the type length limit from `1048576 == 2 ** 20` to `2 ** 24`, which covers all of the code that can be reached with craterbot-check. Individual crates can increase the length limit further if desired. Perf regression is mild and I think we should accept it -- reinstating this limit is important for the new trait solver and to make sure we don't accidentally hit more type-size related regressions in the future. Fixes #125460
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-2/+2
2024-07-02Fix spansMichael Goulet-1/+2
2024-07-02Give Instance::expect_resolve a spanMichael Goulet-0/+1
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-29Auto merge of #120639 - fee1-dead-contrib:new-effects-desugaring, r=oli-obkbors-4/+1
Implement new effects desugaring cc `@rust-lang/project-const-traits.` Will write down notes once I have finished. * [x] See if we want `T: Tr` to desugar into `T: Tr, T::Effects: Compat<true>` * [x] Fix ICEs on `type Assoc: ~const Tr` and `type Assoc<T: ~const Tr>` * [ ] add types and traits to minicore test * [ ] update rustc-dev-guide Fixes #119717 Fixes #123664 Fixes #124857 Fixes #126148
2024-06-28implement new effects desugaringDeadbeef-4/+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-41/+59
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-18Remove redundant argument from `subdiagnostic` methodOli Scherer-1/+1
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-6/+6
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-17Rollup merge of #126567 - compiler-errors:instance-kind, r=oli-obk,lcnrMatthias Krüger-28/+28
Rename `InstanceDef` -> `InstanceKind` Renames `InstanceDef` to `InstanceKind`. The `Def` here is confusing, and makes it hard to distinguish `Instance` and `InstanceDef`. `InstanceKind` makes this more obvious, since it's really just describing what *kind* of instance we have. Not sure if this is large enough to warrant a types team MCP -- it's only 53 files. I don't personally think it does, but happy to write one if anyone disagrees. cc ``@rust-lang/types`` r? types
2024-06-17Remove an unused validation error variantOli Scherer-4/+0
2024-06-16Rename InstanceDef -> InstanceKindMichael Goulet-28/+28
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-14Use is_lang_item more aggressivelyMichael Goulet-7/+7
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-30/+25
2024-06-13rename CompileTimeInterpreter -> CompileTimeMachine, CompileTimeEvalContext ↵Ralf Jung-35/+35
-> 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/+4
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/+4
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-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-3/+5
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
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-29/+27