about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
AgeCommit message (Collapse)AuthorLines
2025-01-30Auto merge of #136035 - SpecificProtagonist:miri-zeroed-alloc, r=oli-obkbors-8/+22
miri: optimize zeroed alloc When allocating zero-initialized memory in MIR interpretation, rustc allocates zeroed memory, marks it as initialized and then re-zeroes it. Remove the last step. I don't expect this to have much of an effect on performance normally, but in my case in which I'm creating a large allocation via mmap it gets in the way.
2025-01-28Rollup merge of #135748 - compiler-errors:len-2, r=RalfJung,oli-obkMatthias Krüger-5/+62
Lower index bounds checking to `PtrMetadata`, this time with the right fake borrow semantics 😸 Change `Rvalue::RawRef` to take a `RawRefKind` instead of just a `Mutability`. Then introduce `RawRefKind::FakeForPtrMetadata` and use that for lowering index bounds checking to a `PtrMetadata`. This new `RawRefKind::FakeForPtrMetadata` acts like a shallow fake borrow in borrowck, which mimics the semantics of the old `Rvalue::Len` operation we're replacing. We can then use this `RawRefKind` instead of using a span desugaring hack in CTFE. cc ``@scottmcm`` ``@RalfJung``
2025-01-28miri: optimize zeroed allocSpecificProtagonist-8/+22
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-01-28Auto merge of #133929 - saethlin:remove-inline-in-all-cgus, r=nnethercotebors-9/+4
Remove -Zinline-in-all-cgus and clean up tests/codegen-units/ Implementation of https://github.com/rust-lang/compiler-team/issues/814 I've taken some liberties with cleaning up the CGU partitioning tests, because that's the only place this flag was used and also mattered. I've often fought a lot with the contents of `tests/codegen-units` and it has never been clear to me when a test failure indicates a problem with my changes as opposed to a test just needing to be manually blessed. Hopefully the combination of the new README, new comments, and using `-Zprint-mono-items=lazy` in the partitioning tests improves that. I've also deleted some of the `tests/run-make/sepcomp` tests. I think all the "sepcomp" tests have been obviated for years by better-designed (less flaky, clearer failures) test suites, but here I'm just deleting the ones I'm confident in.
2025-01-27Remove -Zinline-in-all-cgus and clean up CGU partitioning testsBen Kimock-9/+4
2025-01-28Represent the raw pointer for a array length check as a new kind of fake borrowMichael Goulet-5/+62
2025-01-27Change `collect_and_partition_mono_items` tuple return type to a structOli Scherer-1/+7
2025-01-26Auto merge of #135753 - compiler-errors:from-ty-const, r=oli-obkbors-11/+0
Get rid of `mir::Const::from_ty_const` This function is strange, because it turns valtrees into `mir::Const::Value`, but the rest of the const variants stay as type system consts. All of the callsites except for one in `instsimplify` (array length simplification of `ptr_metadata` call) just go through the valtree arm of the function, so it's easier to just create a `mir::Const` directly for those. For the instsimplify case, if we have a type system const we should *keep* having a type system const, rather than turning it into a `mir::Const::Value`; it doesn't really matter in practice, though, bc `usize` has no padding, but it feels more principled.
2025-01-25Rollup merge of #136031 - lqd:polonius-debugger-episode-1, r=compiler-errorsJacob Pratt-23/+46
Expand polonius MIR dump This PR starts expanding the polonius MIR: - switches to an HTML file, to show graphs in the same document as the MIR dump, share them more easily since it's a single file that can be hosted as a gist, and also to allow for interactivity in the near future. - adds the regular NLL MIR + polonius constraints - embeds a mermaid version of the CFG, similar to the graphviz one, but that needs a smaller js than `dot`'s emscripten js from graphvizonline [Here's an example](https://gistpreview.github.io/?0c18f2a59b5e24ac0f96447aa34ffe00) of how it looks. --- In future PRs: mermaid graphs of the NLL region graph, of the NLL SCCs, of the polonius localized outlives constraints, and the interactive polonius MIR dump. r? ```@matthewjasper```
2025-01-25Rollup merge of #135951 - yotamofek:use-debug-helpers, r=SparrowLiiJacob Pratt-49/+19
Use `fmt::from_fn` in more places in the compiler Use the unstable functions from #117729 in more places in the compiler, follow up to #135494
2025-01-25fix terminator edges commentsRémy Rakic-2/+4
2025-01-25extract principal MIR dump functionRémy Rakic-21/+42
for cases where we want to dump the MIR to a given writer instead of a new file as the default does. this will be used when dumping the MIR to a buffer to process differently, e.g. post-process to escape for an HTML dump.
2025-01-24use `fmt::from_fn` in more places, instead of using structs that impl ↵Yotam Ofek-49/+19
formatting traits
2025-01-24Exclude `mir::coverage` types from TypeFoldable/TypeVisitableZalathar-15/+26
These types are unlikely to ever contain type information in the foreseeable future, so excluding them from TypeFoldable/TypeVisitable avoids some unhelpful derive boilerplate.
2025-01-21Also generate undef scalars and scalar pairsOli Scherer-1/+1
2025-01-20Get rid of mir::Const::from_ty_constMichael Goulet-11/+0
2025-01-19Manual cleanup of some `is_{or_none|some_and}` usagesYotam Ofek-1/+1
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-2/+2
2025-01-19Auto merge of #135709 - lqd:bring-back-len, r=compiler-errorsbors-3/+21
Temporarily bring back `Rvalue::Len` r? `@compiler-errors` as requested in https://github.com/rust-lang/rust/issues/135671#issuecomment-2599580364 > However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔 Agreed. To fix the IMO P-critical #135671 for which we somehow didn't have test coverage, this PR temporarily reverts: - https://github.com/rust-lang/rust/pull/133734 - its bugfix https://github.com/rust-lang/rust/pull/134371 - https://github.com/rust-lang/rust/pull/134330 cc `@scottmcm` I added the few samples from that issue as a test, but we can add more in the future, in particular it seems `@steffahn` [will work on that](https://github.com/rust-lang/rust/issues/135671#issuecomment-2599714354). Fixes #135671. And if we want to land this, it should also be nominated for beta backport.
2025-01-18Revert "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵Rémy Rakic-3/+0
r=davidtwco,RalfJung" This reverts commit b57d93d8b9525fa261404b4cd9c0670eeb1264b8, reversing changes made to 0aeaa5eb22180fdf12a8489e63c4daa18da6f236.
2025-01-18Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"Rémy Rakic-0/+21
This reverts commit e108481f74ff123ad98a63bd107a18d13035b275, reversing changes made to 303e8bd768526a5812bb1776e798e829ddb7d3ca.
2025-01-18coverage: Remove `BcbCounter` and `BcbExpression`Zalathar-6/+2
Making these separate types from `CovTerm` and `Expression` was historically very helpful, but now that most of the counter-creation work is handled by `node_flow` they are no longer needed.
2025-01-13Rollup merge of #134498 - oli-obk:push-wmxynprsyxvr, r=compiler-errorsJacob Pratt-9/+15
Fix cycle error only occurring with -Zdump-mir fixes #134205 During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building). Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
2025-01-11rename `BitSet` to `DenseBitSet`Rémy Rakic-17/+17
This should make it clearer that this bitset is dense, with the advantages and disadvantages that it entails.
2025-01-10mir_transform: implement forced inliningDavid Wood-3/+4
Adds `#[rustc_force_inline]` which is similar to always inlining but reports an error if the inlining was not possible, and which always attempts to inline annotated items, regardless of optimisation levels. It can only be applied to free functions to guarantee that the MIR inliner will be able to resolve calls.
2025-01-10Fix cycle error only occurring with -Zdump-mirOli Scherer-9/+15
2025-01-09Remove the now-useless `Result` from `lit_to_const`Oli Scherer-9/+0
2025-01-09Use error constant instead of explicit error handlingOli Scherer-2/+0
2025-01-08Auto merge of #133858 - dianne:better-blame-constraints-for-static, r=lcnrbors-11/+12
`best_blame_constraint`: Blame better constraints when the region graph has cycles from invariance or `'static` This fixes #132749 by changing which constraint is blamed for region errors in several cases. `best_blame_constraint` had a heuristic that tried to pinpoint the constraint causing an error by filtering out any constraints where the outliving region is unified with the ultimate target region being outlived. However, it used the SCCs of the region graph to do this, which is unreliable; in particular, if the target region is `'static`, or if there are cycles from the presence of invariant types, it was skipping over the constraints it should be blaming. As is the case in that issue, this could lead to confusing diagnostics. The simplest fix seems to work decently, judging by test stderr: this makes `best_blame_constraint` no longer filter constraints by their outliving region's SCC. There are admittedly some quirks in the test output. In many cases, subdiagnostics that depend on the particular constraint being blamed have either started or stopped being emitted. After starting at this for quite a while, I think anything too fickle about whether it outputs based on the particular constraint being blamed should instead be looking at the constraint path as a whole, similar to what's done for [the placeholder-from-predicate note](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static#diff-3c0de6462469af483c9ecdf2c4b00cb26192218ef2d5c62a0fde75107a74caaeR506). Very many tests involving invariant types gained a note pointing out the types' invariance, but in a few cases it was lost. A particularly illustrative example is [tests/ui/lifetimes/copy_modulo_regions.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static?expand=1#diff-96e1f8b29789b3c4ce2f77a5e0fba248829b97ef9d1ce39e7d2b4aa57b2cf4f0); I'd argue the new constraint is a better one to blame, but it lacks the variance diagnostic information that's elsewhere in the constraint path. If desired, I can try making that note check the whole path rather than just the blamed constraint. The subdiagnostic [`BorrowExplanation::add_object_lifetime_default_note`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_borrowck/diagnostics/explain_borrow/enum.BorrowExplanation.html#method.add_object_lifetime_default_note) depends on a `Cast` being blamed, so [a special case](https://github.com/rust-lang/rust/pull/133858/commits/364ca7f99c12fb5220e6b568ac391979317ce878) was necessary to keep it from disappearing from tests specifically testing for it. However, see the FIXME comment in that commit; I think the special case should be removed once that subdiagnostic works properly, but it's nontrivial enough to warrant a separate PR. Incidentally, this removes the note from a test where it was being added erroneously: in [tests/ui/borrowck/two-phase-surprise-no-conflict.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:better-blame-constraints-for-static?expand=1#diff-8cf085af8203677de6575a45458c9e6b03412a927df879412adec7e4f7ff5e14), the object lifetime is explicitly provided and it's not `'static`.
2025-01-06only avoid blaming assignments from argument patternsdianne-6/+1
2025-01-06make outlives constraints from generic arguments less boringdianne-1/+10
2025-01-06`best_blame_constraint`: prioritize blaming interesting-seeming constraintsdianne-5/+2
2025-01-06remove the unused `ConstraintCategory::ClosureBounds`dianne-5/+0
2025-01-06`best_blame_constraint`: avoid blaming assignments without user-provided typesdianne-1/+6
2025-01-01remove `allow_two_phase_borrow`Rémy Rakic-0/+2
it's been simplified over the years, but now it's no longer useful. - document its replacement in `BorrowKind` - use that everywhere instead
2024-12-31Rollup merge of #134949 - compiler-errors:froms, r=jieyouxuStuart Cook-3/+3
Convert some `Into` impls into `From` impls From the [`From`](https://doc.rust-lang.org/std/convert/trait.From.html) docs: > One should always prefer implementing `From` over [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) because implementing `From` automatically provides one with an implementation of [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) thanks to the blanket implementation in the standard library. > > Only implement [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) when targeting a version prior to Rust 1.41 and converting to a type outside the current crate. `From` was not able to do these types of conversions in earlier versions because of Rust’s orphaning rules. See [Into](https://doc.rust-lang.org/std/convert/trait.Into.html) for more details. Some of these impls are likely from before 1.41, and then some others were probably just mistakes. Building nightly rust is definitely not supported on 1.41, so let's modernize these impls :D
2024-12-31Convert some Into impls into From implsMichael Goulet-3/+3
2024-12-30Fix typosNoName-6/+6
2024-12-27MatchBranchSimplification: Consider empty-unreachable otherwise branchclubby789-0/+11
2024-12-23Auto merge of #134465 - lcnr:type-verifier, r=compiler-errorsbors-25/+75
cleanup `TypeVerifier` We should merge it with the `TypeChecker` as we no longer bail in cases where it encounters an error since #111863. It's quite inconsistent whether a check lives in the verifier or the `TypeChecker`, so this feels like a quite impactful cleanup. I expect that for this we may want to change the `TypeChecker` to also be a MIR visitor :thinking: this is non-trivial so I didn't fully do it in this PR. Best reviewed commit by commit. r? `@compiler-errors` feel free to reassign however
2024-12-22Delete `Rvalue::Len`Scott McMurray-21/+0
Everything's moved to `PtrMetadata` instead.
2024-12-22Rollup merge of #134618 - RalfJung:coroutine-clone-comments, r=lqdMatthias Krüger-0/+5
coroutine_clone: add comments I was very surprised to learn that coroutines can be cloned. This has non-trivial semantic consequences that I do not think have been considered. Lucky enough, it's still unstable. Let's add some comments and pointers so we hopefully become aware when a MIR opt actually is in conflict with this. Cc `@rust-lang/wg-mir-opt`
2024-12-21Auto merge of #134268 - lqd:polonius-next, r=jackh726bors-0/+1
Foundations of location-sensitive polonius I'd like to land the prototype I'm describing in the [polonius project goal](https://github.com/rust-lang/rust-project-goals/issues/118). It still is incomplete and naive and terrible but it's working "well enough" to consider landing. I'd also like to make review easier by not opening a huge PR, but have a couple small-ish ones (the +/- line change summary of this PR looks big, but >80% is moving datalog to a single place). This PR starts laying the foundation for that work: - it refactors and collects 99% of the old datalog fact gen, which was spread around everywhere, into a single dedicated module. It's still present at 3 small places (one of which we should revert anyways) that are kinda deep within localized components and are not as easily extractable into the rest of fact gen, so it's fine for now. - starts introducing the localized constraints, the building blocks of the naive way of implementing the location-sensitive analysis in-tree, which is roughly sketched out in https://smallcultfollowing.com/babysteps/blog/2023/09/22/polonius-part-1/ and https://smallcultfollowing.com/babysteps/blog/2023/09/29/polonius-part-2/ but with a different vibe than per-point environments described in these posts, just `r1@p: r2@q` constraints. - sets up the skeleton of generating these localized constraints: converting NLL typeck constraints, and creating liveness constraints - introduces the polonius dual to NLL MIR to help development and debugging. It doesn't do much currently but is a way to see these localized constraints: it's an NLL MIR dump + a dumb listing of the constraints, that can be dumped with `-Zdump-mir=polonius -Zpolonius=next`. Its current state is not intended to be a long-term thing, just for testing purposes -- I will replace its contents in the future with a different approach (an HTML+js file where we can more easily explore/filter/trace these constraints and loan reachability, have mermaid graphs of the usual graphviz dumps, etc). I've started documenting the approach in this PR, I'll add more in the future. It's quite simple, and should be very clear when more constraints are introduced anyways. r? `@matthewjasper` Best reviewed per commit so that the datalog move is less bothersome to read, but if you'd prefer we separate that into a different PR, I can do that (and michael has offered to review these more mechanical changes if it'd help).
2024-12-21coroutine_clone: add commentsRalf Jung-0/+5
2024-12-19Rollup merge of #134497 - Zalathar:spans, r=jieyouxuMatthias Krüger-19/+3
coverage: Store coverage source regions as `Span` until codegen (take 2) This is an attempt to re-land #133418: > Historically, coverage spans were converted into line/column coordinates during the MIR instrumentation pass. > This PR moves that conversion step into codegen, so that coverage spans spend most of their time stored as Span instead. > In addition to being conceptually nicer, this also reduces the size of coverage mappings in MIR, because Span is smaller than 4x u32. That PR was reverted by #133608, because in some circumstances not covered by our test suite we were emitting coverage metadata that was causing `llvm-cov` to exit with an error (#133606). --- The implementation here is *mostly* the same, but adapted for subsequent changes in the relevant code (e.g. #134163). I believe that the changes in #134163 should be sufficient to prevent the problem that required the original PR to be reverted. But I haven't been able to reproduce the original breakage in a regression test, and the `llvm-cov` error message is extremely unhelpful, so I can't completely rule out the possibility of this breaking again. r? jieyouxu (reviewer of the original PR)
2024-12-19Rollup merge of #133702 - RalfJung:single-variant, r=oli-obk许杰友 Jieyou Xu (Joe)-1/+1
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-19coverage: Store coverage source regions as `Span` until codegenZalathar-19/+3
2024-12-18merge PlaceTy field_ty computationlcnr-18/+53
2024-12-18mir: require `is_cleanup` when creating `BasicBlockData`DianQK-2/+2
2024-12-18get_ambient_variance to inherent methodlcnr-7/+22