summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2022-02-16Support pretty printing of invalid constantsTomasz Miąsko-22/+20
Make it possible to pretty print invalid constants by introducing a fallible variant of `destructure_const` and falling back to debug formatting when it fails.
2022-02-15Overhaul `Const`.Nicholas Nethercote-15/+15
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-9/+9
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-12Report the selection error when possibleDeadbeef-15/+36
2022-02-12Adapt new changeDeadbeef-4/+11
2022-02-12Handle Fn family trait call errrorDeadbeef-4/+41
2022-02-12Rebased and improved errorsDeadbeef-4/+2
2022-02-12Improve error messages even moreDeadbeef-126/+388
2022-02-12More informative error message for E0015Deadbeef-49/+51
2022-02-11use body.tainted_by_error to skip loading MIRMichael Goulet-40/+17
2022-02-11add tainted_by_errors to mir::BodyMichael Goulet-5/+8
2022-02-11rework borrowck errors so that it's harder to not set taintedMichael Goulet-4/+6
2022-02-11skip const eval if we have an error in borrowckMichael Goulet-1/+8
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-17/+8
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-07Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakisbors-8/+17
Lazy type-alias-impl-trait Previously opaque types were processed by 1. replacing all mentions of them with inference variables 2. memorizing these inference variables in a side-table 3. at the end of typeck, resolve the inference variables in the side table and use the resolved type as the hidden type of the opaque type This worked okayish for `impl Trait` in return position, but required lots of roundabout type inference hacks and processing. This PR instead stops this process of replacing opaque types with inference variables, and just keeps the opaque types around. Whenever an opaque type `O` is compared with another type `T`, we make the comparison succeed and record `T` as the hidden type. If `O` is compared to `U` while there is a recorded hidden type for it, we grab the recorded type (`T`) and compare that against `U`. This makes implementing * https://github.com/rust-lang/rfcs/pull/2515 much simpler (previous attempts on the inference based scheme were very prone to ICEs and general misbehaviour that was not explainable except by random implementation defined oddities). r? `@nikomatsakis` fixes #93411 fixes #88236
2022-02-03Rollup merge of #92802 - compiler-errors:deduplicate-stack-trace, r=oli-obkYuki Okushi-1/+29
Deduplicate lines in long const-eval stack trace Lemme know if this is kinda overkill, lol. Fixes #92796
2022-02-02Rollup merge of #93546 - tmiasko:validate-switch-int, r=oli-obkMatthias Krüger-0/+18
Validate that values in switch int terminator are unique
2022-02-02Fixup changes that aren't neccessary anymoreOli Scherer-2/+2
2022-02-02Lazily resolve type-alias-impl-trait defining usesOli Scherer-8/+17
by using an opaque type obligation to bubble up comparisons between opaque types and other types Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-02-01add a rustc::query_stability lintlcnr-0/+1
2022-02-01Validate that values in switch int terminator are uniqueTomasz Miąsko-0/+18
2022-01-30Rollup merge of #93358 - compiler-errors:is-not-const, r=fee1-deadMatthias Krüger-3/+2
Add note suggesting that predicate may be satisfied, but is not `const` Not sure if we should be printing this in addition to, or perhaps _instead_ of the help message: ``` help: the trait `~const Add` is not implemented for `NonConstAdd` ``` Also added `ParamEnv::is_const` and `PolyTraitPredicate::is_const_if_const` and, in a separate commit, used those in other places instead of `== hir::Constness::Const`, etc. r? ````@fee1-dead````
2022-01-29Rollup merge of #92274 - woppopo:const_deallocate, r=oli-obkMatthias Krüger-0/+27
Add `intrinsics::const_deallocate` Tracking issue: #79597 Related: #91884 This allows deallocation of a memory allocated by `intrinsics::const_allocate`. At the moment, this can be only used to reduce memory usage, but in the future this may be useful to detect memory leaks (If an allocated memory remains after evaluation, raise an error...?).
2022-01-26drive-by: use is_const and is_const_if_constMichael Goulet-3/+2
2022-01-26`const_deallocate`: Don't deallocate memory allocated in an another const. ↵woppopo-5/+15
Does nothing at runtime. `const_allocate`: Returns a null pointer at runtime.
2022-01-24Auto merge of #93028 - compiler-errors:const_drop_bounds, r=fee1-deadbors-21/+39
Check `const Drop` impls considering `~const` Bounds This PR adds logic to trait selection to account for `~const` bounds in custom `impl const Drop` for types, elaborates the `const Drop` check in `rustc_const_eval` to check those bounds, and steals some drop linting fixes from #92922, thanks `@DrMeepster.` r? `@fee1-dead` `@oli-obk` <sup>(edit: guess I can't request review from two people, lol)</sup> since each of you wrote and reviewed #88558, respectively. Since the logic here is more complicated than what existed, it's possible that this is a perf regression. But it works correctly with tests, and that makes me happy. Fixes #92881
2022-01-23Add `intrinsics::const_deallocate`woppopo-0/+17
2022-01-20update commentslcnr-1/+5
2022-01-19Foreign types are trivially dropMichael Goulet-1/+1
- Also rename a trivial_const_drop to match style of other functions in the util module. - Also add a test for `const Drop` that doesn't depend on a `~const` bound. - Also comment a bit why we remove the const bound during dropck impl check.
2022-01-18Short-circuit some trivially const Drop typesMichael Goulet-10/+9
2022-01-18Check const Drop impls considering ConstIfConst boundsMichael Goulet-12/+31
2022-01-17Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieubors-7/+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-16Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnrbors-22/+13
partially revertish `lazily "compute" anon const default substs` reverts #87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted why revert: <https://github.com/rust-lang/rust/pull/92805#issuecomment-1010736049> r? `@lcnr`
2022-01-15Reduce use of local_def_id_to_hir_id.Camille GILLOT-10/+9
2022-01-15initial revertEllen-22/+13
2022-01-12Remove deprecated LLVM-style inline assemblyTomasz Miąsko-7/+0
2022-01-12Rollup merge of #92432 - fee1-dead:constck-impl-constness, r=oli-obkMatthias Krüger-1/+5
Error when selected impl is not const in constck Catches bad things when checking a `default_method_body_is_const` body, such as: ```rust self.map(/* .. */).is_sorted(); ``` When `Map` does not yet have a `const` `impl` for `Iterator`. r? ```@oli-obk```
2022-01-11Deduplicate lines in long const-eval stack traceMichael Goulet-1/+29
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-7/+13
2022-01-03Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievinkMatthias Krüger-21/+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-30Error when selected impl is not const in constckDeadbeef-1/+5
2021-12-24Auto merge of #91342 - RalfJung:fn-abi, r=eddyb,oli-obkbors-139/+222
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-4/+6
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-20const_eval machine: use original instance for replaced MIR bodiesRalf Jung-1/+11