about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/syntax.rs
AgeCommit message (Collapse)AuthorLines
2025-09-26ProjectionElem::Subtype -> CastKind::Subtypebeepster4096-12/+12
2025-09-16Remove Rvalue::Len.Camille Gillot-10/+0
2025-09-10clarify current MIR semantics re: overlapping assignmentRalf Jung-3/+5
and double-check that we match it in codegen
2025-08-25Remove bug comments from Repeat variantRyan Lee-5/+0
Removed comments related to a bug in Repeat variant.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-29Rollup merge of #143088 - firefighterduck:improve-doc-discr-tag, r=RalfJungMatthias Krüger-9/+9
Improve documentation of `TagEncoding` This PR is follow-up from the [discussion here](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20VariantId.3DDiscriminant.20when.20tag.20is.20niche.20encoded.3F/with/524384295). It aims at making the `TagEncoding` documentation less ambiguous and more detailed with references to relevant implementation sides. It especially clears up the ambiguous use of discriminant/variant index, which sparked the discussion referenced above. PS: While working with layout data, I somehow ended up looking at the docs for `FakeBorrowKind` and noticed that the one example was not in a doc comment. I hope that this is minor enough of a fix for it to be okay in this otherwise unrelated PR.
2025-06-28fix docs of FakeBorrowKindFlorian Sextl-9/+9
2025-06-28Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlinbors-0/+1
Insert checks for enum discriminants when debug assertions are enabled Similar to the existing null-pointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@. r? `@saethlin`
2025-06-27Insert checks for enum discriminants when debug assertions are enabledBastian Kersting-0/+1
Similar to the existing nullpointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following: ```rust let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) }; ``` An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++. This check is similar to Miri's capabilities of checking for valid construction of enum values. This PR is inspired by saethlin@'s PR https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments! I also pair-programmed large parts of this together with vabr-g@.
2025-06-13Unimplement unsized_localsmejrs-7/+0
2025-06-06Allow transmute casts in pre-runtime-MIROli Scherer-2/+0
2025-04-28AsyncDrop implementation using shim codegen of ↵Andrew Zhogin-1/+31
async_drop_in_place::{closure}, scoped async drop added.
2025-04-17do not emit `OpaqueCast` projections with `-Znext-solver`lcnr-0/+2
2025-04-15Split TypeFolder and FallibleTypeFolderMichael Goulet-0/+4
2025-04-07Make use generated TerminatorKind::Call have call_source UseSantiago Pastorino-0/+2
2025-04-03Tighten up assignment operator representations.Nicholas Nethercote-0/+36
In the AST, currently we use `BinOpKind` within `ExprKind::AssignOp` and `AssocOp::AssignOp`, even though this allows some nonsensical combinations. E.g. there is no `&&=` operator. Likewise for HIR and THIR. This commit introduces `AssignOpKind` which only includes the ten assignable operators, and uses it in `ExprKind::AssignOp` and `AssocOp::AssignOp`. (And does similar things for `hir::ExprKind` and `thir::ExprKind`.) This avoids the possibility of nonsensical combinations, as seen by the removal of the `bug!` case in `lang_item_for_binop`. The commit is mostly plumbing, including: - Adds an `impl From<AssignOpKind> for BinOpKind` (AST) and `impl From<AssignOp> for BinOp` (MIR/THIR). - `BinOpCategory` can now be created from both `BinOpKind` and `AssignOpKind`. - Replaces the `IsAssign` type with `Op`, which has more information and a few methods. - `suggest_swapping_lhs_and_rhs`: moves the condition to the call site, it's easier that way. - `check_expr_inner`: had to factor out some code into a separate method. I'm on the fence about whether avoiding the nonsensical combinations is worth the extra code.
2025-03-29Properly document FakeReadsMaja Kądziołka-28/+84
2025-02-24Move `impl` blocks out of `rustc_middle/src/mir/syntax.rs`.Nicholas Nethercote-112/+0
As the comment at the top says, this file is not supposed to contain any code. But some has crept in. This commit moves it out.
2025-02-20Improve how the MIR dialect/phase index is reported.Nicholas Nethercote-1/+1
The only visible change is to the filenames produce by `-Zdump-mir`. E.g. before and after: ``` h.main.003-000.analysis-post-cleanup.after.mir h.main.2-2-000.analysis-post-cleanup.after.mir ``` It also fixes a FIXME comment.
2025-02-20Improve MIR phase comments.Nicholas Nethercote-22/+29
I found the dialect/phase distinction quite confusing when I first read these comments. This commit clarifies things a bit.
2025-02-20Reflow `MirPhase` comments.Nicholas Nethercote-22/+25
Currently many of them exceed 100 chars, which makes them painful to read on a terminal that is 100 chars wide.
2025-02-19Rollup merge of #137213 - nnethercote:rm-rustc_middle-mir-tcx, r=compiler-errorsMatthias Krüger-1/+1
Remove `rustc_middle::mir::tcx` module. This is a really weird module. For example, what does `tcx` in `rustc_middle::mir::tcx::PlaceTy` mean? The answer is "not much". The top-level module comment says: > Methods for the various MIR types. These are intended for use after > building is complete. Awfully broad for a module that has a handful of impl blocks for some MIR types, none of which really relates to `TyCtxt`. `git blame` indicates the comment is ancient, from 2015, and made sense then. This module is now vestigial. This commit removes it and moves all the code within into `rustc_middle::mir::statement`. Some specifics: - `Place`, `PlaceRef`, `Rvalue`, `Operand`, `BorrowKind`: they all have `impl` blocks in both the `tcx` and `statement` modules. The commit merges the former into the latter. - `BinOp`, `UnOp`: they only have `impl` blocks in `tcx`. The commit moves these into `statement`. - `PlaceTy`, `RvalueInitializationState`: they are defined in `tcx`. This commit moves them into `statement` *and* makes them available in `mir::*`, like many other MIR types. r? `@tmandry`
2025-02-19Remove `rustc_middle::mir::tcx` module.Nicholas Nethercote-1/+1
This is a really weird module. For example, what does `tcx` in `rustc_middle::mir::tcx::PlaceTy` mean? The answer is "not much". The top-level module comment says: > Methods for the various MIR types. These are intended for use after > building is complete. Awfully broad for a module that has a handful of impl blocks for some MIR types, none of which really relates to `TyCtxt`. `git blame` indicates the comment is ancient, from 2015, and made sense then. This module is now vestigial. This commit removes it and moves all the code within into `rustc_middle::mir::statement`. Some specifics: - `Place`, `PlaceRef`, `Rvalue`, `Operand`, `BorrowKind`: they all have `impl` blocks in both the `tcx` and `statement` modules. The commit merges the former into the latter. - `BinOp`, `UnOp`: they only have `impl` blocks in `tcx`. The commit moves these into `statement`. - `PlaceTy`, `RvalueInitializationState`: they are defined in `tcx`. This commit moves them into `statement` *and* makes them available in `mir::*`, like many other MIR types.
2025-02-17Update and clarify the comment on `SwitchTargets`.Nicholas Nethercote-11/+19
2025-02-03Contracts core intrinsics.Felix S. Klock II-0/+3
These are hooks to: 1. control whether contract checks are run 2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-01Rollup merge of #130514 - compiler-errors:unsafe-binders, r=oli-obkMatthias Krüger-0/+7
Implement MIR lowering for unsafe binders This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are `Copy`. Later on, I'll introduce a new trait that relaxes this requirement to being "is `Copy` or `ManuallyDrop<T>`" which more closely models how we treat union fields. Namely, wrapping unsafe binders is now `Rvalue::WrapUnsafeBinder`, which acts much like an `Rvalue::Aggregate`. Unwrapping unsafe binders are implemented as a MIR projection `ProjectionElem::UnwrapUnsafeBinder`, which acts much like `ProjectionElem::Field`. Tracking: - https://github.com/rust-lang/rust/issues/130516
2025-01-31Implement MIR, CTFE, and codegen for unsafe bindersMichael Goulet-0/+7
2025-01-31Insert null checks for pointer dereferences when debug assertions are enabledBastian Kersting-0/+1
Similar to how the alignment is already checked, this adds a check for null pointer dereferences in debug mode. It is implemented similarly to the alignment check as a MirPass. This is related to a 2025H1 project goal for better UB checks in debug mode: https://github.com/rust-lang/rust-project-goals/pull/177.
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.