about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
2024-02-24Change InlineAsm to allow multiple targets insteadGary Guo-16/+11
2024-02-23compiler: clippy::complexity fixesMatthias Krüger-2/+2
2024-02-23interpret: do no ICE on OOB shuffle/insert/extract indicesRalf Jung-8/+12
2024-02-22Overhaul `Diagnostic` args.Nicholas Nethercote-3/+3
First, introduce a typedef `DiagnosticArgMap`. Second, make the `args` field public, and remove the `args` getter and `replace_args` setter. These were necessary previously because the getter had a `#[allow(rustc::potential_query_instability)]` attribute, but that was removed in #120931 when the args were changed from `FxHashMap` to `FxIndexMap`. (All the other `Diagnostic` fields are public.)
2024-02-21Rollup merge of #121396 - RalfJung:mir-const-value-inspect, r=oli-obkLeón Orell Valerian Liehr-12/+35
make it possible for outside crates to inspect a mir::ConstValue with the interpreter For MiniRust we need to convert MIR constant values into MiniRust constant values. However, it's not currently possible to get nice high-level access to the inerts of a `ConstValue`: we can access the raw contents (the allocation / `ScalarInt`), but if it is e.g. of enum type and we want to determine which variant is encoded, we are stuck. There's only `try_destructure_mir_constant_for_user_output` which is meant for diagnostics, so it doesn't fit. The interpreter has all the APIs to traverse such a value, so we just need a way to get such a ConstValue into an interpreter instance. This adds the public functions necessary to make that happen.
2024-02-21make it possible for outside crates to inspect a mir::ConstValue with the ↵Ralf Jung-12/+35
interpreter
2024-02-21Convert `bug`s back to `delayed_bug`s.Nicholas Nethercote-1/+1
This commit undoes some of the previous commit's mechanical changes, based on human judgment.
2024-02-21Convert `delayed_bug`s to `bug`s.Nicholas Nethercote-10/+4
I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. The next commit will convert some more back, based on human judgment.
2024-02-20Auto merge of #120576 - nnethercote:merge-Diagnostic-DiagnosticBuilder, ↵bors-0/+7
r=davidtwco Overhaul `Diagnostic` and `DiagnosticBuilder` Implements the first part of https://github.com/rust-lang/compiler-team/issues/722, which moves functionality and use away from `Diagnostic`, onto `DiagnosticBuilder`. Likely follow-ups: - Move things around, because this PR was written to minimize diff size, so some things end up in sub-optimal places. E.g. `DiagnosticBuilder` has impls in both `diagnostic.rs` and `diagnostic_builder.rs`. - Rename `Diagnostic` as `DiagInner` and `DiagnosticBuilder` as `Diag`. r? `@davidtwco`
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-0/+7
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-19Always evaluate free constants and statics, even if previous errors occurredOli Scherer-1/+1
2024-02-17Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercoteMatthias Krüger-1/+1
errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). r? ```@nnethercote```
2024-02-17const_mut_refs: allow mutable refs to staticsRalf Jung-4/+57
2024-02-16Rollup merge of #121179 - RalfJung:zst-mutable-refs, r=oli-obkGuillaume Gomez-58/+53
allow mutable references in const values when they point to no memory Fixes https://github.com/rust-lang/rust/issues/120450 The second commit is just some drive-by test suite cleanup. r? `@oli-obk`
2024-02-16Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkinbors-3/+3
Implement intrinsics with fallback bodies fixes #93145 (though we can port many more intrinsics) cc #63585 The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for * codegen_ssa (so llvm and gcc) * codegen_cranelift other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body). cc `@scottmcm` `@WaffleLapkin` ### todo * [ ] miri support * [x] default intrinsic name to name of function instead of requiring it to be specified in attribute * [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16allow mutable references in const values when they point to no memoryRalf Jung-58/+53
2024-02-16Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnaybors-4/+5
Use generic `NonZero` internally. Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-15Auto merge of #120931 - chenyukang:yukang-cleanup-hashmap, r=michaelwoeristerbors-5/+5
Clean up potential_query_instability with FxIndexMap and UnordMap From https://github.com/rust-lang/rust/pull/120485#issuecomment-1916437191 r? `@michaelwoerister`
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-1/+1
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
2024-02-15Auto merge of #116564 - oli-obk:evaluated_static_in_metadata, ↵bors-64/+248
r=RalfJung,cjgillot Store static initializers in metadata instead of the MIR of statics. This means that adding generic statics would be even more difficult, as we can't evaluate statics from other crates anymore, but the subtle issue I have encountered make me think that having this be an explicit problem is better. The issue is that ```rust static mut FOO: &mut u32 = &mut 42; static mut BAR = unsafe { FOO }; ``` gets different allocations, instead of referring to the same one. This is also true for non-static mut, but promotion makes `static FOO: &u32 = &42;` annoying to demo. Fixes https://github.com/rust-lang/rust/issues/61345 ## Why is this being done? In order to ensure all crates see the same nested allocations (which is the last issue that needs fixing before we can stabilize [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349)), I am working on creating anonymous (from the Rust side, to LLVM it's like a regular static item) static items for the nested allocations in a static. If we evaluate the static item in a downstream crate again, we will end up duplicating its nested allocations (and in some cases, like the `match` case, even duplicate the main allocation).
2024-02-15Do not allocate a second "background" alloc id for the main allocation of a ↵Oli Scherer-52/+192
static. Instead we re-use the static's alloc id within the interpreter for its initializer to refer to the `Allocation` that only exists within the interpreter.
2024-02-15Return ConstAllocation from eval_static_initializer query directlyOli Scherer-7/+27
2024-02-15Store static initializers in metadata instead of the MIR of statics.Oli Scherer-2/+2
2024-02-15Add new query just for static initializersOli Scherer-0/+7
2024-02-15Split a bool argument into two named functionsOli Scherer-18/+35
2024-02-15Use generic `NonZero` internally.Markus Reiter-4/+5
2024-02-15Enforce coroutine-closure layouts are identicalMichael Goulet-0/+20
2024-02-14clean up potential_query_instability with FxIndexMap and UnordMapyukang-5/+5
2024-02-14Use fewer delayed bugs.Nicholas Nethercote-12/+8
For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites.
2024-02-13Bump `indexmap`clubby789-2/+4
`swap` has been deprecated in favour of `swap_remove` - the behaviour is the same though.
2024-02-13Rollup merge of #120959 - nnethercote:rm-good_path, r=oli-obkMatthias Krüger-2/+2
Remove good path delayed bugs Because they're not that useful, and kind of annoying. Details in the individual commits. r? ```@compiler-errors```
2024-02-13Remove `good_path_delayed_bug`.Nicholas Nethercote-2/+2
It's only has a single remaining purpose: to ensure that a diagnostic is printed when `trimmed_def_paths` is used. It's an annoying mechanism: weak, with odd semantics, badly named, and gets in the way of other changes. This commit replaces it with a simpler `must_produce_diag` mechanism, getting rid of a diagnostic `Level` along the way.
2024-02-12Rollup merge of #120958 - ShoyuVanilla:remove-subst, r=oli-obkMatthias Krüger-26/+32
Dejargonize `subst` In favor of #110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2024-02-12Rollup merge of #120950 - compiler-errors:miri-async-closurs, r=RalfJung,oli-obkMatthias Krüger-3/+4
Fix async closures in CTFE First commit renames `is_coroutine_or_closure` into `is_closure_like`, because `is_coroutine_or_closure_or_coroutine_closure` seems confusing and long. Second commit fixes some forgotten cases where we want to handle `TyKind::CoroutineClosure` the same as closures and coroutines. The test exercises the change to `ValidityVisitor::aggregate_field_path_elem` which is the source of #120946, but not the change to `UsedParamsNeedSubstVisitor`, though I feel like it's not that big of a deal. Let me know if you'd like for me to look into constructing a test for the latter, though I have no idea what it'd look like (we can't assert against `TooGeneric` anywhere?). Fixes #120946 r? oli-obk cc ``@RalfJung``
2024-02-12Rollup merge of #120933 - RalfJung:const-check-misc, r=oli-obkMatthias Krüger-10/+12
check_consts: fix duplicate errors, make importance consistent This is stuff I noticed while working on https://github.com/rust-lang/rust/pull/120932, but it's orthogonal to that PR. r? ``@oli-obk``
2024-02-12Rollup merge of #120917 - chenyukang:yukang-dead-parameters, r=compiler-errorsMatthias Krüger-5/+3
Remove a bunch of dead parameters in functions Found this kind of issue when working on https://github.com/rust-lang/rust/pull/119650 I wrote a trivial toy lint and manual review to find these.
2024-02-12Rollup merge of #120833 - ↵Matthias Krüger-76/+62
nnethercote:more-internal-emit_diagnostics-cleanups, r=oli-obk More internal emit diagnostics cleanups Miscellaneous improvements. r? ``@oli-obk``
2024-02-12Make `is_intrinsic` query return the intrinsic nameOli Scherer-3/+3
2024-02-12fix cycle error when a static and a promoted are mutually recursiveRalf Jung-24/+17
This also now allows promoteds everywhere to point to 'extern static', because why not? We still check that constants cannot transitively reach 'extern static' through references. (We allow it through raw pointers.)
2024-02-12Remove `dcx` arg from `ReportErrorExt::add_args`.Nicholas Nethercote-76/+62
Because it also has a `DiagnosticBuilder` arg, which contains a `dcx` reference. Also rename some `builder` variables as `diag`, because that's the usual name.
2024-02-12Dejargnonize substShoyu Vanilla-26/+32
2024-02-12remove a bunch of dead parameters in fnyukang-5/+3
2024-02-11Rollup merge of #120885 - RalfJung:normal-visitor, r=compiler-errorsMatthias Krüger-0/+12
interpret/visitor: ensure we only see normalized types [Prior discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Normalization.20after.20field.20projection) r? `@compiler-errors`
2024-02-11Rollup merge of #120872 - petrochenkov:opthirpar, r=cjgillotMatthias Krüger-4/+3
hir: Refactor getters for HIR parents See individual commits. I ended up removing on of the FIXMEs from https://github.com/rust-lang/rust/pull/120206 instead of addressing it.
2024-02-11Fix async closures in CTFEMichael Goulet-2/+3
2024-02-11is_closure_likeMichael Goulet-1/+1
2024-02-11Auto merge of #120903 - matthiaskrgr:rollup-tmsuzth, r=matthiaskrgrbors-5/+23
Rollup of 9 pull requests Successful merges: - #119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - #120272 (Suppress suggestions in derive macro) - #120773 (large_assignments: Allow moves into functions) - #120874 (Take empty `where` bounds into account when suggesting predicates) - #120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - #120883 (interpret: rename ReadExternStatic → ExternStatic) - #120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - #120895 (don't skip coercions for types with errors) - #120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-11make Primary/Secondary importance consistent between CellBorrow and MutBorrowRalf Jung-7/+7
2024-02-11check_consts: fix some duplicate errors by not calling check_static ↵Ralf Jung-3/+5
unnecessarily
2024-02-11Auto merge of #120405 - cjgillot:gvn-pointer, r=oli-obkbors-1/+1
Fold pointer operations in GVN This PR proposes 2 combinations of cast operations in MIR GVN: - a chain of `PtrToPtr` or `MutToConstPointer` casts can be folded together into a single `PtrToPtr` cast; - we attempt to evaluate more ptr ops when there is no provenance. In particular, this allows to read from static slices. This is not yet sufficient to see through slice operations that use `PtrComponents` (because that's a union), but still a step forward. r? `@ghost`