about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2023-08-02Auto merge of #114333 - RalfJung:dangling-ptr-offset, r=oli-obkbors-25/+32
Miri: fix error on dangling pointer inbounds offset We used to claim that the pointer was "dereferenced", but that is just not true. Can be reviewed commit-by-commit. The first commit is an unrelated rename that didn't seem worth splitting into its own PR. r? `@oli-obk`
2023-08-01Use upvar_tys in more places, make it a listMichael Goulet-2/+3
2023-08-01properly track why we checked whether a pointer is in-boundsRalf Jung-13/+21
also simplify the in-bounds checking in Miri's borrow trackers
2023-08-01rename deref_operand → deref_pointer and some Miri helper functionsRalf Jung-12/+11
2023-07-31fix alignment handling for Repeat expressionsRalf Jung-4/+4
2023-07-29Rollup merge of #113773 - compiler-errors:err-layout-bail, r=cjgillotMatthias Krüger-1/+4
Don't attempt to compute layout of type referencing error Leads to more ICEs and strange diagnostics than are worth it. Fixes #113760
2023-07-28Auto merge of #114134 - fee1-dead-contrib:rm-constness-from-param-env, r=oli-obkbors-30/+38
Remove `constness` from `ParamEnv` This should be replaced by keyword generics/effects. cc #110395 r? `@oli-obk`
2023-07-27Dont report CTFE errors that are due to references-error layoutsMichael Goulet-1/+4
2023-07-27bless clippyDeadbeef-5/+8
2023-07-27Remove `constness` from `ParamEnv`Deadbeef-25/+30
2023-07-27Rollup merge of #114123 - oli-obk:tait_wtf, r=WaffleLapkinGuillaume Gomez-6/+9
Turns out opaque types can have hidden types registered during mir validation See the newly added test's documentation for an explanation. fixes #114121
2023-07-27Turns out opaque types can have hidden types registered during mir validationOli Scherer-6/+9
2023-07-27Rollup merge of #114075 - matthiaskrgr:fmt_args_rustc_3, r=wesleywiserMatthias Krüger-69/+52
inline format!() args from rustc_codegen_llvm to the end (4) r? `@WaffleLapkin`
2023-07-26Auto merge of #114071 - RalfJung:interpret-generic-read-write, r=oli-obkbors-244/+276
interpret: make read/write methods generic Instead of always having to call `into()` to convert things to `PlaceTy`/`OpTy`, make the relevant methods generic. This also means that when we read from an `MPlaceTy`, we avoid creating an intermediate `PlaceTy`. This makes it feasible to remove the `Copy` from `MPlaceTy`. All the other `*Ty` interpreter types already had their `Copy` removed a while ago so this is only consistent. (And in fact we had one function that accidentally took `MPlaceTy` instead of `&MPlaceTy`.)
2023-07-26valtree: a bit of cleanupRalf Jung-15/+15
2023-07-25Rollup merge of #113661 - oli-obk:tait_wtf, r=lcnrMatthias Krüger-3/+8
Double check that hidden types match the expected hidden type Fixes https://github.com/rust-lang/rust/issues/113278 specifically, but I left a TODO for where we should also add some hardening. It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands. r? `@compiler-errors` `@lcnr`
2023-07-25inline format!() args from rustc_codegen_llvm to the end (4)Matthias Krüger-69/+52
r? @WaffleLapkin
2023-07-25make MPlaceTy non-CopyRalf Jung-16/+16
2023-07-25interpret: make read functions generic over operand typeRalf Jung-81/+83
2023-07-25interpret: make write functions generic over the place typeRalf Jung-139/+169
2023-07-25Auto merge of #113393 - compiler-errors:next-solver-unsize-rhs, r=lcnrbors-3/+6
Normalize the RHS of an `Unsize` goal in the new solver `Unsize` goals are... tricky. Not only do they structurally match on their self type, but they're also structural on their other type parameter. I'm pretty certain that it is both incomplete and also just plain undesirable to not consider normalizing the RHS of an unsize goal. More practically, I'd like for this code to work: ```rust trait A {} trait B: A {} impl A for usize {} impl B for usize {} trait Mirror { type Assoc: ?Sized; } impl<T: ?Sized> Mirror for T { type Assoc = T; } fn main() { // usize: Unsize<dyn B> let x = Box::new(1usize) as Box<<dyn B as Mirror>::Assoc>; // dyn A: Unsize<dyn B> let y = x as Box<<dyn A as Mirror>::Assoc>; } ``` --- In order to achieve this, we add `EvalCtxt::normalize_non_self_ty` (naming modulo bikeshedding), which *must* be used for all non-self type arguments that are structurally matched in candidate assembly. Currently this is only necessary for `Unsize`'s argument, but I could see future traits requiring this (hopefully rarely) in the future. It uses `repeat_while_none` to limit infinite looping, and normalizes the self type until it is no longer an alias. Also, we need to fix feature gate detection for `trait_upcasting` and `unsized_tuple_coercion` when HIR typeck has unnormalized types. We can do that by checking the `ImplSource` returned by selection, which necessitates adding a new impl source for tuple upcasting.
2023-07-25Make everything builtin!Michael Goulet-3/+6
2023-07-25Auto merge of #114011 - RalfJung:place-projection, r=oli-obkbors-1142/+951
interpret: Unify projections for MPlaceTy, PlaceTy, OpTy For ~forever, we didn't really have proper shared code for handling projections into those three types. This is mostly because `PlaceTy` projections require `&mut self`: they might have to `force_allocate` to be able to represent a project part-way into a local. This PR finally fixes that, by enhancing `Place::Local` with an `offset` so that such an optimized place can point into a part of a place without having requiring an in-memory representation. If we later write to that place, we will still do `force_allocate` -- for now we don't have an optimized path in `write_immediate` that would avoid allocation for partial overwrites of immediately stored locals. But in `write_immediate` we have `&mut self` so at least this no longer pollutes all our type signatures. (Ironically, I seem to distantly remember that many years ago, `Place::Local` *did* have an `offset`, and I removed it to simplify things. I guess I didn't realize why it was so useful... I am also not sure if this was actually used to achieve place projection on `&self` back then.) The `offset` had type `Option<Size>`, where `None` represent "no projection was applied". This is needed because locals *can* be unsized (when they are arguments) but `Place::Local` cannot store metadata: if the offset is `None`, this refers to the entire local, so we can use the metadata of the local itself (which must be indirect); if a projection gets applied, since the local is indirect, it will turn into a `Place::Ptr`. (Note that even for indirect locals we can have `Place::Local`: when the local appears in MIR, we always start with `Place::Local`, and only check `frame.locals` later. We could eagerly normalize to `Place::Ptr` but I don't think that would actually simplify things much.) Having done all that, we can finally properly abstract projections: we have a new `Projectable` trait that has the basic methods required for projecting, and then all projection methods are implemented for anything that implements that trait. We can even implement it for `ImmTy`! (Not that we need that, but it seems neat.) The visitor can be greatly simplified; it doesn't need its own trait any more but it can use the `Projectable` trait. We also don't need the separate `Mut` visitor any more; that was required only to reflect that projections on `PlaceTy` needed `&mut self`. It is possible that there are some more `&mut self` that can now become `&self`... I guess we'll notice that over time. r? `@oli-obk`
2023-07-25add some sanity checks in write_immediate_no_validateRalf Jung-3/+28
2023-07-25interpret: read_discriminant: only return VariantIdxRalf Jung-35/+49
2023-07-25interpret: refactor projection code to work on a common trait, and use that ↵Ralf Jung-1066/+681
for visitors
2023-07-24interpret: support projecting into Place::Local without force_allocationRalf Jung-249/+404
2023-07-22Auto merge of #113853 - cjgillot:split-validator, r=compiler-errorsbors-188/+303
Reuse the MIR validator for MIR inlining Instead of having the inliner home-cook its own validation, we just check that the substituted MIR body passes the regular validation. The MIR validation is first split in two: control flow validation (MIR syntax and CFG invariants) and type validation (subtyping relationship in assignments and projections). Only the latter can be affected by instantiating type parameters.
2023-07-21Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"David Tolnay-71/+73
This reverts commit 557359f92512ca88b62a602ebda291f17a953002, reversing changes made to 1e6c09a803fd543a98bfbe1624d697a55300a786.
2023-07-21Auto merge of #113892 - RalfJung:uninit-undef-poison, r=wesleywiserbors-1/+1
clarify MIR uninit vs LLVM undef/poison In [this LLVM discussion](https://discourse.llvm.org/t/rfc-load-instruction-uninitialized-memory-semantics/67481) I learned that mapping our uninitialized memory in MIR to poison in LLVM would be quite problematic due to the lack of a byte type. I am not sure where to write down this insight but this seems like a reasonable start.
2023-07-21Reuse MIR validator for inliner.Camille GILLOT-1/+1
2023-07-21Make type validation buffer errors.Camille GILLOT-25/+24
2023-07-21Separate CFG validation from type validation.Camille GILLOT-181/+297
2023-07-21Double check that hidden types match the expected hidden typeOli Scherer-3/+8
2023-07-21CTFE: move `target_{i, u}size_{min, max)` to `rustc_abi::TargetDataLayout`Moulins-11/+9
2023-07-21support non-null pointer niches in CTFEMoulins-63/+63
2023-07-20clarify MIR uninit vs LLVM undef/poisonRalf Jung-1/+1
2023-07-16Refactor checking function target features during const-evalEduardo Sánchez Muñoz-18/+29
* Split into its own function * Do not build a `Vec` of unavailable features
2023-07-16miri: fail when calling a function that requires an unavailable target featureEduardo Sánchez Muñoz-0/+19
miri will report an UB when calling a function that has a `#[target_feature(enable = ...)]` attribute is called and the required feature is not available. "Available features" are the same that `is_x86_feature_detected!` (or equivalent) reports to be available during miri execution (which can be enabled or disabled with the `-C target-feature` flag).
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-104/+100
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-33/+54
2023-07-11fix handling of alignment for dyn-sized placesRalf Jung-4/+6
2023-07-11miri: protect Move() function arguments during the callRalf Jung-64/+180
2023-07-08Auto merge of #113376 - ↵bors-23/+24
Nilstrieb:pointer-coercions-are-not-casts-because-that-sounds-way-to-general-aaaa, r=oli-obk Rename `adjustment::PointerCast` and variants using it to `PointerCoercion` It makes it sounds like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a little enum variants. Make it clear there these are only coercions and that people who see this and think "why are so many pointer related casts not in these variants" aren't insane. This enum was added in #59987. I'm not sure whether the variant sharing is actually worth it, but this at least makes it less confusing. r? oli-obk
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-23/+24
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-07miri: check that assignments do not self-overlapRalf Jung-1/+6
2023-07-07Auto merge of #113308 - compiler-errors:poly-select, r=lcnrbors-14/+9
Split `SelectionContext::select` into fns that take a binder and don't *most* usages of `SelectionContext::select` don't need to use a binder, but wrap them in a dummy because of the signature. Let's split this out into `SelectionContext::{select,poly_select}` and limit the usages of the latter. Right now, we only have 3 places where we're calling `poly_select` -- fulfillment, internally within the old solver, and the auto-trait finder. r? `@lcnr`
2023-07-06Rollup merge of #111917 - WaffleLapkin:validate_unalloc, r=oli-obkMichael Goulet-14/+9
Simplify duplicate checks for mir validator This removes unnecessary allocations & is less code.
2023-07-06Separate select calls that don't need a binderMichael Goulet-14/+9
2023-07-06Auto merge of #113377 - BoxyUwU:move_ty_ctors_to_ty, r=compiler-errorsbors-10/+16
Move `TyCtxt::mk_x` to `Ty::new_x` where applicable Part of rust-lang/compiler-team#616 turns out there's a lot of places we construct `Ty` this is a ridiculously huge PR :S r? `@oli-obk`