about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
2024-12-12Make BorrowSet/BorrowData fields accessible via public gettersWill Crichton-6/+9
2024-12-12Move impl constness into impl trait headerOli Scherer-9/+12
2024-12-11Make some types and methods related to Polonius + Miri public.Will Crichton-8/+20
2024-12-11Require the `constness` query to only be invoked on things that can have ↵Oli Scherer-4/+5
constness
2024-12-11Make a helper privateOli Scherer-1/+1
2024-12-10Rollup merge of #134010 - RalfJung:promoted-type-error-ice, r=oli-obkLeón Orell Valerian Liehr-18/+21
fix ICE on type error in promoted Fixes https://github.com/rust-lang/rust/issues/133968 Ensure that when we turn a type error into a "this promoted failed to evaluate" error, we do record this as something that may happen even in "infallible" promoteds.
2024-12-10Rename some `Analysis` and `ResultsVisitor` methods.Nicholas Nethercote-2/+2
The words "before" and "after" have an obvious temporal meaning, e.g. `seek_before_primary_effect`, `visit_statement_{before,after}_primary_effect`. But "before" is also used to name the effect that occurs before the primary effect of a statement/terminator; this is `Effect::Before`. This leads to the confusing possibility of talking about things happening "before/after the before event". This commit removes this awkward overloading of "before" by renaming `Effect::Before` as `Effect::Early`. It also renames some of the `Analysis` and `ResultsVisitor` methods to be more consistent. Here are the before and after names: - `Effect::{Before,Primary}` -> `Effect::{Early,Primary}` - `apply_before_statement_effect` -> `apply_early_statement_effect` - `apply_statement_effect` -> `apply_primary_statement_effect` - `visit_statement_before_primary_effect` -> `visit_after_early_statement_effect` - `visit_statement_after_primary_effect` -> `visit_after_primary_statement_effect` (And s/statement/terminator/ for all the terminator events.)
2024-12-09fix ICE on type error in promotedRalf Jung-18/+21
2024-12-09interpret: clean up deduplicating allocation functionsRalf Jung-33/+20
2024-12-09interpret: reduce usage of TypingEnv::fully_monomorphizedRalf Jung-8/+9
2024-12-08Rollup merge of #133861 - shamb0:refactor_InterpCx_allocate_str, r=RalfJungMatthias Krüger-13/+32
Add allocate_bytes and refactor allocate_str in InterpCx for raw byte… Fixes https://github.com/rust-lang/miri/issues/4025 This PR introduces a new `allocate_bytes` function in InterpCx and refactors `allocate_str` to use it internally. This change improves memory allocation handling in the interpreter by: 1. Adding `allocate_bytes`: - Direct byte slice allocation support - Handles both mutable and immutable allocations - Maintains proper memory alignment and deduplication 2. Refactoring `allocate_str`: - Now uses `allocate_bytes` internally - Adds string-specific metadata handling - Preserves existing string allocation behavior This is part 1 of the planned changes to improve timezone string handling in Miri. A follow-up PR will update Miri's timezone logic to use this new allocation mechanism. Related: https://github.com/rust-lang/miri/pull/4069
2024-12-07Mention type parameter in more cases and don't suggest ~const bound already ↵Esteban Küber-1/+1
there
2024-12-07Add allocate_bytes and refactor allocate_str in InterpCx for raw byte allocationshamb0-13/+32
Signed-off-by: shamb0 <r.raajey@gmail.com>
2024-12-06Remove polymorphizationBen Kimock-28/+6
2024-12-06Rollup merge of #133211 - Strophox:miri-correct-state-update-ffi, r=RalfJungMatthias Krüger-12/+60
Extend Miri to correctly pass mutable pointers through FFI Based off of https://github.com/rust-lang/rust/pull/129684, this PR further extends Miri to execute native calls that make use of pointers to *mutable* memory. We adapt Miri's bookkeeping of internal state upon any FFI call that gives external code permission to mutate memory. Native code may now possibly write and therefore initialize and change the pointer provenance of bytes it has access to: Such memory is assumed to be *initialized* afterwards and bytes are given *arbitrary (wildcard) provenance*. This enables programs that correctly use mutating FFI calls to run Miri without errors, at the cost of possibly missing Undefined Behaviour caused by incorrect usage of mutating FFI. > <details> > > <summary> Simple example </summary> > > ```rust > extern "C" { > fn init_int(ptr: *mut i32); > } > > fn main() { > let mut x = std::mem::MaybeUninit::<i32>::uninit(); > let x = unsafe { > init_int(x.as_mut_ptr()); > x.assume_init() > }; > > println!("C initialized my memory to: {x}"); > } > ``` > ```c > void init_int(int *ptr) { > *ptr = 42; > } > ``` > should now show `C initialized my memory to: 42`. > > </details> r? ``@RalfJung``
2024-12-05extend Miri to correctly pass mutable pointers through FFIStrophox-12/+60
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-12-03Rollup merge of #133681 - RalfJung:niches, r=wesleywiserMatthias Krüger-21/+29
improve TagEncoding::Niche docs, sanity check, and UB checks Turns out the `niche_variants` range can actually contain the `untagged_variant`. We should report this as UB in Miri, so this PR implements that. Also rename `partially_check_layout` to `layout_sanity_check` for better consistency with how similar functions are called in other parts of the compiler. Turns out my adjustments to the transmutation logic also fix https://github.com/rust-lang/rust/issues/126267.
2024-12-03Bounds-check with PtrMetadata instead of Len in MIRScott McMurray-5/+20
2024-12-03Auto merge of #133321 - compiler-errors:const-checker, r=wesleywiserbors-10/+9
Get rid of HIR const checker As far as I can tell, the HIR const checker was implemented in https://github.com/rust-lang/rust/pull/66170 because we were not able to issue useful const error messages in the MIR const checker. This seems to have changed in the last 5 years, probably due to work like #90532. I've tweaked the diagnostics slightly and think the error messages have gotten *better* in fact. Thus I think the HIR const checker has reached the end of its usefulness, and we can retire it. cc `@RalfJung`
2024-12-01fix ICE when promoted has layout size overflowRalf Jung-12/+16
2024-12-01fix safe-transmute handling of enumsRalf Jung-1/+1
2024-11-30report UB when the niche value refers to the untagged variantRalf Jung-20/+28
2024-11-26Move `always_storage_live_locals`.Nicholas Nethercote-3/+2
It's very closely related to `MaybeStorageLive` and `MaybeStorageDead`. It's weird that it's currently in a different module.
2024-11-23remove is_trivially_const_dropRalf Jung-5/+0
2024-11-22Check drop is trivial before checking ty needs dropMichael Goulet-1/+6
2024-11-22Deduplicate checking drop terminatorMichael Goulet-92/+53
2024-11-22Gate const drop behind const_destruct feature, and fix ↵Michael Goulet-82/+119
const_precise_live_drops post-drop-elaboration check
2024-11-22More comments, reverse polarity of structural checkMichael Goulet-35/+41
2024-11-22Implement ~const Destruct in new solverMichael Goulet-39/+42
2024-11-22Get rid of HIR const checkerMichael Goulet-10/+9
2024-11-20Auto merge of #131326 - dingxiangfei2009:issue-130836-attempt-2, r=nikomatsakisbors-0/+4
Reduce false positives of tail-expr-drop-order from consumed values (attempt #2) r? `@nikomatsakis` Tracked by #123739. Related to #129864 but not replacing, yet. Related to #130836. This is an implementation of the approach suggested in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/temporary.20drop.20order.20changes). A new MIR statement `BackwardsIncompatibleDrop` is added to the MIR syntax. The lint now works by inspecting possibly live move paths before at the `BackwardsIncompatibleDrop` location and the actual drop under the current edition, which should be one before Edition 2024 in practice.
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-0/+4
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-20interpret: make typing_env field privateRalf Jung-7/+6
2024-11-19`InterpCx` store `TypingEnv` instead of a `ParamEnv`lcnr-127/+115
2024-11-19move `fn is_item_raw` to `TypingEnv`lcnr-11/+10
2024-11-19Auto merge of #133164 - RalfJung:promoted-oom, r=jieyouxubors-1/+11
interpret: do not ICE when a promoted fails with OOM Fixes https://github.com/rust-lang/rust/issues/130687 try-job: aarch64-apple try-job: dist-x86_64-linux
2024-11-18Auto merge of #132460 - lcnr:questionable-uwu, r=compiler-errorsbors-154/+145
Use `TypingMode` throughout the compiler instead of `ParamEnv` Hopefully the biggest single PR as part of https://github.com/rust-lang/types-team/issues/128. ## `infcx.typing_env` while defining opaque types I don't know how'll be able to correctly handle opaque types when using something taking a `TypingEnv` while defining opaque types. To correctly handle the opaques we need to be able to pass in the current `opaque_type_storage` and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This is ## `layout_of` and `Reveal::All` We convert the `ParamEnv` to `Reveal::All` right at the start of the `layout_of` query, so I've changed callers of `layout_of` to already use a post analysis `TypingEnv` when encountering it. https://github.com/rust-lang/rust/blob/ca87b535a05097df6abbe2a031b057de2cefac5b/compiler/rustc_ty_utils/src/layout.rs#L51 ## `Ty::is_[unpin|sized|whatever]` I haven't migrated `fn is_item_raw` to use `TypingEnv`, will do so in a followup PR, this should significantly reduce the amount of `typing_env.param_env`. At some point there will probably be zero such uses as using the type system while ignoring the `typing_mode` is incorrect. ## `MirPhase` and phase-transitions When inside of a MIR-body, we can mostly use its `MirPhase` to figure out the right `typing_mode`. This does not work during phase transitions, most notably when transitioning from `Analysis` to `Runtime`: https://github.com/rust-lang/rust/blob/dae7ac133b9eda152784c075facb31a6688c92b1/compiler/rustc_mir_transform/src/lib.rs#L606-L625 All these passes still run with `MirPhase::Analysis`, but we should only use `Reveal::All` once we're run the `RevealAll` pass. This required me to manually construct the right `TypingEnv` in all these passes. Given that it feels somewhat easy to accidentally miss this going forward, I would maybe like to change `Body::phase` to an `Option` and replace it at the start of phase transitions. This then makes it clear that the MIR is currently in a weird state. r? `@ghost`
2024-11-18interpret: do not ICE when a promoted fails with OOMRalf Jung-1/+11
2024-11-18Rollup merge of #133163 - RalfJung:cold, r=saethlinGuillaume Gomez-3/+0
remove pointless cold_path impl in interpreter This has a fallback impl so the interpreter impl is not needed. r? ``@saethlin``
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-154/+145
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-18remove pointless cold_path impl in interpreterRalf Jung-3/+0
2024-11-18rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirectRalf Jung-2/+2
2024-11-17Auto merge of #120370 - x17jiri:likely_unlikely_fix, r=saethlinbors-0/+3
Likely unlikely fix RFC 1131 ( https://github.com/rust-lang/rust/issues/26179 ) added likely/unlikely intrinsics, but they have been broken for a while: https://github.com/rust-lang/rust/issues/96276 , https://github.com/rust-lang/rust/issues/96275 , https://github.com/rust-lang/rust/issues/88767 . This PR tries to fix them. Changes: - added a new `cold_path()` intrinsic - `likely()` and `unlikely()` changed to regular functions implemented using `cold_path()`
2024-11-17Likely unlikely fixJiri Bobek-0/+3
2024-11-16stabilize const_ptr_is_nullRalf Jung-0/+6
2024-11-13check_consts: fix error requesting feature gate when that gate is not ↵Ralf Jung-12/+36
actually needed
2024-11-12allow rustc_private feature in force-unstable-if-unmarked cratesRalf Jung-3/+20
2024-11-10ensure that all publicly reachable const fn have const stability infoRalf Jung-17/+20
2024-11-10honor rustc_const_stable_indirect in non-staged_api crate with ↵Ralf Jung-3/+4
-Zforce-unstable-if-unmarked
2024-11-09Rollup merge of #132823 - RalfJung:conditional-const-calls, ↵Jubilee-78/+78
r=fee1-dead,compiler-errors require const_impl_trait gate for all conditional and trait const calls Alternative to https://github.com/rust-lang/rust/pull/132786. `@compiler-errors` this is basically what I meant with my proposals. I found it's easier to express this in code than English. ;) r? `@compiler-errors`