summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-03-15Rollup merge of #122471 - RalfJung:const-eval-span, r=oli-obkMatthias Krüger-2/+5
preserve span when evaluating mir::ConstOperand This lets us show to the user where they were using the faulty const (which can be quite relevant when generics are involved). I wonder if we should change "erroneous constant encountered" to something like "the above error was encountered while evaluating this constant" or so, to make this more similar to what the collector emits when showing a "backtrace" of where things get monomorphized? It seems a bit strange to rely on the order of emitted diagnostics for that but it seems the collector already [does that](https://github.com/rust-lang/rust/blob/da8a8c9223722e17cc0173ce9490076b4a6d263d/compiler/rustc_monomorphize/src/collector.rs#L472-L475).
2024-03-14preserve span when evaluating mir::ConstOperandRalf Jung-2/+5
2024-03-14Rollup merge of #122322 - Zalathar:branch, r=oli-obkMatthias Krüger-47/+121
coverage: Initial support for branch coverage instrumentation (This is a review-ready version of the changes that were drafted in #118305.) This PR adds support for branch coverage instrumentation, gated behind the unstable flag value `-Zcoverage-options=branch`. (Coverage instrumentation must also be enabled with `-Cinstrument-coverage`.) During THIR-to-MIR lowering (MIR building), if branch coverage is enabled, we collect additional information about branch conditions and their corresponding then/else blocks. We inject special marker statements into those blocks, so that the `InstrumentCoverage` MIR pass can reliably identify them even after the initially-built MIR has been simplified and renumbered. The rest of the changes are mostly just plumbing needed to gather up the information that was collected during MIR building, and include it in the coverage metadata that we embed in the final binary. Note that `llvm-cov show` doesn't print branch coverage information in its source views by default; that needs to be explicitly enabled with `--show-branches=count` or similar. --- The current implementation doesn't have any support for instrumenting `if let` or let-chains. I think it's still useful without that, and adding it would be non-trivial, so I'm happy to leave that for future work.
2024-03-14Rollup merge of #122368 - pavedroad:master, r=oli-obkMatthias Krüger-1/+1
chore: remove repetitive words
2024-03-14Auto merge of #122243 - RalfJung:local-place-sanity-check, r=oli-obkbors-1/+1
interpret: ensure that Place is never used for a different frame We store the address where the stack frame stores its `locals`. The idea is that even if we pop and push, or switch to a different thread with a larger number of frames, then the `locals` address will most likely change so we'll notice that problem. This is made possible by some recent changes by `@WaffleLapkin,` where we no longer use `Place` across things that change the number of stack frames. I made these debug assertions for now, just to make sure this can't cost us any perf. The first commit is unrelated but it's a one-line comment change so it didn't warrant a separate PR... r? `@oli-obk`
2024-03-14coverage: Include recorded branch info in coverage instrumentationZalathar-3/+68
2024-03-13coverage: Add `CoverageKind::BlockMarker`Zalathar-0/+5
2024-03-13coverage: Make `is_eligible_for_coverage` a hook methodZalathar-38/+41
This will allow MIR building to check whether a function is eligible for coverage instrumentation, and avoid collecting branch coverage info if it is not.
2024-03-13Allow `rustc_mir_transform` to register hook providersZalathar-6/+7
2024-03-12chore: remove repetitive wordspavedroad-1/+1
Signed-off-by: pavedroad <qcqs@outlook.com> chore: remove repetitive words Signed-off-by: pavedroad <qcqs@outlook.com>
2024-03-12Ensure nested allocations in statics do not get deduplicatedOli Scherer-1/+7
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-1/+1
2024-03-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-5/+5
To match `derive(LintDiagnostic)`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-4/+4
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-09add_retag: fix comment that does not match the codeRalf Jung-1/+1
2024-03-08Distinguish between library and lang UB in assert_unsafe_preconditionBen Kimock-5/+22
2024-03-08Auto merge of #122182 - matthiaskrgr:rollup-gzimi4c, r=matthiaskrgrbors-10/+20
Rollup of 8 pull requests Successful merges: - #118623 (Improve std::fs::read_to_string example) - #119365 (Add asm goto support to `asm!`) - #120608 (Docs for std::ptr::slice_from_raw_parts) - #121832 (Add new Tier-3 target: `loongarch64-unknown-linux-musl`) - #121938 (Fix quadratic behavior of repeated vectored writes) - #122099 (Add `#[inline]` to `BTreeMap::new` constructor) - #122103 (Make TAITs and ATPITs capture late-bound lifetimes in scope) - #122143 (PassWrapper: update for llvm/llvm-project@a3319371970b) Failed merges: - #122076 (Tweak the way we protect in-place function arguments in interpreters) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-08Rollup merge of #119365 - nbdd0121:asm-goto, r=AmanieuMatthias Krüger-10/+20
Add asm goto support to `asm!` Tracking issue: #119364 This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto). Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary. r? ``@Amanieu`` cc ``@ojeda``
2024-03-08Auto merge of #120268 - DianQK:otherwise_is_last_variant_switchs, r=oli-obkbors-27/+57
Replace the default branch with an unreachable branch If it is the last variant Fixes #119520. Fixes #110097. LLVM currently has limited ability to eliminate dead branches in switches, even with the patch of https://github.com/llvm/llvm-project/issues/73446. The main reasons are as follows: - Additional costs are required to calculate the range of values, and there exist many scenarios that cannot be analyzed accurately. - Matching values by bitwise calculation cannot handle odd branches, nor can it handle values like `-1, 0, 1`. See [SimplifyCFG.cpp#L5424](https://github.com/llvm/llvm-project/blob/llvmorg-17.0.6/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L5424) and https://llvm.godbolt.org/z/qYMqhvMa8 - The current range information is continuous, even if the metadata for the range is submitted. See [ConstantRange.cpp#L1869-L1870](https://github.com/llvm/llvm-project/blob/llvmorg-17.0.6/llvm/lib/IR/ConstantRange.cpp#L1869-L1870). - The metadata of the range may be lost in passes such as SROA. See https://rust.godbolt.org/z/e7f87vKMK. Although we can make improvements, I think it would be more appropriate to put this issue to rustc first. After all, we can easily know the possible values. Note that we've currently found a slow compilation problem in the presence of unreachable branches. See https://github.com/llvm/llvm-project/issues/78578. r? compiler
2024-03-08Add a workaround for the `TailDuplicator` compile time overheadDianQK-5/+24
2024-03-08Update MIR with `MirPatch` in `UninhabitedEnumBranching`DianQK-37/+30
2024-03-07Get all variants to eliminate the default branching if we cannot get the ↵DianQK-0/+6
layout of type
2024-03-07Replace the default branch with an unreachable branch If it is the last variantDianQK-6/+18
2024-03-07Auto merge of #121985 - RalfJung:interpret-return-place, r=oli-obkbors-2/+2
interpret: avoid a long-lived PlaceTy in stack frames `PlaceTy` uses a representation that's not very stable under changes to the stack. I'd feel better if we didn't have one in the long-term machine state. r? `@oli-obk`
2024-03-05Auto merge of #121780 - nnethercote:diag-renaming2, r=davidtwcobors-6/+6
Diagnostic renaming 2 A sequel to #121489. r? `@davidtwco`
2024-03-05Rename `DiagnosticMessage` as `DiagMessage`.Nicholas Nethercote-6/+6
2024-03-04consistently use MPlaceTy for return placesRalf Jung-2/+2
2024-03-04Remove some depgraph edges on the HIR by invoking the intrinsic query ↵Oli Scherer-3/+3
instead of checking the attribute
2024-03-04Add a scheme for moving away from `extern "rust-intrinsic"` entirelyOli Scherer-0/+10
2024-03-04Return a struct from `query intrinsic` to be able to add another field in ↵Oli Scherer-7/+7
the next commit
2024-03-04Add `is_intrinsic` helperOli Scherer-1/+1
2024-03-01Fix typo in commentGurinder Singh-1/+1
2024-02-29Rollup merge of #121654 - compiler-errors:async-fn-for-fn-def, r=oli-obkGuillaume Gomez-1/+5
Fix `async Fn` confirmation for `FnDef`/`FnPtr`/`Closure` types Fixes three issues: 1. The code in `extract_tupled_inputs_and_output_from_async_callable` was accidentally getting the *future* type and the *output* type (returned by the future) messed up for fnptr/fndef/closure types. :/ 2. We have a (class of) bug(s) in the old solver where we don't really support higher ranked built-in `Future` goals for generators. This is not possible to hit on stable code, but [can be hit with `unboxed_closures`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=e935de7181e37e13515ad01720bcb899) (#121653). * I'm opting not to fix that in this PR. Instead, I just instantiate placeholders when confirming `async Fn` goals. 4. Fixed a bug when generating `FnPtr` shims for `async Fn` trait goals. r? oli-obk
2024-02-28Rename `DiagnosticArg{,Map,Name,Value}` as `DiagArg{,Map,Name,Value}`.Nicholas Nethercote-4/+4
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-8/+8
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-27Also support `fnptr(): async Fn` in codegenMichael Goulet-1/+5
2024-02-27ffi_unwind_calls: treat RustIntrinsic like regular Rust callsRalf Jung-4/+9
2024-02-26Auto merge of #121516 - RalfJung:platform-intrinsics-begone, r=oli-obkbors-1/+0
remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsics `@Amanieu` `@workingjubilee` I don't think there is any reason these need to be "special"? The [original RFC](https://rust-lang.github.io/rfcs/1199-simd-infrastructure.html) indicated eventually making them stable, but I think that is no longer the plan, so seems to me like we can clean this up a bit. Blocked on https://github.com/rust-lang/stdarch/pull/1538, https://github.com/rust-lang/rust/pull/121542.
2024-02-26Do not const pop unionsGurinder Singh-14/+26
as they can made to produce values whose types don't match their underlying layout types which can lead to ICEs on eval
2024-02-25remove platform-intrinsics ABI; make SIMD intrinsics be regular intrinsicsRalf Jung-1/+0
2024-02-25Auto merge of #121114 - Nilstrieb:no-inline!, r=saethlinbors-0/+4
Add `#[rustc_no_mir_inline]` for standard library UB checks should help with #121110 and also with #120848 Because the MIR inliner cannot know whether the checks are enabled or not, so inlining is an unnecessary compile time pessimization when debug assertions are disabled. LLVM knows whether they are enabled or not, so it can optimize accordingly without wasting time. r? `@saethlin`
2024-02-24Add `#[rustc_no_mir_inline]` for standard library UB checksNilstrieb-0/+4
Co-authored-by: Ben Kimock <kimockb@gmail.com>
2024-02-24Implement asm goto in MIR and MIR loweringGary Guo-1/+2
2024-02-24Change InlineAsm to allow multiple targets insteadGary Guo-9/+18
2024-02-24promotion: don't promote int::MIN / -1Ralf Jung-3/+26
2024-02-23Rollup merge of #121492 - Zalathar:hole, r=fmeaseMatthias Krüger-65/+62
coverage: Rename `is_closure` to `is_hole` Extracted from #121433, since I was having second thoughts about some of the other changes bundled in that PR, but these changes are still fine. --- When refining covspans, we don't specifically care which ones represent closures; we just want to know which ones represent "holes" that should be carved out of other spans and then discarded. (Closures are currently the only source of hole spans, but in the future we might want to also create hole spans for nested items and inactive `#[cfg(..)]` regions.) ``@rustbot`` label +A-code-coverage
2024-02-23coverage: Rename `is_closure` to `is_hole`Zalathar-60/+59
When refining covspans, we don't specifically care which ones represent closures; we just want to know which ones represent "holes" that should be carved out of other spans and then discarded. (Closures are currently the only source of hole spans, but in the future we might want to also create hole spans for nested items and inactive `#[cfg(..)]` regions.)
2024-02-23coverage: Remove some lingering references to `pending_dups`Zalathar-6/+4
2024-02-23coverage: Use variable name `this` in `CoverageGraph::from_mir`Zalathar-7/+6
This makes it easier to see that we're manipulating the instance that is being constructed, and is a lot less verbose than `basic_coverage_blocks`.
2024-02-22Auto merge of #121309 - Nilstrieb:inline-all-the-fallbacks, r=oli-obkbors-0/+17
Make intrinsic fallback bodies cross-crate inlineable This change was prompted by the stage1 compiler spending 4% of its time when compiling the polymorphic-recursion MIR opt test in `unlikely`. Intrinsic fallback bodies like `unlikely` should always be inlined, it's very silly if they are not. To do this, we enable the fallback bodies to be cross-crate inlineable. Not that this matters for our workloads since the compiler never actually _uses_ the "fallback bodies", it just uses whatever was cfg(bootstrap)ped, so I've also added `#[inline]` to those. See the comments for more information. r? oli-obk