summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-11-01Mark `simplify_aggregate_to_copy` mir-opt as unsound许杰友 Jieyou Xu (Joe)-1/+3
Co-authored-by: DianQK <dianqk@dianqk.net> (cherry picked from commit 10b8ba4ecb19ac2eb7be97a1a1eb1ffae9fec534)
2024-10-08coverage. Warn about too many test vectorszhuyunxing-1/+15
2024-10-08coverage. Adapt to mcdc mapping formats introduced by llvm 19zhuyunxing-115/+274
2024-10-07Rollup merge of #131325 - Zalathar:tweak-counters, r=jieyouxuStuart Cook-25/+28
coverage: Multiple small tweaks to counter creation I've been experimenting with some larger changes to how coverage counters are assigned to parts of the control-flow graph, and while none of that is ready yet, along the way I've repeatedly found myself wanting these smaller tweaks as a base. There are no changes to compiler output.
2024-10-07Auto merge of #131068 - RalfJung:immediate-offset-sanity-check, r=nnethercotebors-7/+23
Don't use Immediate::offset to transmute pointers to integers This applies the relatively new `assert_matches_abi` check in the `offset` operation on immediates, which makes sure that if offsets are used to alter the layout (which is possible because the field layout is arbitrarily picked by the caller), this is not done in a way that breaks the invariant of the `Immediate` type. This leads to ICEs in a GVN mir-opt test, so the second commit fixes GVN. Fixes https://github.com/rust-lang/rust/issues/131064.
2024-10-06coverage: Store `bcb_needs_counter` in a field as a bitsetZalathar-8/+14
This makes it possible for other parts of counter-assignment to check whether a node is guaranteed to end up with some kind of counter. Switching from `impl Fn` to a concrete `&BitSet` just avoids the hassle of trying to store a closure in a struct field, and currently there's no foreseeable need for this information to not be a bitset.
2024-10-06coverage: Have MakeBcbCounters own its CoverageCountersZalathar-13/+14
2024-10-06coverage: Make `BcbCounter` module-privateZalathar-10/+6
2024-10-06Auto merge of #130540 - veera-sivarajan:fix-87525, r=estebankbors-0/+86
Add a Lint for Pointer to Integer Transmutes in Consts Fixes #87525 This PR adds a MirLint for pointer to integer transmutes in const functions and associated consts. The implementation closely follows this comment: https://github.com/rust-lang/rust/pull/85769#issuecomment-880969112. More details about the implementation can be found in the comments. Note: This could break some sound code as mentioned by RalfJung in https://github.com/rust-lang/rust/pull/85769#issuecomment-886491680: > ... technically const-code could transmute/cast an int to a ptr and then transmute it back and that would be correct -- so the lint will deny some sound code. Does not seem terribly likely though. References: 1. https://doc.rust-lang.org/std/mem/fn.transmute.html 2. https://doc.rust-lang.org/reference/items/associated-items.html#associated-constants
2024-10-05fix GVN trying to transmute pointers to integersRalf Jung-7/+23
2024-10-05Add a Lint for Pointer to Integer Transmutes in ConstsVeera-0/+86
2024-10-05Compute array length from type for unconditional panic.Camille GILLOT-7/+9
2024-10-04Rollup merge of #131202 - Urgau:wide-ptrs-compiler, r=jieyouxuGuillaume Gomez-3/+3
Use wide pointers consistenly across the compiler This PR replace every use of "fat pointer" for the more recent "wide pointer" terminology. Since some time T-lang as preferred the "wide pointer" terminology, as can be seen on [the last RFCs](https://github.com/search?q=repo%3Arust-lang%2Frfcs+%22wide+pointer%22&type=code), on some [lints](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#ambiguous-wide-pointer-comparisons), but also in [the reference](https://doc.rust-lang.org/stable/reference/expressions/operator-expr.html?highlight=wide%20pointer#pointer-to-pointer-cast). Currently we have a [mix of both](https://github.com/search?q=repo%3Arust-lang%2Frust+%22wide+pointer%22&type=code) (including in error messages), which isn't great, but with this PR no more. r? `@jieyouxu` (feel free to re-roll)
2024-10-04Use wide pointers consistenly across the compilerUrgau-3/+3
2024-10-04Auto merge of #131201 - compiler-errors:unop-not, r=cjgillotbors-0/+8
Disable jump threading `UnOp::Not` for non-bool Fix #131195, where jumpthreading was optimizing `!a == b` into `a != b` for non-bool, where this is definitely not true.
2024-10-03Disable jump threading UnOp::Not for non-boolMichael Goulet-0/+8
2024-10-03Avoid ICE in coverage builds with bad `#[coverage(..)]` attributesZalathar-1/+2
This code can sometimes witness malformed coverage attributes in builds that are going to fail, so use `span_delayed_bug` to avoid an inappropriate ICE in that case.
2024-10-01make InterpResult a dedicated type to avoid accidentally discarding the errorRalf Jung-152/+127
2024-09-30panic when an interpreter error gets unintentionally discardedRalf Jung-111/+153
2024-09-29Rollup merge of #130990 - RalfJung:mir-const-normalize, r=compiler-errorsMatthias Krüger-3/+1
try to get rid of mir::Const::normalize It was easy to make this compile, let's see if anything breaks... r? `@compiler-errors`
2024-09-29cleanup: don't clone types that are CopyMatthias Krüger-8/+7
2024-09-28try to get rid of mir::Const::normalizeRalf Jung-3/+1
2024-09-25Add a debug assertion in codegen that unsize casts of the same principal ↵Michael Goulet-15/+0
trait def id are truly NOPs
2024-09-25Validate unsize coercion in MIR validationMichael Goulet-3/+47
2024-09-25Auto merge of #130803 - cuviper:file-buffered, r=joshtriplettbors-1/+2
Add `File` constructors that return files wrapped with a buffer In addition to the light convenience, these are intended to raise visibility that buffering is something you should consider when opening a file, since unbuffered I/O is a common performance footgun to Rust newcomers. ACP: https://github.com/rust-lang/libs-team/issues/446 Tracking Issue: #130804
2024-09-24Dogfood `feature(file_buffered)`Josh Stone-1/+2
2024-09-24be even more precise about "cast" vs "coercion"Lukas Markeffsky-21/+23
2024-09-24unify dyn* coercions with other pointer coercionsLukas Markeffsky-6/+6
2024-09-24Revert "Auto merge of #129047 - DianQK:early_otherwise_branch_scalar, ↵许杰友 Jieyou Xu (Joe)-175/+85
r=cjgillot" This reverts commit a772336fb3fbd1fe4493077fcfe04e0221296a99, reversing changes made to 702987f75b74f789ba227ee04a3d7bb1680c2309. It seems Apply EarlyOtherwiseBranch to scalar value #129047 may have lead to several nightly regressions: - https://github.com/rust-lang/rust/issues/130769 - https://github.com/rust-lang/rust/issues/130774 - https://github.com/rust-lang/rust/issues/130771 And since this is a mir-opt ICE that seems to quite easy to trigger with real-world crates being affected, let's revert for now and reland the mir-opt later.
2024-09-23Auto merge of #129047 - DianQK:early_otherwise_branch_scalar, r=cjgillotbors-85/+175
Apply `EarlyOtherwiseBranch` to scalar value In the future, I'm thinking of hoisting discriminant via GVN so that we only need to write very little code here. r? `@cjgillot`
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-234/+175
2024-09-18Apply `EarlyOtherwiseBranch` to scalar valueDianQK-85/+175
2024-09-17Rollup merge of #130201 - compiler-errors:foreign-synthetic-body, r=lcnrMatthias Krüger-17/+21
Encode `coroutine_by_move_body_def_id` in crate metadata We synthesize the MIR for a by-move body for the `FnOnce` implementation of async closures. It can be accessed with the `coroutine_by_move_body_def_id` query. We weren't encoding this query in the metadata though, nor were we properly recording that synthetic MIR in `mir_keys`, so the `optimized_mir` wasn't getting encoded either! Stacked on top is a fix to consider `DefKind::SyntheticCoroutineBody` to return true in several places I missed. Specifically, we should consider the def-kind in `fn DefKind::is_fn_like()`, since that's what we were using to make sure we ensure `query mir_inliner_callees` before the MIR gets stolen for the body. This led to some CI failures that were caught by miri but which I added a test for.
2024-09-17Auto merge of #130455 - compiler-errors:inline-ordering, r=saethlinbors-10/+0
Remove semi-nondeterminism of `DefPathHash` ordering from inliner Déjà vu or something because I kinda thought I had put this PR up before. I recall a discussion somewhere where I think it was `@saethlin` mentioning that this check was no longer needed since we have "proper" cycle detection. Putting that up as a PR now. This may slighlty negatively affect inlining, since the cycle breaking here means that we still inlined some cycles when the def path hashes were ordered in certain ways, this leads to really bad nondeterminism that makes minimizing ICEs and putting up inliner bugfixes difficult. r? `@cjgillot` or `@saethlin` or someone else idk
2024-09-16Fix a couple more DefKind discrepancies between DefKind::Closure and ↵Michael Goulet-1/+1
DefKind::SyntheticCoroutineBody
2024-09-17Rollup merge of #130380 - Zalathar:counters, r=jieyouxuMatthias Krüger-151/+170
coverage: Clarify some parts of coverage counter creation This is a series of semi-related changes that are trying to make the `counters` module easier to read, understand, and modify. For example, the existing code happens to avoid ever using the count for a `TerminatorKind::Yield` node as the count for its sole out-edge (since doing so would be incorrect), but doesn't do so explicitly, so seemingly-innocent changes can result in baffling test failures. This PR also takes the opportunity to simplify some debug-logging code that was making its surrounding code disproportionately hard to read. There should be no changes to the resulting coverage instrumentation/mappings, as demonstrated by the absence of changes to the coverage test suite.
2024-09-16Remove semi-nondeterminism of DefPathHash ordering from inlinerMichael Goulet-10/+0
2024-09-16Record synthetic MIR bodies in mir_keysMichael Goulet-16/+20
2024-09-16Don't ICE when generating Fn shim for async closure with borrowck errorMichael Goulet-5/+12
2024-09-15coverage: Remove unnecessary `bcb_successors`Zalathar-7/+1
Given that we directly access the graph predecessors/successors in so many other places, and sometimes must do so to satisfy the borrow checker, there is little value in having this trivial helper method.
2024-09-15coverage: Replace `bcb_has_multiple_in_edges` with `sole_predecessor`Zalathar-35/+30
This does a better job of expressing the special cases that occur when a node in the coverage graph has exactly one in-edge.
2024-09-15coverage: Simplify choosing an out-edge to be given a counter expressionZalathar-69/+48
By building the list of candidate edges up-front, and making the candidate-selection method fallible, we can remove a few pieces of awkward code.
2024-09-15coverage: Track whether a node's count is the sum of its out-edgesZalathar-13/+57
2024-09-15coverage: Streamline creation of physical edge countersZalathar-6/+17
2024-09-15coverage: Streamline creation of physical node countersZalathar-23/+19
- Look up the node's predecessors only once - Get rid of some overly verbose logging - Explain why some nodes need physical counters - Extract a helper method to create and set a physical node counter
2024-09-15coverage: Tweak comments in `graph`Zalathar-4/+4
2024-09-14Auto merge of #130357 - fmease:rollup-j3ej4q0, r=fmeasebors-20/+20
Rollup of 6 pull requests Successful merges: - #130017 (coverage: Extract `executor::block_on` from several async coverage tests) - #130268 (simd_shuffle: require index argument to be a vector) - #130290 (Stabilize entry_insert) - #130294 (Lifetime cleanups) - #130343 (docs: Enable required feature for 'closure_returning_async_block' lint) - #130349 (Fix `Parser::break_up_float`'s right span) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-14Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnrLeón Orell Valerian Liehr-20/+20
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`
2024-09-14Auto merge of #128299 - DianQK:clone-copy, r=cjgillotbors-1/+97
Simplify the canonical clone method and the copy-like forms to copy Fixes #128081. The optimized clone method ends up as the following MIR: ``` _2 = copy ((*_1).0: i32); _3 = copy ((*_1).1: u64); _4 = copy ((*_1).2: [i8; 3]); _0 = Foo { a: move _2, b: move _3, c: move _4 }; ``` We can transform this to: ``` _0 = copy (*_1); ``` r? `@cjgillot`
2024-09-14Simplify the canonical clone method to copyDianQK-1/+97
The optimized clone method ends up as the following MIR: ``` _2 = copy ((*_1).0: i32); _3 = copy ((*_1).1: u64); _4 = copy ((*_1).2: [i8; 3]); _0 = Foo { a: move _2, b: move _3, c: move _4 }; ``` We can transform this to: ``` _0 = copy (*_1); ```