about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
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
2023-03-10Auto merge of #108977 - matthiaskrgr:rollup-1bnl1hu, r=matthiaskrgrbors-1/+1
Rollup of 9 pull requests Successful merges: - #108879 (Unconstrained terms should account for infer vars being equated) - #108936 (Rustdoc: don't hide anonymous reexport) - #108940 (Add myself to compiler reviewers list) - #108945 (Make some report and emit errors take DefIds instead of BodyIds) - #108946 (Document the resulting values produced when using `From<bool>` on floats) - #108956 (Make ptr::from_ref and ptr::from_mut in #106116 const.) - #108960 (Remove `body_def_id` from `Inherited`) - #108963 (only call git on git checkouts during bootstrap) - #108964 (Fix the docs for pointer method with_metadata_of) Failed merges: - #108950 (Directly construct Inherited in typeck.) r? `@ghost` `@rustbot` modify labels: rollup
2023-03-09Remove body_def_id from InheritedMichael Goulet-1/+1
2023-03-09Introduce a no-op PlaceMention statement for `let _ =`.Camille GILLOT-1/+10
2023-03-08Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiaskoMatthias Krüger-36/+3
Remove DropAndReplace terminator #107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-08Assume the frame has all the locals.Camille GILLOT-17/+13
2023-03-07remove leftover commentGiacomo Pasini-3/+0
2023-03-07Remove DropAndReplace terminatorGiacomo Pasini-33/+3
PR 107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-06Rollup merge of #108803 - cjgillot:const-prop-normalize, r=oli-obkMatthias Krüger-9/+2
Do not ICE when failing to normalize in ConstProp. There is no reason to delay a bug there, as we bubble up the failure as TooGeneric. Fixes https://github.com/rust-lang/rust/issues/97728
2023-03-06Rollup merge of #108790 - cjgillot:mono-cast, r=oli-obkMatthias Krüger-13/+22
Do not ICE when interpreting a cast between non-monomorphic types Fixes https://github.com/rust-lang/rust/issues/101596
2023-03-06Rollup merge of #108786 - saethlin:free-regions-check, r=oli-obkMatthias Krüger-0/+11
Check for free regions in MIR validation This turns https://github.com/rust-lang/rust/issues/108720 into a MIR validation failure that will reproduce without debug-assertions enabled. ``` error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:296 ~ futures_util[3805]::future::future::remote_handle::{impl#3}::poll), const_param_did: None }) (after pass ScalarReplacementOfAggregates) at bb0[0]: Free regions in optimized runtime-post-cleanup MIR --> /home/ben/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.26/src/future/future/remote_handle.rs:96:13 | 96 | let this = self.project(); | ^^^^ ```
2023-03-06Rollup merge of #107801 - davidtwco:stability-implies-const, r=NilstriebMatthias Krüger-7/+22
const_eval: `implies_by` in `rustc_const_unstable` Fixes #107605. Extend support for `implies_by` (from `#[stable]` and `#[unstable]`) to `#[rustc_const_stable]` and `#[rustc_const_unstable]`. cc ``@steffahn``
2023-03-06Do not ICE when failing to normalize in ConstProp.Camille GILLOT-9/+2
2023-03-05Do not ICE when casting polymorphic values.Camille GILLOT-13/+22
2023-03-05Check for free regions in MIR validationBen Kimock-0/+11
2023-03-05Auto merge of #108351 - petrochenkov:rmdit, r=cjgillotbors-4/+2
rustc_middle: Remove trait `DefIdTree` This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary.
2023-03-04Rollup merge of #108669 - Nilstrieb:query-my-uninitness, r=compiler-errorsDylan DPC-1/+5
Allow checking whether a type allows being uninitialized This is useful for clippy ([rust-lang/clippy#10407](https://github.com/rust-lang/rust-clippy/issues/10407)) and for the future `MaybeUninit::assume_init` panics (#100423).
2023-03-03Rollup merge of #108685 - est31:backticks_matchmaking, r=petrochenkovMatthias Krüger-3/+3
Match unmatched backticks in compiler/ Found with GNU grep: ``` grep -rEn '^(([^`]*`){2})*[^`]*`[^`]*$' compiler/ | rg -v '\s*[//]?.{1,2}```' ```
2023-03-03Don't put integers into backticks during formattingest31-2/+2
2023-03-03Match end user facing unmatched backticks in compiler/est31-2/+2
2023-03-02Rollup merge of #108022 - CraftSpider:align-bytes, r=oli-obkMatthias Krüger-21/+46
Support allocations with non-Box<[u8]> bytes This is prep work for allowing miri to support passing pointers to C code, which will require `Allocation`s to be correctly aligned. Currently, it just makes `Allocation` generic and plumbs the necessary changes through the right places. The follow-up to this will be adding a type in the miri interpreter which correctly aligns the bytes, using that for the Miri engine, then allowing Miri to pass pointers into these allocations to C calls. Based off of #100467, credit to ```@emarteca``` for the code
2023-03-02rustc_middle: Remove trait `DefIdTree`Vadim Petrochenkov-4/+2
This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary.
2023-03-02Allow checking whether a type allows being uninitializedNilstrieb-1/+5
This is useful for clippy and for the future `MaybeUninit::assume_init` panics.
2023-03-01Rollup merge of #108505 - Nilstrieb:further-unify-validity-intrinsics, ↵Matthias Krüger-62/+50
r=michaelwoerister Further unify validity intrinsics Also merges the inhabitedness check into the query to further unify the code paths. Depends on #108364
2023-02-27Auto merge of #108487 - cjgillot:no-typeck-mir, r=oli-obkbors-4/+2
Avoid invoking typeck from borrowck This PR attempts to reduce direct dependencies between typeck and MIR-related queries. The goal is to have all the information transit either through THIR or through dedicated queries that avoid depending on the whole `TypeckResults`. In a first commit, we store the type information that MIR building requires into THIR. This avoids edges between mir_built and typeck. In the second and third commit, we wrap informations around closures (upvars, kind origin and user-provided signature) to avoid borrowck depending on typeck information. There should be a single remaining borrowck -> typeck edge in the good path, due to inline consts.
2023-02-27Implement checked Shl/Shr at MIR building.Camille GILLOT-9/+0
2023-02-27Unify all validity check intrinsicsNilstrieb-62/+50
Also merges the inhabitedness check into the query to further unify the code paths.