about summary refs log tree commit diff
path: root/compiler/rustc_mir_build
AgeCommit message (Collapse)AuthorLines
2024-07-25Various notes on match loweringZalathar-54/+198
2024-07-24Improve "covered_by_many" errorNadrieril-19/+18
2024-07-24Explain why a given pattern is considered unreachableNadrieril-23/+78
2024-07-24Move rustc-specific entrypoint to the `rustc` moduleNadrieril-6/+10
2024-07-23Rollup merge of #125834 - ↵Matthias Krüger-2/+22
workingjubilee:weaken-thir-unsafeck-for-addr-of-static-mut, r=compiler-errors treat `&raw (const|mut) UNSAFE_STATIC` implied deref as safe Fixes rust-lang/rust#125833 As reported in that and related issues, `static mut STATIC_MUT: T` is very often used in embedded code, and is in many ways equivalent to `static STATIC_CELL: SyncUnsafeCell<T>`. The Rust expression of `&raw mut STATIC_MUT` and `SyncUnsafeCell::get(&STATIC_CELL)` are approximately equal, and both evaluate to `*mut T`. The library function is safe because it has *declared itself* to be safe. However, the raw ref operator is unsafe because all uses of `static mut` are considered unsafe, even though the static's value is not used by this expression (unlike, for example, `&STATIC_MUT`). We can fix this unnatural difference by simply adding the proper exclusion for the safety check inside the THIR unsafeck, so that we do not declare it unsafe if it is not. While the primary concern here is `static mut`, this change is made for all instances of an "unsafe static", which includes a static declared inside `extern "abi" {}`. Hypothetically, we could go as far as generalizing this to all instances of `&raw (const|mut) *ptr`, but today we do not, as we have not actually considered the range of possible expressions that use a similar encoding. We do not even extend this to thread-local equivalents, because they have less clear semantics.
2024-07-22compiler: treat `&raw (const|mut) UNSAFE_STATIC` implied deref as safeJubilee Young-2/+22
The implied deref to statics introduced by HIR->THIR lowering is only used to create place expressions, it lacks unsafe semantics. It is also confusing, as there is no visible `*ident` in the source. For both classes of "unsafe static" (extern static and static mut) allow this operation. We lack a clear story around `thread_local! { static mut }`, which is actually its own category of item that reuses the static syntax but has its own rules. It's possible they should be similarly included, but in the absence of a good reason one way or another, we do not bless it.
2024-07-22Rollup merge of #125990 - tbu-:pr_unsafe_env_lint_name, r=ehussTrevor Gross-2/+2
Rename `deprecated_safe` lint to `deprecated_safe_2024` Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`. Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375. r? `@ehuss`
2024-07-21Rollup merge of #128033 - Nadrieril:explain-empty-wildcards, r=compiler-errorsJubilee-16/+20
Explain why we require `_` for empty patterns This adds a note to the "non-exhaustive patterns" diagnostic to explain why we sometimes require extra `_` patterns on empty types. This is one of the two diagnostic improvements I wanted to do before [stabilizing `min_exhaustive_patterns`](https://github.com/rust-lang/rust/pull/122792). r? ``@compiler-errors``
2024-07-21Explain why we require `_` for empty patternsNadrieril-0/+4
2024-07-21Tweak `collect_non_exhaustive_tys`Nadrieril-16/+16
2024-07-20Rollup merge of #127917 - Zalathar:after-or, r=NadrierilMatthias Krüger-91/+129
match lowering: Split `finalize_or_candidate` into more coherent methods I noticed that `finalize_or_candidate` was responsible for several different postprocessing tasks, making it difficult to understand. This PR aims to clean up some of the confusion by: - Extracting `remove_never_subcandidates` from `merge_trivial_subcandidates` - Extracting `test_remaining_match_pairs_after_or` from `finalize_or_candidate` - Taking what remains of `finalize_or_candidate`, and inlining it into its caller --- Reviewing individual commits and ignoring whitespace is recommended. Most of the large-looking changes are just moving existing code around, mostly unaltered. r? ``@Nadrieril``
2024-07-20Rollup merge of #127556 - Zalathar:autoref, r=NadrierilMatthias Krüger-81/+84
Replace a long inline "autoref" comment with method docs This comment has two problems: - It is very long, making the flow of the enclosing method hard to follow. - It starts by talking about an `autoref` flag that hasn't existed since #59114. - This makes it hard to trust that the information in the comment is accurate or relevant, even though much of it still seems to be true. This PR therefore replaces the long inline comment with a revised doc comment on `bind_matched_candidate_for_guard`, and some shorter inline comments. For readers who want more historical context, we also link to the PR that added the old comment, and the PR that removed the `autoref` flag.
2024-07-20Inline `finalize_or_candidate`Zalathar-17/+7
2024-07-20Improve `test_remaining_match_pairs_after_or`Zalathar-0/+13
2024-07-20Split out `test_remaining_match_pairs_after_or`Zalathar-43/+58
Only the last candidate can possibly have more match pairs, so this can be separate from the main or-candidate postprocessing loop.
2024-07-20Improve `merge_trivial_subcandidates`Zalathar-5/+15
2024-07-20Split out `remove_never_subcandidates`Zalathar-37/+47
2024-07-18Rollup merge of #127858 - Zalathar:pair-tree, r=NadrierilMatthias Krüger-39/+46
match lowering: Rename `MatchPair` to `MatchPairTree` In #120904, `MatchPair` became able to store other match pairs as children, forming a tree. That has made the old name confusing, so this patch renames the type to `MatchPairTree`. This PR also includes a patch renaming the `test` method to `pick_test_for_match_pair`, since it would conflict with the main change. r? `@Nadrieril`
2024-07-18remove saw_const_match_error; check if pattern contains an Error insteadRalf Jung-14/+3
2024-07-18avoid creating an Instance only to immediately disassemble it againRalf Jung-41/+3
2024-07-18pattern lowering: make sure we never call user-defined PartialEq instancesRalf Jung-28/+17
2024-07-18const_to_pat: cleanup leftovers from when we had to deal with non-structural ↵Ralf Jung-226/+108
constants
2024-07-18valtree construction: keep track of which type was valtree-incompatibleRalf Jung-4/+3
2024-07-17Rollup merge of #127472 - Zalathar:block-and-unit, r=fmeaseMatthias Krüger-73/+86
MIR building: Stop using `unpack!` for `BlockAnd<()>` This is a subset of #127416, containing only the parts related to `BlockAnd<()>`. The first patch removes the non-assigning form of the `unpack!` macro, because it is frustratingly inconsistent with the main form. We can replace it with an ordinary method that discards the `()` and returns the block. The second patch then finds all of the remaining code that was using `unpack!` with `BlockAnd<()>`, and updates it to use that new method instead. --- Changes since original review of #127416: - Renamed `fn unpack_block` → `fn into_block` - Removed `fn unpack_discard`, replacing it with `let _: BlockAnd<()> = ...` (2 occurrences) - Tweaked `arm_end_blocks` to unpack earlier and build `Vec<BasicBlock>` instead of `Vec<BlockAnd<()>>`
2024-07-17Rename `deprecated_safe` lint to `deprecated_safe_2024`Tobias Bucher-2/+2
Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`. Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375.
2024-07-17Rename `test` to `pick_test_for_match_pair`Zalathar-3/+6
2024-07-17Rename `MatchPair` to `MatchPairTree`Zalathar-37/+41
In #120904, `MatchPair` became able to store other match pairs as children, forming a tree. That has made the old name confusing, so this patch renames the type to `MatchPairTree`.
2024-07-16Rollup merge of #127707 - Zalathar:expand-until, r=NadrierilMatthias Krüger-14/+19
match lowering: Use an iterator to find `expand_until` A small cleanup that I noticed while looking at #127164. This makes it easier to see that the split point is always the index after the found item, or the whole list if no stopping point was found. r? `@Nadrieril`
2024-07-16Rollup merge of #127709 - Zalathar:pair-mod, r=NadrierilTrevor Gross-245/+272
match lowering: Move `MatchPair` tree creation to its own module This makes it easier to see that `MatchPair::new` has only one non-recursive caller, because the recursive callers are all in this module. No functional changes. --- I have used `git diff --color-moved` to verify that the moved code is identical to the old code, except for reduced visibility on the helper methods.
2024-07-16Use an iterator to find `expand_until`Zalathar-14/+19
This makes it easier to see that the split point is always the index after the found item, or the whole list if no stopping point was found.
2024-07-14Add cache for `allocate_str`Adwin White-1/+1
2024-07-14Improve internal docs for `MatchPair`Zalathar-5/+24
2024-07-14Move `MatchPair` tree creation to its own moduleZalathar-240/+248
This makes it easier to see that `MatchPair::new` has only one non-recursive caller, because the recursive callers are all in this module.
2024-07-10Replace a long inline "autoref" comment with method docsZalathar-81/+84
This comment has two problems: - It is very long, making the flow of the enclosing method hard to follow. - It starts by talking about an `autoref` flag that hasn't existed since #59114. This PR therefore replaces the long inline comment with a revised doc comment on `bind_matched_candidate_for_guard`, and some shorter inline comments. For readers who want more historical context, we also link to the PR that added the old comment, and the PR that removed the `autoref` flag.
2024-07-09Address review commentsNadrieril-4/+4
2024-07-09Return the `otherwise_block` instead of passing it as argumentNadrieril-57/+29
This saves a few blocks and matches the common `unpack!` paradigm.
2024-07-09Factor out the "process remaining candidates" casesNadrieril-44/+30
2024-07-09Don't try to save an extra blockNadrieril-13/+9
This is preparation for the next commit.
2024-07-09Move or-pattern expansion inside the main part of the algorithmNadrieril-36/+24
2024-07-09Factor out the special handling of or-patternsNadrieril-81/+104
2024-07-09Move a functionNadrieril-19/+19
2024-07-09Auto merge of #127028 - Nadrieril:fix-or-pat-expansion, r=matthewjasperbors-0/+3
Fix regression in the MIR lowering of or-patterns In https://github.com/rust-lang/rust/pull/126553 I made a silly indexing mistake and regressed the MIR lowering of or-patterns. This fixes it. r? `@compiler-errors` because I'd like this to be merged quickly :pray:
2024-07-08Auto merge of #113128 - WaffleLapkin:become_trully_unuwuable, r=oli-obk,RalfJungbors-2/+139
Support tail calls in mir via `TerminatorKind::TailCall` This is one of the interesting bits in tail call implementation — MIR support. This adds a new `TerminatorKind` which represents a tail call: ```rust TailCall { func: Operand<'tcx>, args: Vec<Operand<'tcx>>, fn_span: Span, }, ``` *Structurally* this is very similar to a normal `Call` but is missing a few fields: - `destination` — tail calls don't write to destination, instead they pass caller's destination to the callee (such that eventual `return` will write to the caller of the function that used tail call) - `target` — similarly to `destination` tail calls pass the caller's return address to the callee, so there is nothing to do - `unwind` — I _think_ this is applicable too, although it's a bit confusing - `call_source` — `become` forbids operators and is not created as a lowering of something else; tail calls always come from HIR (at least for now) It might be helpful to read the interpreter implementation to understand what `TailCall` means exactly, although I've tried documenting it too. ----- There are a few `FIXME`-questions still left, ideally we'd be able to answer them during review ':) ----- r? `@oli-obk` cc `@scottmcm` `@DrMeepster` `@JakobDegen`
2024-07-08Stop using `unpack!` for `BlockAnd<()>`Zalathar-29/+26
2024-07-08Remove the non-assigning form of `unpack!`Zalathar-44/+60
This kind of unpacking can be expressed as an ordinary method on `BlockAnd<()>`.
2024-07-07Fix conflicts after rebaseMaybe Lapkin-1/+1
- r-l/r 126784 - r-l/r 127113 - r-l/miri 3562
2024-07-07Fix unconditional recursion lint wrt tail callsMaybe Waffle-2/+16
2024-07-07Properly handle drops for tail callsDrMeepster-18/+107
2024-07-07Support tail calls in mir via `TerminatorKind::TailCall`Maybe Waffle-2/+36
2024-07-05coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`Zalathar-60/+73
This opens the door to collecting and storing coverage information that is unrelated to branch coverage or MC/DC.