about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/syntax.rs
AgeCommit message (Collapse)AuthorLines
2025-01-28Represent the raw pointer for a array length check as a new kind of fake borrowMichael Goulet-1/+54
2025-01-24Exclude `mir::coverage` types from TypeFoldable/TypeVisitableZalathar-1/+8
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-18Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"Rémy Rakic-0/+10
This reverts commit e108481f74ff123ad98a63bd107a18d13035b275, reversing changes made to 303e8bd768526a5812bb1776e798e829ddb7d3ca.
2024-12-22Delete `Rvalue::Len`Scott McMurray-10/+0
Everything's moved to `PtrMetadata` instead.
2024-12-21coroutine_clone: add commentsRalf Jung-0/+5
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-0/+28
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-8/+1
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-03compiler: Directly use rustc_abi in metadata and middleJubilee Young-1/+1
Stop reexporting ReprOptions from middle::ty
2024-10-31stop using `ParamEnv::reveal` while handling MIRlcnr-16/+4
2024-10-31`ConstCx` stop using `ParamEnv::reveal`lcnr-6/+17
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-1/+23
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-10-05clarify semantics of ConstantIndex MIR projectionRalf Jung-2/+4
2024-09-24update doc commentLukas Markeffsky-2/+4
2024-09-24be even more precise about "cast" vs "coercion"Lukas Markeffsky-2/+11
2024-09-24unify dyn* coercions with other pointer coercionsLukas Markeffsky-2/+0
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-09-13ProjectionElem and UnOp/BinOp dont need to be PartialOrd/OrdMichael Goulet-3/+3
2024-09-03explain why Rvalue::Len still existsRalf Jung-0/+3
2024-08-21fix comment on PlaceMention semanticsRalf Jung-1/+1
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-4/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-15/+11
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-07Fix conflicts after rebaseMaybe Lapkin-1/+1
- r-l/r 126784 - r-l/r 127113 - r-l/miri 3562
2024-07-07Support tail calls in mir via `TerminatorKind::TailCall`Maybe Waffle-0/+31
2024-06-21Save 2 pointers in `TerminatorKind` (96 → 80 bytes)Scott McMurray-4/+4
These things don't need to be `Vec`s; boxed slices are enough. The frequent one here is call arguments, but MIR building knows the number of arguments from the THIR, so the collect is always getting the allocation right in the first place, and thus this shouldn't ever add the shrink-in-place overhead.
2024-06-20More GVN for PtrMetadataScott McMurray-2/+4
`PtrMetadata` doesn't care about `*const`/`*mut`/`&`/`&mut`, so GVN away those casts in its argument. This includes updating MIR to allow calling PtrMetadata on references too, not just raw pointers. That means that `[T]::len` can be just `_0 = PtrMetadata(_1)`, for example. # Conflicts: # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
2024-06-19Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIRScott McMurray-2/+11
Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.)
2024-06-19Rollup merge of #126154 - RalfJung:storage-live, r=compiler-errorsLeón Orell Valerian Liehr-4/+7
StorageLive: refresh storage (instead of UB) when local is already live Blocked on [this FCP](https://github.com/rust-lang/rust/issues/99160#issuecomment-2155924538), which also contains the motivation. Fixes https://github.com/rust-lang/rust/issues/99160 Fixes https://github.com/rust-lang/rust/issues/98896 (by declaring it not-a-bug) Fixes https://github.com/rust-lang/rust/issues/119366 Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/129
2024-06-14MIR Shl/Shr: the offset can be computed with rem_euclidRalf Jung-2/+4
2024-06-08StorageLive: refresh storage (instead of UB) when local is already liveRalf Jung-4/+7
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-0/+7
2024-05-27MIR validation: ensure that downcast projection is followed by field projectionRalf Jung-2/+2
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-8/+11
2024-05-15MIR operators: clarify Shl/Shr handling of negative offsetsRalf Jung-2/+6
2024-04-29Remove `extern crate rustc_data_structures` from numerous crates.Nicholas Nethercote-0/+1
2024-04-29Remove `extern crate rustc_macros` from `rustc_middle`.Nicholas Nethercote-0/+1
2024-04-23Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasperLeón Orell Valerian Liehr-10/+61
deref patterns: lower deref patterns to MIR This lowers deref patterns to MIR. This is a bit tricky because this is the first kind of pattern that requires storing a value in a temporary. Thanks to https://github.com/rust-lang/rust/pull/123324 false edges are no longer a problem. The thing I'm not confident about is the handling of fake borrows. This PR ignores any fake borrows inside a deref pattern. We are guaranteed to at least fake borrow the place of the first pointer value, which could be enough, but I'm not certain.
2024-04-21Add `AggregateKind::RawPtr` and enough support to compileScott McMurray-0/+15
2024-04-20Fix documentation of `BorrowKind::Fake`Nadrieril-3/+3
2024-04-20Add a non-shallow fake borrowNadrieril-11/+62
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-1/+1
We want to run them on all 64-bit platforms.
2024-04-16Move size assertions for `mir::syntax` types into the same fileZalathar-0/+1
A redundant size assertion for `StatementKind` was added in #122937, because the existing assertion was in a different file. This patch cleans that up, and also moves the `TerminatorKind` assertion into the same file where it belongs, to avoid the same thing happening again.
2024-04-03Rollup merge of #123401 - Zalathar:assert-size-aarch64, r=fmeaseJacob Pratt-1/+1
Check `x86_64` size assertions on `aarch64`, too (Context: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Checking.20size.20assertions.20on.20aarch64.3F) Currently the compiler has around 30 sets of `static_assert_size!` for various size-critical data structures (e.g. various IR nodes), guarded by `#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]`. (Presumably this cfg avoids having to maintain separate size values for 32-bit targets and unusual 64-bit targets. Apparently it may have been necessary before the i128/u128 alignment changes, too.) This is slightly incovenient for people on aarch64 workstations (e.g. Macs), because the assertions normally aren't checked until we push to a PR. So this PR adds `aarch64` to the `#[cfg(..)]` guarding all of those assertions in the compiler. --- Implemented with a simple find/replace. Verified by manually inspecting each `static_assert_size!` in `compiler/`, and checking that either the replacement succeeded, or adding aarch64 wouldn't have been appropriate.
2024-04-03rename `expose_addr` to `expose_provenance`joboet-2/+2
2024-04-03Check `x86_64` size assertions on `aarch64`, tooZalathar-1/+1
This makes it easier for contributors on aarch64 workstations (e.g. Macs) to notice when these assertions have been violated.
2024-04-02Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=AmanieuJacob Pratt-2/+2
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066). The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".) The new name nicely matches `ptr::without_provenance`.
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+10
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~
2024-03-27Eliminate `UbCheck` for non-standard librariesDianQK-2/+2
2024-03-24Address PR feedbackScott McMurray-0/+8
2024-03-24Rollup merge of #122937 - Zalathar:unbox, r=oli-obkMatthias Krüger-7/+2
Unbox and unwrap the contents of `StatementKind::Coverage` The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future. ``@rustbot`` label +A-code-coverage