about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
AgeCommit message (Collapse)AuthorLines
2024-09-13ProjectionElem and UnOp/BinOp dont need to be PartialOrd/OrdMichael Goulet-3/+3
2024-09-13Auto merge of #107251 - dingxiangfei2009:let-chain-rescope, r=jieyouxubors-0/+3
Rescope temp lifetime in if-let into IfElse with migration lint Tracking issue #124085 This PR shortens the temporary lifetime to cover only the pattern matching and consequent branch of a `if let`. At the expression location, means that the lifetime is shortened from previously the deepest enclosing block or statement in Edition 2021. This warrants an Edition change. Coming with the Edition change, this patch also implements an edition lint to warn about the change and a safe rewrite suggestion to preserve the 2021 semantics in most cases. Related to #103108. Related crater runs: https://github.com/rust-lang/rust/pull/129466.
2024-09-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-21/+17
Simplify some nested `if` statements Applies some but not all instances of `clippy::collapsible_if`. Some ended up looking worse afterwards, though, so I left those out. Also applies instances of `clippy::collapsible_else_if` Review with whitespace disabled please.
2024-09-11Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errorsJubilee-4/+3
Remove needless returns detected by clippy in the compiler
2024-09-11Also fix if in elseMichael Goulet-5/+3
2024-09-11Simplify some nested if statementsMichael Goulet-16/+14
2024-09-11rescope temp lifetime in let-chain into IfElseDing Xiang Fei-0/+3
apply rules by span edition
2024-09-10const-eval interning: accpt interior mutable pointers in final value (but ↵Ralf Jung-4/+43
keep rejecting mutable references)
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-4/+3
2024-09-08interpret: reset provenance on typed copiesRalf Jung-0/+13
2024-09-06Auto merge of #129999 - matthiaskrgr:rollup-pzr9c8p, r=matthiaskrgrbors-0/+3
Rollup of 11 pull requests Successful merges: - #128919 (Add an internal lint that warns when accessing untracked data) - #129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined) - #129653 (clarify that addr_of creates read-only pointers) - #129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails) - #129939 (explain why Rvalue::Len still exists) - #129942 (copy rustc rustlib artifacts from ci-rustc) - #129943 (use the bootstrapped compiler for `test-float-parse` test) - #129944 (Add compat note for trait solver change) - #129947 (Add digit separators in `Duration` examples) - #129955 (Temporarily remove fmease from the review rotation) - #129957 (forward linker option to lint-docs) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-05Rollup merge of #129939 - RalfJung:rvalue-len, r=compiler-errorsMatthias Krüger-0/+3
explain why Rvalue::Len still exists I just spent a bit of time trying to remove this until I realized why that's non-trivial. Let's document that for the next person. :)
2024-09-05Rollup merge of #129706 - compiler-errors:scratch, r=estebankMatthias Krüger-1/+3
Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir First, we add a missing match for `DefKind::SyntheticCoroutineBody` in `dump_mir`. Fixes #129703. The second commit (directly below) serves as a test. Second, we reorder the `dump_mir` in `coroutine_by_move_body_def_id` to be *after* we adjust the body source, and change the disambiguator so it reads more like any other MIR body. This also serves as a test for the ICE, since we're dumping the MIR of a body with `DefKind::SyntheticCoroutineBody`. Third, we change the parenting of the synthetic MIR body to have the *coroutine-closure* (i.e. async closure) as its parent, so we don't have long strings of `{closure#0}-{closure#0}-{closure#0}`. try-job: test-various
2024-09-03Don't ICE when dumping MIR of a synthetic coroutine bodyMichael Goulet-1/+3
2024-09-03explain why Rvalue::Len still existsRalf Jung-0/+3
2024-09-03Rollup merge of #129926 - nnethercote:mv-SanityCheck-and-MirPass, r=cjgillotMatthias Krüger-62/+0
Move `SanityCheck` and `MirPass` They are currently in `rustc_middle`. This PR moves them to `rustc_mir_transform`, which makes more sense. r? ``@cjgillot``
2024-09-03Move `MirPass` to `rustc_mir_transform`.Nicholas Nethercote-62/+0
Because that's now the only crate that uses it. Moving stuff out of `rustc_middle` is always welcome. I chose to use `impl crate::MirPass`/`impl crate::MirLint` (with explicit `crate::`) everywhere because that's the only mention of `MirPass`/`MirLint` used in all of these files. (Prior to this change, `MirPass` was mostly imported via `use rustc_middle::mir::*` items.)
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-4/+4
2024-08-31Auto merge of #129831 - matthiaskrgr:rollup-befq6zx, r=matthiaskrgrbors-1/+2
Rollup of 11 pull requests Successful merges: - #128523 (Add release notes for 1.81.0) - #129605 (Add missing `needs-llvm-components` directives for run-make tests that need target-specific codegen) - #129650 (Clean up `library/profiler_builtins/build.rs`) - #129651 (skip stage 0 target check if `BOOTSTRAP_SKIP_TARGET_SANITY` is set) - #129684 (Enable Miri to pass pointers through FFI) - #129762 (Update the `wasm-component-ld` binary dependency) - #129782 (couple more crash tests) - #129816 (tidy: say which feature gate has a stability issue mismatch) - #129818 (make the const-unstable-in-stable error more clear) - #129824 (Fix code examples buttons not appearing on click on mobile) - #129826 (library: Fix typo in `core::mem`) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-31Rollup merge of #129684 - Strophox:miri-pass-pointer-to-ffi, r=RalfJungMatthias Krüger-1/+2
Enable Miri to pass pointers through FFI Following https://github.com/rust-lang/rust/pull/126787, the purpose of this PR is to now enable Miri to execute native calls that make use of pointers. > <details> > > <summary> Simple example </summary> > > ```rust > extern "C" { > fn ptr_printer(ptr: *mut i32); > } > > fn main() { > let ptr = &mut 42 as *mut i32; > unsafe { > ptr_printer(ptr); > } > } > ``` > ```c > void ptr_printer(int *ptr) { > printf("printing pointer dereference from C: %d\n", *ptr); > } > ``` > should now show `printing pointer dereference from C: 42`. > > </details> Note that this PR does not yet implement any logic involved in updating Miri's "analysis" state (byte initialization, provenance) upon such a native call. r? ``@RalfJung``
2024-08-30enable Miri to pass const pointers through FFIStrophox-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-08-30make `-Z mir-include-spans` a dedicated enumRémy Rakic-1/+1
We want to allow setting this on the CLI, override it only in MIR passes, and disable it altogether in mir-opt tests. The default value is "only for NLL MIR dumps", which is considered off for all intents and purposes, except for `rustc_borrowck` when an NLL MIR dump is requested.
2024-08-30introduce `PrettyPrintMirOptions` for cosmetic MIR dump optionsRémy Rakic-27/+89
initially starting with `-Z mir-include-spans` because we want them in the NLL mir dump pass
2024-08-29Add `warn(unreachable_pub)` to `rustc_middle`.Nicholas Nethercote-5/+5
I am surprised the diff is so small for this enormous crate.
2024-08-28coverage: Rename `CodeRegion` to `SourceRegion`Zalathar-5/+5
LLVM uses the word "code" to refer to a particular kind of coverage mapping. This unrelated usage of the word is confusing, and makes it harder to introduce types whose names correspond to the LLVM classification of coverage kinds.
2024-08-26Stop using a special inner body for the coroutine by-move body for async ↵Michael Goulet-19/+0
closures
2024-08-25Rollup merge of #129091 - RalfJung:box_as_ptr, r=AmanieuMatthias Krüger-4/+2
add Box::as_ptr and Box::as_mut_ptr methods Unstably implements https://github.com/rust-lang/libs-team/issues/355. Tracking issue: https://github.com/rust-lang/rust/issues/129090. r? libs-api
2024-08-21fix comment on PlaceMention semanticsRalf Jung-1/+1
2024-08-21fix link in mir/modkyoto7250-1/+1
change url path when rewrite those code
2024-08-19Auto merge of #122551 - RayMuir:copy_fmt, r=saethlinbors-1/+1
Added "copy" to Debug fmt for copy operands In MIR's debug mode (--emit mir) the printing for Operands is slightly inconsistent. The RValues - values on the right side of an Assign - are usually printed with their Operand when they are Places. Example: _2 = move _3 But for arguments, the operand is omitted. _2 = _1 I propose a change be made, to display the place with the operand. _2 = copy _1 Move and copy have different semantics, meaning this difference is important and helpful to the user. It also adds consistency to the pretty printing. -- EDIT -- Consider this example Rust program and its MIR output with the **updated pretty printer.** This was generated with the arguments --emit mir --crate-type lib -Zmir-opt-level=0 (Otherwise, it's optimised away since it's a junk program). ```rust fn main(foo: i32) { let v = 10; if v == 20 { foo; } else { v; } } ``` ```MIR // WARNING: This output format is intended for human consumers only // and is subject to change without notice. Knock yourself out. fn main(_1: i32) -> () { debug foo => _1; let mut _0: (); let _2: i32; let mut _3: bool; let mut _4: i32; let _5: i32; let _6: i32; scope 1 { debug v => _2; } bb0: { StorageLive(_2); _2 = const 10_i32; StorageLive(_3); StorageLive(_4); _4 = copy _2; _3 = Eq(move _4, const 20_i32); switchInt(move _3) -> [0: bb2, otherwise: bb1]; } bb1: { StorageDead(_4); StorageLive(_5); _5 = copy _1; StorageDead(_5); _0 = const (); goto -> bb3; } bb2: { StorageDead(_4); StorageLive(_6); _6 = copy _2; StorageDead(_6); _0 = const (); goto -> bb3; } bb3: { StorageDead(_3); StorageDead(_2); return; } } ``` In this example program, we can see that when we move a place, it is preceded by "move". e.g. ``` _3 = Eq(move _4, const 20_i32);```. However, when we copy a place such as ```_5 = _1;```, it is not preceded by the operand in the original printout. I propose to change the print to include the copy ```_5 = copy _1``` as in this example. Regarding the arguments part. When I originally submitted this PR, I was under the impression this only affected the print for arguments to a function, but actually, it affects anything that uses a copy. This is preferable anyway with regard to consistency. The PR is about making ```copy``` explicit.
2024-08-18Added "copy" to Debug fmt for copy operandsRayMuir-1/+1
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-16/+16
2024-08-16mir/pretty: use `Option` instead of `Either<Once, Empty>`Josh Stone-9/+9
`Either` is wasteful for a one-or-none iterator, especially since `Once` is already an `option::IntoIter` internally. We don't really need any of the iterator mechanisms in this case, just a single conditional insert.
2024-08-14use the new Box methods in the interpreterRalf Jung-4/+2
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-94/+51
2024-08-02Rollup merge of #128494 - RalfJung:mir-lazy-lists, r=compiler-errorsMatthias Krüger-9/+47
MIR required_consts, mentioned_items: ensure we do not forget to fill these lists Bodies initially get created with empty required_consts and mentioned_items, but at some point those should be filled. Make sure we notice when that is forgotten.
2024-08-01MIR required_consts, mentioned_items: ensure we do not forget to fill these ↵Ralf Jung-9/+47
lists
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-88/+12
2024-08-01on a signed deref check, mention the right pointer in the errorRalf Jung-9/+7
2024-07-29Rollup merge of #128277 - RalfJung:offset_from_wildcard, r=oli-obkMatthias Krüger-6/+14
miri: fix offset_from behavior on wildcard pointers offset_from wouldn't behave correctly when the "end" pointer was a wildcard pointer (result of an int2ptr cast) just at the end of the allocation. Fix that by expressing the "same allocation" check in terms of two `check_ptr_access_signed` instead of something specific to offset_from, which is both more canonical and works better with wildcard pointers. The second commit just improves diagnostics: I wanted the "pointer is dangling (has no provenance)" message to say how many bytes of memory it expected to see (since if it were 0 bytes, this would actually be legal, so it's good to tell the user that it's not 0 bytes). And then I was annoying that the error looks so different for when you deref a dangling pointer vs an out-of-bounds pointer so I made them more similar. Fixes https://github.com/rust-lang/miri/issues/3767
2024-07-29Reformat `use` declarations.Nicholas Nethercote-139/+122
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27improve dangling/oob errors and make them more uniformRalf Jung-6/+14
2024-07-25Auto merge of #127042 - GrigorenkoPV:derivative, r=compiler-errorsbors-9/+4
Switch from `derivative` to `derive-where` This is a part of the effort to get rid of `syn 1.*` in compiler's dependencies: #109302 Derivative has not been maintained in nearly 3 years[^1]. It also depends on `syn 1.*`. This PR replaces `derivative` with `derive-where`[^2], a not dead alternative, which uses `syn 2.*`. A couple of `Debug` formats have changed around the skipped fields[^3], but I doubt this is an issue. [^1]: https://github.com/mcarton/rust-derivative/issues/117 [^2]: https://lib.rs/crates/derive-where [^3]: See the changes in `tests/ui`
2024-07-22Auto merge of #127442 - saethlin:alloc-decoding-lock, r=oli-obkbors-89/+25
Try to fix ICE from re-interning an AllocId with different allocation contents As far as I can tell, based on my investigation in https://github.com/rust-lang/rust/issues/126741, the racy decoding scheme implemented here was never fully correct, but the arrangement of Allocations that's required to ICE the compiler requires some very specific MIR optimizations to create. As far as I can tell, GVN likes to create the problematic pattern, which is why we're noticing this problem now. So the solution here is to not do racy decoding. If two threads race to decoding an AllocId, one of them is going to sit on a lock until the other is done.
2024-07-21Explain why the new setup can't deadlockBen Kimock-1/+13
2024-07-18valtree construction: keep track of which type was valtree-incompatibleRalf Jung-3/+5
2024-07-17Remove in-progress allocation decoding statesBen Kimock-89/+13
2024-07-16Auto merge of #127638 - adwinwhite:cache_string, r=oli-obkbors-6/+11
Add cache for `allocate_str` Best effort cache for string allocation in const eval. Fixes [rust-lang/miri#3470](https://github.com/rust-lang/miri/issues/3470).
2024-07-15Rollup merge of #127758 - Zalathar:expression-used, r=oli-obkMatthias Krüger-13/+0
coverage: Restrict `ExpressionUsed` simplification to `Code` mappings In the future, branch and MC/DC mappings might have expressions that don't correspond to any single point in the control-flow graph. That makes it trickier to keep track of which expressions should expect an `ExpressionUsed` node. We therefore sidestep that complexity by only performing `ExpressionUsed` simplification for expressions associated directly with ordinary `Code` mappings. (This simplification step is inherited from the original coverage implementation, which only supported `Code` mappings anyway, so there's no particular reason to extend it to other kinds of mappings unless we specifically choose to.) Relevant to: - #124154 - #126677 - #124278 ```@rustbot``` label +A-code-coverage
2024-07-15coverage: Restrict `ExpressionUsed` simplification to `Code` mappingsZalathar-13/+0
In the future, branch and MC/DC mappings might have expressions that don't correspond to any single point in the control-flow graph. That makes it trickier to keep track of which expressions should expect an `ExpressionUsed` node. We therefore sidestep that complexity by only performing `ExpressionUsed` simplification for expressions associated directly with ordinary `Code` mappings.