about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2024-03-02Tiny missed simplificationNadrieril-5/+2
2024-03-02Rollup merge of #121892 - Zalathar:expr-kind-let, r=NadrierilMatthias Krüger-32/+6
The ordinary lowering of `thir::ExprKind::Let` is unreachable After desugaring, `let` expressions should only appear inside `if` expressions or `match` guards, possibly nested within a let-chain. In both cases they are specifically handled by the lowerings of those expressions, so this case is currently unreachable. --- Context: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Lowering.20of.20.60thir.3A.3AExprKind.3A.3ALet.60.20is.20unreachable My conclusions are partly based on the observation that stubbing out this match arm doesn't cause any test failures. So either this really is unreachable, or it can be reached in some obscure circumstances that our test suite doesn't cover. If we end up needing this code (or something like it) for an implementation of https://github.com/rust-lang/rfcs/pull/3573, it should be easy enough to pull it back out of version control history. I looked into having the `if`/`match` lowerings call back into `expr_into_dest`, but from what I can tell that won't work well, because there are extra scoping considerations that require some awareness of the enclosing if/match. r? ```@Nadrieril```
2024-03-02The ordinary lowering of `thir::ExprKind::Let` is unreachableZalathar-32/+6
After desugaring, `let` expressions should only appear inside `if` expressions or `match` guards, possibly nested within a let-chain. In both cases they are specifically handled by the lowerings of those expressions, so this case is currently unreachable.
2024-03-02Rollup merge of #121715 - Nadrieril:testcase-or, r=matthewjasperMatthias Krüger-122/+155
match lowering: pre-simplify or-patterns too This is the final part of my work to simplify match pairs early: now we do it for or-patterns too. This makes it possible to collect fake borrows separately from the main match lowering algorithm. That'll enable more simplifications of or-pattern handling. Note: I was tempted to have `Candidate` contain a `FlatPat`, but there are so many places that use `candidate.match_pairs` etc directly that I chose not to. r? `@matthewjasper`
2024-03-01Rollup merge of #121750 - Nadrieril:switchkind-if, r=matthewjasperMatthias Krüger-49/+45
match lowering: Separate the `bool` case from other integers in `TestKind` `TestKind::SwitchInt` had a special case for `bool` essentially everywhere it's used, so I made `TestKind::If` to handle the bool case on its own. r? `@matthewjasper`
2024-03-01Rollup merge of #121706 - Nadrieril:simplify-sort-candidate, r=matthewjasperMatthias Krüger-34/+17
match lowering: Remove hacky branch in sort_candidate Reusing `self.test()` there wasn't actually pulling a lot of weight. In particular the `TestKind::Len` cases were all already correctly handled. r? `@matthewjasper`
2024-03-01Rollup merge of #121784 - Zalathar:if-or-converge, r=NadrierilMatthias Krüger-2/+8
Make the success arms of `if lhs || rhs` meet up in a separate block Extracted from #118305, where this is necessary to avoid introducing a bug when injecting marker statements into the then/else arms. --- In the previous code (#111752), the success block of `lhs` would jump directly to the success block of `rhs`. However, `rhs_success_block` could already contain statements that are specific to the RHS, and the direct goto causes them to be executed in the LHS success path as well. This patch therefore creates a fresh block that the LHS and RHS success blocks can both jump to. --- I think the reason we currently get away with this is that `rhs_success_block` usually doesn't contain anything other than StorageDead statements for locals used by the RHS, and those statements don't seem to cause problems in the LHS success path (which never makes those locals live). But if we start adding meaningful statements for branch coverage (or MC/DC coverage), it's important to keep the LHS and RHS blocks separate.
2024-03-01Auto merge of #121728 - tgross35:f16-f128-step1-ty-updates, r=compiler-errorsbors-0/+4
Add stubs in IR and ABI for `f16` and `f128` This is the very first step toward the changes in https://github.com/rust-lang/rust/pull/114607 and the [`f16` and `f128` RFC](https://rust-lang.github.io/rfcs/3453-f16-and-f128.html). It adds the types to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`, and just propagates those out as `unimplemented!` stubs where necessary. These types do not parse yet so there is no feature gate, and it should be okay to use `unimplemented!`. The next steps will probably be AST support with parsing and the feature gate. r? `@compiler-errors` cc `@Nilstrieb` suggested breaking the PR up in https://github.com/rust-lang/rust/pull/120645#issuecomment-1925900572
2024-02-29Rollup merge of #121376 - Nadrieril:mir-half-ranges, r=pnkfelixGuillaume Gomez-22/+30
Skip unnecessary comparison with half-open range patterns This is the last remaining detail in the implementation of half-open range patterns. Until now, a half-open range pattern like `10..` was converted to `10..T::MAX` before lowering to MIR, which generated an extra pointless comparison. With this PR we don't generate it.
2024-02-29Make the success arms of `if lhs || rhs` meet up in a separate blockZalathar-2/+8
In the previous code, the success block of `lhs` would jump directly to the success block of `rhs`. However, `rhs_success_block` could already contain statements that are specific to the RHS, and the direct goto causes them to be executed in the LHS success path as well. This patch therefore creates a fresh block that the LHS and RHS success blocks can both jump to.
2024-02-28Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`Trevor Gross-0/+4
Make changes necessary to support these types in the compiler.
2024-02-28Separate the `bool` case from other integers in `TestKind`Nadrieril-49/+45
2024-02-28No need to pass `fake_borrows` everywhere nowNadrieril-45/+8
2024-02-28Collect fake borrows ahead of timeNadrieril-40/+83
2024-02-28Pre-simplify or-patterns tooNadrieril-40/+67
2024-02-28Lower bindings in a predictable orderNadrieril-50/+20
2024-02-28Appease rust-analyzerNadrieril-4/+4
For some reason it doesn't figure out the slice coercion.
2024-02-28Rename `DiagnosticArg{,Map,Name,Value}` as `DiagArg{,Map,Name,Value}`.Nicholas Nethercote-14/+14
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-12/+9
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-27Group default cases in `sort_candidate`Nadrieril-17/+9
2024-02-27Remove hacky branch in `sort_candidate`Nadrieril-23/+14
Reusing `self.test` wasn't actually pulling a lot of weight.
2024-02-27Skip unnecessary comparison with half-open rangesNadrieril-22/+30
2024-02-25make non-PartialEq-typed consts as patterns a hard errorRalf Jung-15/+14
2024-02-24Rollup merge of #121374 - Nadrieril:factor-explain, r=matthewjasperMatthias Krüger-151/+218
match lowering: Split off `test_candidates` into several functions and improve comments The logic of `test_candidates` has three steps: pick a test, sort the candidates, and generate code for everything. So I split it off into three methods. I also ended up reworking the comments that explain the algorithm. In particular I added detailed examples. I removed the digression about https://github.com/rust-lang/rust/issues/29740 because it's no longer relevant to how the code is structured today. r? ``@matthewjasper``
2024-02-24Implement asm goto in MIR and MIR loweringGary Guo-9/+24
2024-02-24Change InlineAsm to allow multiple targets insteadGary Guo-6/+7
2024-02-24Add asm label support to THIRGary Guo-2/+11
2024-02-24Add asm label support to AST and HIRGary Guo-0/+3
2024-02-24Tweak debug!() callGuillaume Boisseau-1/+1
Co-authored-by: matthewjasper <20113453+matthewjasper@users.noreply.github.com>
2024-02-23compiler: clippy::complexity fixesMatthias Krüger-12/+7
2024-02-22Rollup merge of #121427 - nnethercote:fix-Rocket, r=oli-obkMatthias Krüger-2/+4
Fix panic when compiling `Rocket`. This panic was reported [here](https://github.com/rust-lang/rust/pull/120576#issuecomment-1957515484). r? ``@oli-obk``
2024-02-22Make some `IntoDiagnostic` impls generic.Nicholas Nethercote-2/+4
PR #119097 made the decision to make all `IntoDiagnostic` impls generic, because this allowed a bunch of nice cleanups. But four hand-written impls were unintentionally overlooked. This commit makes them generic.
2024-02-21Inline `simplify_match_pair`Nadrieril-34/+18
2024-02-21Process bindings and ascriptions in `MatchPair::new()`Nadrieril-90/+77
2024-02-21Introduce `TestCase` enum to replace most matching on `PatKind`Nadrieril-143/+132
2024-02-21Tiny simplificationNadrieril-24/+16
2024-02-21Rollup merge of #121175 - Nadrieril:simplify-or-selection, r=matthewjasperLeón Orell Valerian Liehr-40/+51
match lowering: test one or pattern at a time This is a bit more opinionated than the previous PRs. On the face of it this is less efficient and more complex than before, but I personally found the loop that digs into `leaf_candidates` on each iteration very confusing. Instead this does "generate code for this or-pattern" then "generate further code for each branch if needed" in two steps. Incidentally this way we don't _require_ or patterns to be sorted at the end. It's still an important optimization but I find it clearer to not rely on it for correctness. r? `@matthewjasper`
2024-02-21Split off `test_candidates` into several functions and improve commentsNadrieril-151/+218
2024-02-21Test one or pattern at a timeNadrieril-29/+42
2024-02-21Tweak block managementNadrieril-13/+11
2024-02-21Rollup merge of #121208 - nnethercote:delayed_bug-to-bug, r=lcnrDylan DPC-28/+18
Convert `delayed_bug`s to `bug`s. I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. This is too dangerous to merge. Increased coverage (fuzzing or a crater run) would likely hit more cases. But it might be useful for people to look at and think about which paths are genuinely unreachable. r? `@ghost`
2024-02-21Auto merge of #121172 - Nadrieril:simplify-empty-selection, r=matthewjasperbors-103/+62
match lowering: simplify empty candidate selection In match lowering, `match_simplified_candidates` is tasked with removing candidates that are fully matched and linking them up properly. The code that does that was needlessly complicated; this PR simplifies it. The overall change isn't big but I split it up into tiny commits to convince myself that I was correctly preserving behavior. The test changes are all due to the first commit. Let me know if you'd prefer me to split up the PR to make reviewing easier. r? `@matthewjasper`
2024-02-21Auto merge of #120904 - Nadrieril:match-lowering-intermediate-repr, ↵bors-256/+215
r=matthewjasper match lowering: eagerly simplify match pairs This removes one important complication from match lowering. Before this, match pair simplification (which includes collecting bindings and type ascriptions) was intertwined with the whole match lowering algorithm. I'm avoiding this by storing in each `MatchPair` the sub-`MatchPair`s that correspond to its subfields. This makes it possible to simplify everything (except or-patterns) in `Candidate::new()`. This should open up further simplifications. It will also give us proper control over the order of bindings. r? `@matthewjasper`
2024-02-21Convert `bug`s back to `delayed_bug`s.Nicholas Nethercote-10/+10
This commit undoes some of the previous commit's mechanical changes, based on human judgment.
2024-02-21Convert `delayed_bug`s to `bug`s.Nicholas Nethercote-28/+18
I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. The next commit will convert some more back, based on human judgment.
2024-02-20Upgrade a `debug_assert` to `assert`Nadrieril-4/+1
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-3/+11
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-19Update commentsNadrieril-8/+5
2024-02-19Don't default `fully_matched` to false to avoid mistakesNadrieril-10/+23
2024-02-19Compute subpairs when creating match pairNadrieril-78/+72