about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2025-01-07Avoid naming variables `str`Josh Triplett-4/+4
This renames variables named `str` to other names, to make sure `str` always refers to a type. It's confusing to read code where `str` (or another standard type name) is used as an identifier. It also produces misleading syntax highlighting.
2025-01-04rustc_intrinsic: support functions without body; they are implicitly marked ↵Ralf Jung-1/+2
as must-be-overridden
2024-12-30Auto merge of #134757 - RalfJung:const_swap, r=scottmcmbors-46/+29
stabilize const_swap libs-api FCP passed in https://github.com/rust-lang/rust/issues/83163. However, I only just realized that this actually involves an intrinsic. The intrinsic could be implemented entirely with existing stable const functionality, but we choose to make it a primitive to be able to detect more UB. So nominating for `@rust-lang/lang` to make sure they are aware; I leave it up to them whether they want to FCP this. While at it I also renamed the intrinsic to make the "nonoverlapping" constraint more clear. Fixes #83163
2024-12-27Rollup merge of #134787 - fmease:spruce-up-queries, r=compiler-errors许杰友 Jieyou Xu (Joe)-10/+4
Spruce up the docs of several queries related to the type/trait system and const eval - Editorial - Proper rustdoc summary/synopsis line by making use of extra paragraphs: Leads to better rendered output on module pages, in search result lists and overall, too - Use rustdoc warning blocks for admonitions of the form "do not call / avoid calling this query directly" - Use intra-doc links of the form ``[`Self::$query`]`` to cross-link queries. Indeed, such links are generally a bit brittle due to the existence of `TyCtxtFeed` which only contains a subset of queries. Therefore the docs of `feedable` queries cannot cross-link to non-`feedable` ones. I'd say it's fine to use intra-doc links despite the potential/unlikely occasional future breakage (if a query with the aforementioned characteristics becomes `feedable`). `Self::` is nicer than `TyCtxt::` (which would be more stable) since it accounts for other contexts like `TyCtxt{Feed,At,Ensure{,WithValue}}` - Informative - Generally add, flesh out and correct some doc comments - Add *Panic* sections (to a few selected queries only). The lists of panics aren't necessarily exhaustive and focus on the more "obvious" or "important" panics. - Where applicable add a paragraph calling attention to the relevant [`#[rustc_*]` TEST attribute](https://rustc-dev-guide.rust-lang.org/compiler-debugging.html#rustc_-test-attributes) The one non-doc change (it's internal and not observable): Be even more defensive in `query constness`'s impl (spiritual follow-up to #134122) (see self review comment). Fixes #133494. r\? **any**(compiler-errors, oli-obk)
2024-12-27Rollup merge of #134606 - RalfJung:ptr-copy-docs, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-0/+2
ptr::copy: fix docs for the overlapping case Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/549 As discussed in that issue, it doesn't make any sense for `copy` to read a byte via `src` after it was already written via `dst`. The entire point of this method is that is copies correctly even if they overlap, and that requires always reading any given location before writing it. Cc `@rust-lang/opsem`
2024-12-27Spruce up the docs of several queries related to the type/trait system and ↵León Orell Valerian Liehr-10/+4
const eval
2024-12-25swap_typed_nonoverlapping: properly detect overlap even when swapping scalar ↵Ralf Jung-45/+28
values
2024-12-25rename typed_swap → typed_swap_nonoverlappingRalf Jung-1/+1
2024-12-25miri: add test for overlapping typed_swapRalf Jung-1/+1
2024-12-24Auto merge of #134716 - Zalathar:rollup-1h4q8cc, r=Zalatharbors-0/+2
Rollup of 5 pull requests Successful merges: - #134638 (Fix effect predicates from item bounds in old solver) - #134662 (Fix safety docs for `dyn Any + Send {+ Sync}`) - #134689 (core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets) - #134699 (Belay new reviews for workingjubilee) - #134701 (Correctly note item kind in `NonConstFunctionCall` error message) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-24Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obkbors-3/+12
Begin to implement type system layer of unsafe binders Mostly TODOs, but there's a lot of match arms that are basically just noops so I wanted to split these out before I put up the MIR lowering/projection part of this logic. r? oli-obk Tracking: - https://github.com/rust-lang/rust/issues/130516
2024-12-23Note def descr in NonConstFunctionCallMichael Goulet-0/+2
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-3/+12
2024-12-22Delete `Rvalue::Len`Scott McMurray-13/+3
Everything's moved to `PtrMetadata` instead.
2024-12-21ptr::copy: fix docs for the overlapping caseRalf Jung-0/+2
2024-12-20Auto merge of #134550 - jhpratt:rollup-wsfmo59, r=jhprattbors-9/+13
Rollup of 6 pull requests Successful merges: - #126118 (docs: Mention `spare_capacity_mut()` in `Vec::set_len`) - #132830 (Rename `elem_offset` to `element_offset`) - #133103 (Pass FnAbi to find_mir_or_eval_fn) - #134321 (Hide `= _` as associated constant value inside impl blocks) - #134518 (fix typos in the example code in the doc comments of `Ipv4Addr::from_bits()`, `Ipv6Addr::from_bits()` & `Ipv6Addr::to_bits()`) - #134521 (Arbitrary self types v2: roll loop.) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-20Rollup merge of #133103 - tiif:fnabi, r=RalfJungJacob Pratt-9/+13
Pass FnAbi to find_mir_or_eval_fn https://github.com/rust-lang/miri/issues/4013 needs information from ``FnAbi``, hence it is passed to ``find_mir_or_eval_fn``. r? `@RalfJung`
2024-12-20Auto merge of #134438 - lqd:const-qualif-bitsets, r=compiler-errorsbors-5/+7
Use `MixedBitSet`s in const qualif These analyses' domains should be very homogeneous, having compressed bitmaps on huge cfgs should make a difference (and doesn’t have an impact on the smaller / regular cfgs in our benchmarks). This is a >40% walltime reduction on [this stress test](https://github.com/Manishearth/icu4x_compile_sample) extracted from a real world ICU case, and a 10x or so max-rss reduction. cc `@oli-obk` `@RalfJung` Should help with (or fix) issue #134404.
2024-12-19Pass FnAbi to find_mir_or_eval_fntiif-9/+13
2024-12-19Rollup merge of #133702 - RalfJung:single-variant, r=oli-obk许杰友 Jieyou Xu (Joe)-17/+18
Variants::Single: do not use invalid VariantIdx for uninhabited enums ~~Stacked on top of https://github.com/rust-lang/rust/pull/133681, only the last commit is new.~~ Currently, `Variants::Single` for an empty enum contains a `VariantIdx` of 0; looking that up in the enum variant list will ICE. That's quite confusing. So let's fix that by adding a new `Variants::Empty` case for types that have 0 variants. try-job: i686-msvc
2024-12-18Auto merge of #134443 - joshtriplett:use-field-init-shorthand, ↵bors-1/+1
r=lqd,tgross35,nnethercote Use field init shorthand where possible Field init shorthand allows writing initializers like `tcx: tcx` as `tcx`. The compiler already uses it extensively. Fix the last few places where it isn't yet used. EDIT: this PR also updates `rustfmt.toml` to set `use_field_init_shorthand = true`.
2024-12-18make no-variant types a dedicated Variants variantRalf Jung-9/+13
2024-12-18Variants::Single: do not use invalid VariantIdx for uninhabited enumsRalf Jung-15/+12
2024-12-18make const qualif use mixed bitsets instead of dense bitsetsRémy Rakic-5/+7
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-9/+7
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-17Use field init shorthand where possibleJosh Triplett-1/+1
Field init shorthand allows writing initializers like `tcx: tcx` as `tcx`. The compiler already uses it extensively. Fix the last few places where it isn't yet used.
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-2/+2
2024-12-15Rollup merge of #134285 - oli-obk:push-vwrqsqlwnuxo, r=UrgauStuart Cook-3/+2
Add some convenience helper methods on `hir::Safety` Makes a lot of call sites simpler and should make any refactorings needed for https://github.com/rust-lang/rust/pull/134090#issuecomment-2541332415 simpler, as fewer sites have to be touched in case we end up storing some information in the variants of `hir::Safety`
2024-12-14Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵bors-7/+31
r=davidtwco,RalfJung Bounds-check with PtrMetadata instead of Len in MIR Rather than emitting `Len(*_n)` in array index bounds checks, emit `PtrMetadata(copy _n)` instead -- with some asterisks for arrays and `&mut` that need it to be done slightly differently. We're getting pretty close to removing `Len` entirely, actually. I think just one more PR after this (for slice drop shims). r? mir
2024-12-14Add some convenience helper methods on `hir::Safety`Oli Scherer-3/+2
2024-12-14Rollup merge of #134191 - willcrichton:dev, r=RalfJung,lqdMatthias Krüger-12/+27
Make some types and methods related to Polonius + Miri public We have a tool, [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/), which uses Polonius and Miri to visualize the compile-time and run-time semantics of a Rust program. Changes in the last few months to both APIs have hidden away details we depend upon. This PR re-exposes some of those details, specifically: **Polonius:** - `BorrowSet` and `BorrowData` are added to `rustc_borrowck::consumers`, and their fields are made `pub` instead of `pub(crate)`. We need this to interpret the `BorrowIndex`es generated by Polonius. - `BorrowSet::build` is now `pub`. We need this because the borrowck API doesn't provide access to the `BorrowSet` constructed during checking. - `PoloniusRegionVid` is added to `rustc_borrowck::consumers`. We need this because it's also contained in the Polonius facts. **Miri:** - `InterpCx::local_to_op` is now a special case of `local_at_frame_to_op`, which allows querying locals in any frame. We need this because we walk the whole stack at each step to collect the state of memory. - `InterpCx::layout_of_local` is now `pub`. We need this because we need to know the layout of every local at each step. If these changes go against some design goal for keeping certain types private, please let me know so we can hash out a better solution. Additionally, if there's a better way to document that it's important that certain types stay public, also let me know. For example, `BorrowSet` was previously public but was hidden in 6676cec, breaking our build. cc ```@RalfJung``` ```@nnethercote``` ```@gavinleroy```
2024-12-13Update compiler/rustc_const_eval/src/interpret/step.rsscottmcm-1/+3
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-12-13Auto merge of #134269 - matthiaskrgr:rollup-fkshwux, r=matthiaskrgrbors-10/+11
Rollup of 7 pull requests Successful merges: - #133900 (Advent of `tests/ui` (misc cleanups and improvements) [1/N]) - #133937 (Keep track of parse errors in `mod`s and don't emit resolve errors for paths involving them) - #133938 (`rustc_mir_dataflow` cleanups, including some renamings) - #134058 (interpret: reduce usage of TypingEnv::fully_monomorphized) - #134130 (Stop using driver queries in the public API) - #134140 (Add AST support for unsafe binders) - #134229 (Fix typos in docs on provenance) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-13Rollup merge of #134058 - RalfJung:interpret-typing-env, r=lcnrMatthias Krüger-8/+9
interpret: reduce usage of TypingEnv::fully_monomorphized r? `@lcnr`
2024-12-13Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r=oli-obkMatthias Krüger-2/+2
`rustc_mir_dataflow` cleanups, including some renamings Some opinionated commits in this collection, let's see how we go. r? `@cjgillot`
2024-12-13Don't retag the `PtrMetadata(&raw const *_n)` in slice indexingScott McMurray-2/+9
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