summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
2022-02-15Overhaul `Const`.Nicholas Nethercote-8/+8
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
2022-02-15Overhaul `TyS` and `Ty`.Nicholas Nethercote-6/+6
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
2022-02-11use body.tainted_by_error to skip loading MIRMichael Goulet-17/+9
2022-02-11rework borrowck errors so that it's harder to not set taintedMichael Goulet-2/+4
2022-02-11skip const eval if we have an error in borrowckMichael Goulet-1/+5
2022-01-20update commentslcnr-1/+5
2022-01-17Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieubors-2/+0
Remove deprecated LLVM-style inline assembly The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it is time to remove `llvm_asm!` to avoid continued maintenance cost. Closes #70173. Closes #92794. Closes #87612. Closes #82065. cc `@rust-lang/wg-inline-asm` r? `@Amanieu`
2022-01-15initial revertEllen-8/+4
2022-01-12Remove deprecated LLVM-style inline assemblyTomasz Miąsko-2/+0
2022-01-11Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef`Aaron Hill-3/+3
The field is also renamed from `ident` to `name. In most cases, we don't actually need the `Span`. A new `ident` method is added to `VariantDef` and `FieldDef`, which constructs the full `Ident` using `tcx.def_ident_span()`. This method is used in the cases where we actually need an `Ident`. This makes incremental compilation properly track changes to the `Span`, without all of the invalidations caused by storing a `Span` directly via an `Ident`.
2022-01-04rename StackPopClean::None to RootRalf Jung-6/+12
2022-01-03Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievinkMatthias Krüger-12/+1
Remove `NullOp::Box` Follow up of #89030 and MCP rust-lang/compiler-team#460. ~1 month later nothing seems to be broken, apart from a small regression that #89332 (1aac85bb716c09304b313d69d30d74fe7e8e1a8e) shows could be regained by remvoing the diverging path, so it shall be safe to continue and remove `NullOp::Box` completely. r? `@jonas-schievink` `@rustbot` label T-compiler
2021-12-31Extend check for UnsafeCell in consts to cover unionsTomasz Miąsko-1/+8
A validity companion to changes from #90373.
2021-12-24Auto merge of #91342 - RalfJung:fn-abi, r=eddyb,oli-obkbors-136/+209
CTFE eval_fn_call: use FnAbi to determine argument skipping and compatibility This makes use of the `FnAbi` type in CTFE/Miri, which `@eddyb` has been saying for years is what we should do.^^ `FnAbi` is used to - determine which arguments to skip (rather than the previous heuristic of skipping ZST arguments with the Rust ABI) - impose further restrictions on whether caller and callee are consistent in how a given argument is passed I was hoping it would also simplify the code, but that is not the case -- the previous type compatibility checks are still required (AFAIK), only the ZST skipping is gone and that took barely any code. We also need some hacks because `FnAbi` assumes a certain way of implementing `caller_location` (by passing extra arguments), but Miri can just read the caller location from the call stack so it doesn't need those arguments. (The fact that every backend has to separately implement support for these arguments seems suboptimal -- looks like this might have been better implemented on the MIR level.) To avoid having to implement those unnecessary arguments in Miri, we just compute *whether* the argument is present on the caller/callee side, but don't actually pass that argument around. I have no idea if this looks the way `@eddyb` thinks it should look... but it makes Miri's test suite pass. ;) One of rustc's tests fails unfortunately (`ui/const-generics/issues/issue-67739.rs`), some const generic code that is evaluated too early -- I think that should raise `TooGeneric` but instead it ICEs. My assumption is this is some FnAbi code that has not been properly tested on polymorphic code, but it might also be me calling that FnAbi code the wrong way. r? `@oli-obk` `@eddyb` Fixes https://github.com/rust-lang/rust/issues/56166 Miri PR at https://github.com/rust-lang/miri/pull/1928
2021-12-22Store a `DefId` instead of an `AdtDef` in `AggregateKind::Adt`Aaron Hill-2/+2
The `AggregateKind` enum ends up in the final mir `Body`. Currently, any changes to `AdtDef` (regardless of how significant they are) will legitimately cause the overall result of `optimized_mir` to change, invalidating any codegen re-use involving that mir. This will get worse once we start hashing the `Span` inside `FieldDef` (which is itself contained in `AdtDef`). To try to reduce these kinds of invalidations, this commit changes `AggregateKind::Adt` to store just the `DefId`, instead of the full `AdtDef`. This allows the result of `optimized_mir` to be unchanged if the `AdtDef` changes in a way that doesn't actually affect any of the MIR we build.
2021-12-20better name for AdjustForForeignAbiError error variant in InterpErrorRalf Jung-1/+3
2021-12-20don't ICE on variadic function callsRalf Jung-2/+9
2021-12-20also compare ArgAttributesRalf Jung-29/+38
2021-12-20compare calling convention instead of call ABIRalf Jung-37/+9
2021-12-20CTFE eval_fn_call: use FnAbi to determine argument skipping and compatibilityRalf Jung-107/+190
2021-12-19Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obkbors-2/+2
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2021-12-15miri: lift restriction on extern types being the only field in a structTomasz Miąsko-27/+11
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-2/+2
2021-12-14Rollup merge of #91856 - ouz-a:master, r=oli-obkMatthias Krüger-2/+3
Looser check for overflowing_binary_op Fix for issue #91636 tight check resulted in ICE, this makes the check a little looser. It seems `eq` allows comparing of `supertype` and `subtype` if `lhs = supertype` and `rhs = subtype` but not vice versa, is this intended behavior ?
2021-12-14comment updateouz-a-1/+1
2021-12-13Remove `in_band_lifetimes` from `rustc_const_eval`LegionMammal978-12/+13
See #91867 for more information.
2021-12-14Add regression test and commentouz-a-1/+2
2021-12-13formattingouz-a-1/+1
2021-12-13Looser check for binary_op_overflowouz-a-1/+1
2021-12-12Auto merge of #91549 - fee1-dead:const_env, r=spastorinobors-0/+1
Eliminate ConstnessAnd again Closes #91489. Closes #89432. Reverts #91491. Reverts #89450. r? `@spastorino`
2021-12-12Rollup merge of #91815 - RalfJung:span, r=oli-obkMatthias Krüger-2/+2
better span for unexpected normalization failure in CTFE engine No reason to use `DUMMY_SP` here.
2021-12-12Rollup merge of #91814 - japm48:spelling-fix, r=RalfJungMatthias Krüger-2/+2
doc: fix typo in comments `dereferencable -> dereferenceable` Fixes #91802.
2021-12-12Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"Deadbeef-0/+1
This reverts commit ff2439b7b9bafcfdff86b7847128014699df8442, reversing changes made to 2a9e0831d6603d87220cedd1b1293e2eb82ef55c.
2021-12-11better span for unexpected normalization failure in CTFE engineRalf Jung-2/+2
2021-12-12doc: fix typo in commentsjapm48-2/+2
dereferencable -> dereferenceable
2021-12-11Rollup merge of #90081 - woppopo:const_write_bytes, r=oli-obkMatthias Krüger-0/+24
Make `intrinsics::write_bytes` const This is required to constify `MaybeUninit::zeroed` and `(*mut T)::write_bytes`. Tracking issue: #86302
2021-12-09Remove redundant [..]sest31-1/+1
2021-12-05allow for failure of subst_normalize_erasing_regions in const_evalb-naber-11/+23
2021-12-03Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"Santiago Pastorino-1/+0
This reverts commit 18bb8c61a975fff6424cda831ace5b0404277145, reversing changes made to d9baa361902b172be716f96619b909f340802dea.
2021-12-02Auto merge of #91354 - fee1-dead:const_env, r=spastorinobors-0/+1
Cleanup: Eliminate ConstnessAnd This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature. We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`. This is a continuation of https://github.com/rust-lang/rust/pull/90274. r? `@oli-obk` cc `@spastorino` `@ecstatic-morse`
2021-11-29CTFE: support assert_zero_valid and assert_uninit_validRalf Jung-1/+25
2021-11-29Always use const param envs for const eval.Oli Scherer-0/+1
Nothing else makes sense, and there is no "danger" in doing so, as it only does something if there are const bounds, which are unstable. This used to happen implicitly via the inferctxt before, which was much more fragile.
2021-11-27Miri: fix alignment check in array initializationRalf Jung-1/+5
2021-11-24Make `intrinsics::write_bytes` constwoppopo-0/+24
2021-11-23explain why CTFE/Miri perform truncation on shift offsetRalf Jung-1/+6
2021-11-20Revert "require full validity when determining the discriminant of a value"Ralf Jung-12/+0
This reverts commit 0a2b7d71d96a22126cce57f0dab5890d060f2259, reversing changes made to 47c1bd1bcc50b25d133f8be3d49825491c1df249. This caused several unforeseen problems: - https://github.com/rust-lang/rust/issues/91029 - https://github.com/rust-lang/rust/pull/89764#issuecomment-973588007
2021-11-20Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obkMatthias Krüger-32/+55
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for https://github.com/rust-lang/miri/issues/1912. r? ``````@oli-obk``````
2021-11-19Rollup merge of #90895 - RalfJung:read-discriminant-valid, r=oli-obkYuki Okushi-0/+12
require full validity when determining the discriminant of a value This resolves (for now) the semantic question that came up in https://github.com/rust-lang/rust/pull/89764: arguably, reading the discriminant of a value is 'using' that value, so we are in our right to demand full validity. Reading a discriminant is somewhat special in that it works for values of *arbitrary* type; all the other primitive MIR operations work on specific types (e.g. `bool` or an integer) and basically implicitly require validity as part of just "doing their job". The alternative would be to just require that the discriminant itself is valid, if any -- but then what do we do for types that do not have a discriminant, which kind of validity do we check? [This code](https://github.com/rust-lang/rust/blob/81117ff930fbf3792b4f9504e3c6bccc87b10823/compiler/rustc_codegen_ssa/src/mir/place.rs#L206-L215) means we have to at least reject uninhabited types, but I would rather not special case that. I don't think this can be tested in CTFE (since validity is not enforced there), I will add a compile-fail test to Miri: ```rust #[allow(enum_intrinsics_non_enums)] fn main() { let i = 2u8; std::mem::discriminant(unsafe { &*(&i as *const _ as *const bool) }); // UB } ``` (I tried running the check even on the CTFE machines, but then it runs during ConstProp and that causes all sorts of problems. We could run it for ConstEval but not ConstProp, but that simply does not seem worth the effort currently.) r? ``@oli-obk``
2021-11-18fix CTFE/Miri simd_insert/extract on array-style repr(simd) typesRalf Jung-32/+55
2021-11-14require full validity when determining the discriminant of a valueRalf Jung-0/+12