about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2023-04-12Auto merge of #110249 - matthiaskrgr:rollup-7iig04q, r=matthiaskrgrbors-1/+1
Rollup of 8 pull requests Successful merges: - #110153 (Fix typos in compiler) - #110165 (rustdoc: use CSS `overscroll-behavior` instead of JavaScript) - #110175 (Symbol cleanups) - #110203 (Remove `..` from return type notation) - #110205 (rustdoc: make settings radio and checks thicker, less contrast) - #110222 (Improve the error message when forwarding a matched fragment to another macro) - #110237 (Split out a separate feature gate for impl trait in associated types) - #110241 (tidy: Issue an error when UI test limits are too high) Failed merges: - #110218 (Remove `ToRegionVid`) r? `@ghost` `@rustbot` modify labels: rollup
2023-04-10Fix typos in compilerDaniPopes-1/+1
2023-04-09Fix transmute intrinsic mir validation ICEJakob Degen-2/+10
2023-04-07Auto merge of #102906 - nbdd0121:mir, r=wesleywiser,tmiaskobors-78/+74
Refactor unwind in MIR This makes unwinding from current `Option<BasicBlock>` into ```rust enum UnwindAction { Continue, Cleanup(BasicBlock), Unreachable, Terminate, } ``` cc `@JakobDegen` `@RalfJung` `@Amanieu`
2023-04-06Stabilize is_some_andJonas Platte-1/+0
2023-04-06Fix mir interp of `TerminatorKind::Terminate`Gary Guo-1/+2
2023-04-06Fix toolsGary Guo-0/+1
2023-04-06Address review feedbackGary Guo-15/+23
2023-04-06Rename `Abort` terminator to `Terminate`Gary Guo-7/+10
Unify terminology used in unwind action and terminator, and reflect the fact that a nounwind panic is triggered instead of an immediate abort is triggered for this terminator.
2023-04-06Add `UnwindAction::Terminate`Gary Guo-0/+3
2023-04-06Add `UnwindAction::Unreachable`Gary Guo-47/+25
This also makes eval machine's `StackPopUnwind` redundant so that is replaced.
2023-04-06Refactor unwind from Option to a new enumGary Guo-21/+23
2023-04-06Rollup merge of #109921 - compiler-errors:dyn-star-const-static, r=eholkYuki Okushi-1/+1
Don't ICE when encountering `dyn*` in statics or consts Since we have properly implemented `dyn*` support in CTFE (#107728), let's not ICE here anymore. Fixes #105777 r? `@eholk`
2023-04-04Rollup merge of #109938 - oli-obk:try_norm, r=compiler-errorsMichael Goulet-8/+1
Move a const-prop-lint specific hack from mir interpret to const-prop-lint and make it fallible fixes #109743 This hack didn't need to live in the mir interpreter. For const-prop-lint it is entirely correct to avoid doing any const prop if normalization fails at this stage. Most likely we couldn't const propagate anything anyway, and if revealing was needed (so opaque types were involved), we wouldn't want to be too smart and leak the hidden type anyway.
2023-04-04Rollup merge of #109901 - cjgillot:validate-debuginfo, r=b-naberMichael Goulet-4/+39
Enforce VarDebugInfo::Place in MIR validation.
2023-04-04Move a const-prop-lint specific hack from mir interpret to const-prop-lint ↵Oli Scherer-8/+1
and make it fallible
2023-04-04dyn* is a valid constMichael Goulet-1/+1
2023-04-03Enforce VarDebugInfo::Place in MIR validation.Camille GILLOT-4/+39
2023-04-02Use `&IndexSlice` instead of `&IndexVec` where possibleScott McMurray-3/+3
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
2023-04-02Auto merge of #109849 - scottmcm:more-fieldidx-rebase, r=oli-obkbors-4/+5
Use `FieldIdx` in various things related to aggregates Shrank `AggregateKind` by 8 bytes on x64, since the active field of a union is tracked as an `Option<FieldIdx>` instead of `Option<usize>`. Part 3/? of https://github.com/rust-lang/compiler-team/issues/606 [`IndexSlice`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_index/vec/struct.IndexVec.html#deref-methods-IndexSlice%3CI,+T%3E) was added in https://github.com/rust-lang/rust/pull/109787
2023-04-01Use `FieldIdx` in various things related to aggregatesScott McMurray-4/+5
Shrank `AggregateKind` by 8 bytes on x64, since the active field of a union is tracked as an `Option<FieldIdx>` instead of `Option<usize>`.
2023-04-01slighty simplify a few boolean expressions (clippy::nonminimal_bool)Matthias Krüger-2/+1
2023-03-31Auto merge of #98112 - saethlin:mir-alignment-checks, r=oli-obkbors-0/+6
Insert alignment checks for pointer dereferences when debug assertions are enabled Closes https://github.com/rust-lang/rust/issues/54915 - [x] Jake tells me this sounds like a place to use `MirPatch`, but I can't figure out how to insert a new basic block with a new terminator in the middle of an existing basic block, using `MirPatch`. (if nobody else backs up this point I'm checking this as "not actually a good idea" because the code looks pretty clean to me after rearranging it a bit) - [x] Using `CastKind::PointerExposeAddress` is definitely wrong, we don't want to expose. Calling a function to get the pointer address seems quite excessive. ~I'll see if I can add a new `CastKind`.~ `CastKind::Transmute` to the rescue! - [x] Implement a more helpful panic message like slice bounds checking. r? `@oli-obk`
2023-03-30Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>`Scott McMurray-5/+10
And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`. There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places. Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
2023-03-29Auto merge of #108089 - Zoxc:windows-tls, r=bjorn3bors-0/+1
Support TLS access into dylibs on Windows This allows access to `#[thread_local]` in upstream dylibs on Windows by introducing a MIR shim to return the address of the thread local. Accesses that go into an upstream dylib will call the MIR shim to get the address of it. `convert_tls_rvalues` is introduced in `rustc_codegen_ssa` which rewrites MIR TLS accesses to dummy calls which are replaced with calls to the MIR shims when the dummy calls are lowered to backend calls. A new `dll_tls_export` target option enables this behavior with a `false` value which is set for Windows platforms. This fixes https://github.com/rust-lang/rust/issues/84933.
2023-03-29Rename `IndexVec::last` → `last_index`Scott McMurray-2/+2
As I've been trying to replace a `Vec` with an `IndexVec`, having `last` exist on both but returning very different types makes the transition a bit awkward -- the errors are later, where you get things like "there's no `ty` method on `mir::Field`" rather than a more localized error like "hey, there's no `last` on `IndexVec`". So I propose renaming `last` to `last_index` to help distinguish `Vec::last`, which returns an element, and `IndexVec::last_index`, which returns an index. (Similarly, `Iterator::last` also returns an element, not an index.)
2023-03-29Support TLS access into dylibs on WindowsJohn Kåre Alsaker-0/+1
2023-03-28Auto merge of #108080 - oli-obk:FnPtr-trait, r=lcnrbors-0/+1
Add a builtin `FnPtr` trait that is implemented for all function pointers r? `@ghost` Rebased version of https://github.com/rust-lang/rust/pull/99531 (plus adjustments mentioned in the PR). If perf is happy with this version, I would like to land it, even if the diagnostics fix in 9df8e1befb5031a5bf9d8dfe25170620642d3c59 only works for `FnPtr` specifically, and does not generally improve blanket impls.
2023-03-28Move const trait bounds checks to MIR constckDeadbeef-25/+26
Fixes #109543. When checking paths in HIR typeck, we don't want to check for const predicates since all we want might just be a function pointer. Therefore we move this to MIR constck and check that bounds are met during MIR constck.
2023-03-27Add a builtin `FnPtr` traitlcnr-0/+1
2023-03-25Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`Scott McMurray-6/+6
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
2023-03-24miri: fix raw pointer dyn receiversRalf Jung-1/+9
2023-03-23A MIR transform that checks pointers are alignedBen Kimock-0/+6
2023-03-22Add `CastKind::Transmute` to MIRScott McMurray-4/+43
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
2023-03-23Rollup merge of #109435 - oli-obk:🇨🇭🥚_copy_op, r=RalfJungDylan DPC-7/+8
Detect uninhabited types early in const eval r? `@RalfJung` implements https://github.com/rust-lang/rust/pull/108442#discussion_r1143003840 this is a breaking change, as some UB during const eval is now detected instead of silently being ignored. Users can see this and other UB that may cause future breakage with `-Zextra-const-ub-checks` or just by running miri on their code, which sets that flag by default.
2023-03-22Auto merge of #109119 - lcnr:trait-system-cleanup, r=compiler-errorsbors-2/+5
a general type system cleanup removes the helper functions `traits::fully_solve_X` as they add more complexity then they are worth. It's confusing which of these helpers should be used in which context. changes the way we deal with overflow to always add depth in `evaluate_predicates_recursively`. It may make sense to actually fully transition to not have `recursion_depth` on obligations but that's probably a bit too much for this PR. also removes some other small - and imo unnecessary - helpers. r? types
2023-03-21Use local key in providersMichael Goulet-4/+3
2023-03-21Detect uninhabited types early in const eval.Oli Scherer-2/+2
2023-03-21remove some trait solver helperslcnr-2/+5
they add more complexity then they are worth. It's confusing which of these helpers should be used in which context.
2023-03-21Add a layout argument to `enforce_validity`.Oli Scherer-6/+7
This is in preparation of checking the validity only of certain types.
2023-03-20Rollup merge of #109307 - cjgillot:inline-location, r=compiler-errorsMatthias Krüger-1/+5
Ignore `Inlined` spans when computing caller location. Fixes https://github.com/rust-lang/rust/issues/105538
2023-03-18Ignore `Inlined` spans when computing caller location.Camille GILLOT-1/+5
2023-03-18Rollup merge of #109234 - tmiasko:overflow-checks, r=cjgillotMatthias Krüger-8/+4
Tweak implementation of overflow checking assertions Extract and reuse logic controlling behaviour of overflow checking assertions instead of duplicating it three times. r? `@cjgillot`
2023-03-16Tweak implementation of overflow checking assertionsTomasz Miąsko-8/+4
Extract and reuse logic controlling behaviour of overflow checking assertions instead of duplicating it three times.
2023-03-16Auto merge of #108944 - cjgillot:clear-local-info, r=oli-obkbors-4/+5
Wrap the whole LocalInfo in ClearCrossCrate. MIR contains a lot of information about locals. The primary purpose of this information is the quality of borrowck diagnostics. This PR aims to drop this information after MIR analyses are finished, ie. starting from post-cleanup runtime MIR.
2023-03-15Auto merge of #108282 - cjgillot:mir-checked-sh, r=tmiaskobors-9/+0
Implement checked Shl/Shr at MIR building. This does not require any special handling by codegen backends, as the overflow behaviour is entirely determined by the rhs (shift amount). This allows MIR ConstProp to remove the overflow check for constant shifts. ~There is an existing different behaviour between cg_llvm and cg_clif (cc `@bjorn3).` I took cg_llvm's one as reference: overflow if `rhs < 0 || rhs > number_of_bits_in_lhs_ty`.~ EDIT: `cg_llvm` and `cg_clif` implement the overflow check differently. This PR uses `cg_llvm`'s implementation based on a `BitAnd` instead of `cg_clif`'s one based on an unsigned comparison.
2023-03-14Remove LocalKind::Var.Camille GILLOT-3/+4
2023-03-14Wrap the whole LocalInfo in ClearCrossCrate.Camille GILLOT-1/+1
2023-03-12Auto merge of #108872 - cjgillot:simp-const-prop, r=oli-obkbors-17/+13
Strengthen state tracking in const-prop Some/many of the changes are replicated between both the const-prop lint and the const-prop optimization. Behaviour changes: - const-prop opt does not give a span to propagated values. This was useless as that span's primary purpose is to diagnose evaluation failure in codegen. - we remove the `OnlyPropagateInto` mode. It was only used for function arguments, which are better modeled by a write before entry. - the tracking of assignments and discriminants make clearer that we do nothing in `NoPropagation` mode or on indirect places.
2023-03-11Simplify message pathsest31-1/+1
This makes it easier to open the messages file while developing on features. The commit was the result of automatted changes: for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done