about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
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-1145/+955
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-1067/+685
for visitors
2023-07-24interpret: support projecting into Place::Local without force_allocationRalf Jung-251/+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/+74
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-64/+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/+22
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`
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-10/+16
2023-07-05Name the destructure_mir_constant query appropriatelyOli Scherer-3/+3
2023-07-05Use options instead of errors if the errors are never neededOli Scherer-13/+11
2023-07-05Remove a function argument that is always passed with the same value.Oli Scherer-1/+1
2023-07-05Specialize `DestructuredConstant` to its one user (pretty printing)Oli Scherer-1/+1
2023-07-05Specialize `try_destructure_mir_constant` for its sole userOli Scherer-10/+9
2023-07-02Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillotbors-1/+0
Make simd_shuffle_indices use valtrees This removes the second-to-last user of the `destructure_mir_constant` query. So in a follow-up we can remove the query and just move the query provider function directly into pretty printing (which is the last user). cc `@rust-lang/clippy` there's a small functional change, but I think it is correct?
2023-07-01Put `LayoutError` behind reference to shrink resultNilstrieb-4/+4
`LayoutError` is 24 bytes, which is bigger than the `Ok` types, so let's shrink that.
2023-06-28remove FIXME and add testJames Dietz-2/+0
2023-06-28add check for ConstKind::Value(_)James Dietz-2/+7
2023-06-27Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorinobors-16/+12
Use PlaceRef abstractions more often Associated issue: https://github.com/rust-lang/rust/issues/80647 r? `@spastorino`
2023-06-26Make simd_shuffle_indices use valtreesOli Scherer-1/+0
2023-06-25use PlaceRef abstractions more consistentlyEric Mark Martin-16/+12
2023-06-24Add enum for `can_access_statics` booleanNilstrieb-15/+36
`/*can_access_statics:*/ false` is one of the ways to do this, but not the one I like.
2023-06-20address most easy commentsZiru Niu-7/+5
2023-06-20merge `BorrowKind::Unique` into `BorrowKind::Mut`Ziru Niu-4/+5
2023-06-19Rollup merge of #112232 - fee1-dead-contrib:match-eq-const-msg, r=b-naberMichael Goulet-50/+79
Better error for non const `PartialEq` call generated by `match` Resolves #90237
2023-06-19Dedup some type checks in the MIR validatorScott McMurray-76/+57