about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2023-11-12interpret: simplify handling of shifts by no longer trying to handle signed ↵Ralf Jung-28/+26
and unsigned shift amounts in the same branch
2023-11-12patterns: don't ice when encountering a raw str sliceRalf Jung-4/+9
2023-11-09Auto merge of #117712 - lcnr:expand-coroutine, r=jackh726bors-7/+7
generator layout: ignore fake borrows fixes #117059 We emit fake shallow borrows in case the scrutinee place uses a `Deref` and there is a match guard. This is necessary to prevent the match guard from mutating the scrutinee: https://github.com/rust-lang/rust/blob/fab1054e1742790c22ccc92a625736d658363677/compiler/rustc_mir_build/src/build/matches/mod.rs#L1250-L1265 These fake borrows end up impacting the generator witness computation in `mir_generator_witnesses`, which causes the issue in #117059. This PR now completely ignores fake borrows during this computation. This is sound as thse are always removed after analysis and the actual computation of the generator layout happens afterwards. Only the second commit impacts behavior, and could be backported by itself. r? types
2023-11-08rename `BorrowKind::Shallow` to `Fake`lcnr-7/+7
also adds some comments
2023-11-08Auto merge of #116930 - RalfJung:raw-ptr-match, r=davidtwcobors-10/+27
patterns: reject raw pointers that are not just integers Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not. This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](https://github.com/rust-lang/rust/pull/116930#issuecomment-1784654073) for some more explanation and context. Also fixes https://github.com/rust-lang/rust/issues/116929. Cc `@oli-obk` `@lcnr`
2023-11-03Auto merge of #117507 - nnethercote:rustc_span, r=Nilstriebbors-3/+3
`rustc_span` cleanups Just some things I found while looking over this crate. r? `@oli-obk`
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-3/+3
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-11-01Rollup merge of #117441 - cjgillot:diag-noassert, r=oli-obk,RalfJungMatthias Krüger-8/+20
Do not assert in op_to_const. `op_to_const` is used in `try_destructure_mir_constant_for_diagnostics`, which may encounter invalid constants created by optimizations and debugging. r? ``@oli-obk`` Fixes https://github.com/rust-lang/rust/issues/117368
2023-11-01Rollup merge of #117373 - saethlin:avoid-ice-lint, r=compiler-errorsMatthias Krüger-8/+4
Avoid the path trimming ICE lint in error reporting Types or really anything in MIR should never be formatted without path trimming disabled, because its formatting often tries to construct trimmed paths. In this case, the lint turns a nice error report into an irrelevant ICE.
2023-11-01Comment `for_diagnostics` flag.Camille GILLOT-0/+5
2023-11-01Specify diagnostic path.Camille GILLOT-6/+13
2023-11-01Rename hook.Camille GILLOT-3/+3
2023-11-01Do not assert in op_to_const.Camille GILLOT-2/+2
2023-11-01Avoid the path trimming ICE lint in error reportingBen Kimock-8/+4
2023-11-01Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiserbors-13/+12
Support enum variants in offset_of! This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like ```rust offset_of!(Type, field.Variant.field) ``` Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful. [RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant) Tracking Issue #106655.
2023-10-31Enums in offset_of: update based on est31, scottmcm & llogiq reviewGeorge Bateman-24/+12
2023-10-31Support enum variants in offset_of!George Bateman-12/+23
2023-10-31Turn const_caller_location from a query to a hookOli Scherer-6/+9
2023-10-30Rollup merge of #117317 - RalfJung:track-caller, r=oli-obkGuillaume Gomez-158/+135
share some track_caller logic between interpret and codegen Also move the code that implements the track_caller intrinsics out of the core interpreter engine -- it's just a helper creating a const-allocation, doesn't need to be part of the interpreter core.
2023-10-29Auto merge of #116270 - cjgillot:gvn-aggregate, r=oli-obk,RalfJungbors-9/+58
See through aggregates in GVN This PR is extracted from https://github.com/rust-lang/rust/pull/111344 The first 2 commit are cleanups to avoid repeated work. I propose to stop removing useless assignments as part of this pass, and let a later `SimplifyLocals` do it. This makes tests easier to read (among others). The next 3 commits add a constant folding mechanism to the GVN pass, presented in https://github.com/rust-lang/rust/pull/116012. ~This pass is designed to only use global allocations, to avoid any risk of accidental modification of the stored state.~ The following commits implement opportunistic simplifications, in particular: - projections of aggregates: `MyStruct { x: a }.x` gets replaced by `a`, works with enums too; - projections of arrays: `[a, b][0]` becomes `a`; - projections of repeat expressions: `[a; N][x]` becomes `a`; - transform arrays of equal operands into a repeat rvalue. Fixes https://github.com/rust-lang/miri/issues/3090 r? `@oli-obk`
2023-10-28patterns: reject raw pointers that are not just integersRalf Jung-10/+27
2023-10-28share the track_caller handling within a mir::BodyRalf Jung-29/+11
2023-10-28interpret: call caller_location logic the same way codegen does, and share ↵Ralf Jung-158/+153
some code
2023-10-25Rename has_provance and tweaks comments.Camille GILLOT-1/+4
2023-10-25Refactor away the need for some `descr` methods.Oli Scherer-1/+1
Instead we use `Display` impls and their `alternate` render scheme to decide whether we want backticks or not.
2023-10-25Rename `AsyncCoroutineKind` to `CoroutineSource`Oli Scherer-2/+2
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-25Take an AllocId in intern_const_alloc_for_constprop.Camille GILLOT-2/+1
2023-10-25Move provenance checks out of interning method.Camille GILLOT-13/+3
2023-10-25Directly intern values instead of copying them.Camille GILLOT-1/+47
2023-10-25Evaluate computed values to constants.Camille GILLOT-7/+18
2023-10-24Rollup merge of #117081 - GoodDaisy:master, r=wesleywiserMatthias Krüger-1/+1
fix typos in comments
2023-10-23Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obkMatthias Krüger-41/+44
Make `ty::print::Printer` take `&mut self` instead of `self` based on #116815 This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-23fix typos in commentsGoodDaisy-1/+1
2023-10-23Ensure that `eval_to_allocation_raw` isn't called on static items from miriOli Scherer-9/+6
2023-10-23Split `eval_to_allocation_raw_provider`Oli Scherer-2/+9
2023-10-23Pull out const error reporting into its own functionOli Scherer-31/+32
2023-10-23Pull mplace validation logic out into an interpreter methodOli Scherer-21/+33
2023-10-23The mutability was ignored anyway, so just check for staticnessOli Scherer-4/+7
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-41/+44
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-20Rename `CoroutineKind::Gen` to `::Coroutine`Oli Scherer-1/+1
2023-10-20s/generator/coroutine/Oli Scherer-26/+26
2023-10-20s/Generator/Coroutine/Oli Scherer-40/+40
2023-10-20Adjust importsMichael Goulet-3/+3
2023-10-19Auto merge of #115214 - Urgau:rfc-3127-trim-paths, r=compiler-errorsbors-1/+9
Implement rustc part of RFC 3127 trim-paths This PR implements (or at least tries to) [RFC 3127 trim-paths](https://github.com/rust-lang/rust/issues/111540), the rustc part. That is `-Zremap-path-scope` with all of it's components/scopes. `@rustbot` label: +F-trim-paths
2023-10-19Rollup merge of #116650 - RalfJung:miri-intptrcast, r=oli-obkMatthias Krüger-0/+10
add some comments and some cleanup around Miri intptrcast `@saethlin` maybe this helps a bit?
2023-10-18Auto merge of #116815 - Nilstrieb:more-funny-pretty-printers, r=compiler-errorsbors-25/+17
Remove lots of generics from `ty::print` All of these generics mostly resolve to the same thing, which means we can remove them, greatly simplifying the types involved in pretty printing and unlocking another simplification (that is not performed in this PR): Using `&mut self` instead of passing `self` through the return type. cc `@eddyb` you probably know why it's like this, just checking in and making sure I didn't do anything bad r? oli-obk
2023-10-17Remove `Print::Error`Nilstrieb-1/+1
All printing goes through `fmt::Error` now.
2023-10-17Remove `Printer::Error`Nilstrieb-19/+17
It's always a `fmt::Error` except in some cases where it was `!`, but we're not really winning anything in that case.
2023-10-17Remove `Print::Output`Nilstrieb-1/+1
Now that `Printer` doesn't have subprinters anymore, the output of a printing operation is always the same.
2023-10-17Remove "subprinter" types from `Printer`Nilstrieb-18/+12
These are `Self` in almost all printers except one, which can just store the state as a field instead. This simplifies the printer and allows for further simplifications, for example using `&mut self` instead of passing around the printer.