about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2024-06-23Replace `f16` and `f128` pattern matching stubs with real implementationsTrevor Gross-2/+2
This section of code depends on `rustc_apfloat` rather than our internal types, so this is one potential ICE that we should be able to melt now. This also fixes some missing range and match handling in `rustc_middle`.
2024-06-22Change comment to reflect switch to THIR unsafeckNadrieril-14/+10
2024-06-22Reuse `lower_let_expr` for `let .. else` loweringNadrieril-87/+49
2024-06-22Don't use fake wildcards when we can get the failure block directlyNadrieril-50/+59
This commit too was obtained by repeatedly inlining and simplifying.
2024-06-21Save 2 pointers in `TerminatorKind` (96 → 80 bytes)Scott McMurray-8/+10
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-20[GVN] Add tests for generic pointees with PtrMetadataScott McMurray-0/+4
2024-06-19Move `lower_match_tree`Nadrieril-65/+64
2024-06-19There's nothing to bind for a wildcardNadrieril-8/+1
This commit was obtained by repeatedly inlining and simplifying.
2024-06-19Small dedupNadrieril-18/+15
2024-06-19Only one caller of `lower_match_tree` was using the fake borrowsNadrieril-31/+17
2024-06-19We can traverse bindings before `lower_match_tree` nowNadrieril-50/+98
2024-06-19Auto merge of #126679 - fmease:rollup-njrv2py, r=fmeasebors-23/+48
Rollup of 6 pull requests Successful merges: - #125447 (Allow constraining opaque types during subtyping in the trait system) - #125766 (MCDC Coverage: instrument last boolean RHS operands from condition coverage) - #125880 (Remove `src/tools/rust-demangler`) - #126154 (StorageLive: refresh storage (instead of UB) when local is already live) - #126572 (override user defined channel when using precompiled rustc) - #126662 (Unconditionally warn on usage of `wasm32-wasi`) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-19Rollup merge of #125766 - RenjiSann:fresh-mcdc-branch-on-bool, r=nnethercoteLeón Orell Valerian Liehr-23/+48
MCDC Coverage: instrument last boolean RHS operands from condition coverage Fresh PR from #124652 -- This PR ensures that the top-level boolean expressions that are not part of the control flow are correctly instrumented thanks to condition coverage. See discussion on https://github.com/rust-lang/rust/issues/124120. Depends on `@Zalathar` 's condition coverage implementation #125756.
2024-06-19Rollup merge of #126553 - Nadrieril:expand-or-pat-into-above, r=matthewjasperLeón Orell Valerian Liehr-97/+120
match lowering: expand or-candidates mixed with candidates above This PR tweaks match lowering of or-patterns. Consider this: ```rust match (x, y) { (1, true) => 1, (2, false) => 2, (1 | 2, true | false) => 3, (3 | 4, true | false) => 4, _ => 5, } ``` One might hope that this can be compiled to a single `SwitchInt` on `x` followed by some boolean checks. Before this PR, we compile this to 3 `SwitchInt`s on `x`, because an arm that contains more than one or-pattern was compiled on its own. This PR groups branch `3` with the two branches above, getting us down to 2 `SwitchInt`s on `x`. We can't in general expand or-patterns freely, because this interacts poorly with another optimization we do: or-pattern simplification. When an or-pattern doesn't involve bindings, we branch the success paths of all its alternatives to the same block. The drawback is that in a case like: ```rust match (1, true) { (1 | 2, false) => unreachable!(), (2, _) => unreachable!(), _ => {} } ``` if we used a single `SwitchInt`, by the time we test `false` we don't know whether we came from the `1` case or the `2` case, so we don't know where to go if `false` doesn't match. Hence the limitation: we can process or-pattern alternatives alongside candidates that precede it, but not candidates that follow it. (Unless the or-pattern is the only remaining match pair of its candidate, in which case we can process it alongside whatever). This PR allows the processing of or-pattern alternatives alongside candidates that precede it. One benefit is that we now process or-patterns in a single place in `mod.rs`. r? ``@matthewjasper``
2024-06-19coverage: Make MCDC take in account last RHS of condition-coverageDorian Péron-23/+48
Condition coverage extends branch coverage to treat the specific case of last operands of boolean decisions not involved in control flow. This is ultimately made for MCDC to be exhaustive on all boolean expressions. This patch adds a call to `visit_branch_coverage_operation` to track the top-level operand of the said decisions, and changes `visit_coverage_standalone_condition` so MCDC branch registration is called when enabled on these _last RHS_ cases.
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-1/+1
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-3/+3
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-16Expand or-candidates mixed with candidates aboveNadrieril-97/+79
We can't mix them with candidates below them, but we can mix them with candidates above.
2024-06-16Factor out `finalize_or_candidate`Nadrieril-18/+42
2024-06-16Use `otherwise_block` for or-pattern shortcuttingNadrieril-3/+8
2024-06-16Always set `otherwise_block`sNadrieril-13/+20
2024-06-16Tweak simple or-pattern expansionNadrieril-16/+21
2024-06-15Rollup merge of #126354 - compiler-errors:variance, r=lcnrMatthias Krüger-4/+4
Use `Variance` glob imported variants everywhere Fully commit to using the globbed variance. Could be convinced the other way, and change this PR to not use the globbed variants anywhere, but I'd rather we do one or the other. r? lcnr
2024-06-14Use is_lang_item more aggressivelyMichael Goulet-3/+5
2024-06-12Use Variance glob import everywhereMichael Goulet-4/+4
2024-06-12Add TODO comment to unsafe env modificationTobias Bucher-0/+8
Addresses https://github.com/rust-lang/rust/pull/124636#issuecomment-2132119534. I think that the diff display regresses a little, because it's no longer showing the `+` to show where the `unsafe {}` is added. I think it's still fine.
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-0/+2
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-17/+13
2024-06-07Revert "Create const block DefIds in typeck instead of ast lowering"Oli Scherer-9/+14
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-1/+5
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-06Auto merge of #126056 - matthiaskrgr:rollup-ytwg62v, r=matthiaskrgrbors-34/+47
Rollup of 6 pull requests Successful merges: - #124731 (Add translation support by mdbook-i18n-helpers to bootstrap) - #125168 (Match ergonomics 2024: align implementation with RFC) - #125925 (Don't trigger `unsafe_op_in_unsafe_fn` for deprecated safe fns) - #125987 (When `derive`ing, account for HRTB on `BareFn` fields) - #126045 (check_expr_struct_fields: taint context with errors if struct definit…) - #126048 (Fix typos in cargo-specifics.md) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-05Don't trigger `unsafe_op_in_unsafe_fn` for deprecated safe fnsTobias Bucher-34/+47
Fixes #125875.
2024-06-05Add `Ty` to `mir::Const::Ty`Boxy-17/+26
2024-06-05Add `Ty` to `ConstKind::Value`Boxy-3/+3
2024-06-05Basic removal of `Ty` from places (boring)Boxy-4/+2
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-1/+5
2024-06-04Reduce `pub` exposure.Nicholas Nethercote-275/+275
A lot of errors don't need to be visible outside the crate, and some other things as well.
2024-06-04Remove out-of-date comment.Nicholas Nethercote-2/+0
Exhaustiveness and usefulness checking are now in `rustc_pattern_analysis`.
2024-05-31Rollup merge of #125756 - Zalathar:branch-on-bool, r=oli-obkMatthias Krüger-2/+63
coverage: Optionally instrument the RHS of lazy logical operators (This is an updated version of #124644 and #124402. Fixes #124120.) When `||` or `&&` is used outside of a branching context (such as the condition of an `if`), the rightmost value does not directly influence any branching decision, so branch coverage instrumentation does not treat it as its own true-or-false branch. That is a correct and useful interpretation of “branch coverage”, but might be undesirable in some contexts, as described at #124120. This PR therefore adds a new coverage level `-Zcoverage-options=condition` that behaves like branch coverage, but also adds additional branch instrumentation to the right-hand-side of lazy boolean operators. --- As discussed at https://github.com/rust-lang/rust/issues/124120#issuecomment-2092394586, this is mainly intended as an intermediate step towards fully-featured MC/DC instrumentation. It's likely that we'll eventually want to remove this coverage level (rather than stabilize it), either because it has been incorporated into MC/DC instrumentation, or because it's getting in the way of future MC/DC work. The main appeal of landing it now is so that work on tracking conditions can proceed concurrently with other MC/DC-related work. ````@rustbot```` label +A-code-coverage
2024-05-30Auto merge of #124636 - tbu-:pr_env_unsafe, r=petrochenkovbors-5/+44
Make `std::env::{set_var, remove_var}` unsafe in edition 2024 Allow calling these functions without `unsafe` blocks in editions up until 2021, but don't trigger the `unused_unsafe` lint for `unsafe` blocks containing these functions. Fixes #27970. Fixes #90308. CC #124866.
2024-05-30Rollup merge of #125754 - Zalathar:conditions-num, r=lqdMatthias Krüger-17/+17
coverage: Rename MC/DC `conditions_num` to `num_conditions` Updated version of #124571, without the other changes that were split out into #125108 and #125700. This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate. Some of the code touched by this PR could perhaps use some other changes, but I would prefer to keep this PR as a simple renaming and avoid scope creep. `@rustbot` label +A-code-coverage
2024-05-30Rollup merge of #125711 - oli-obk:const_block_ice2, r=NadrierilMatthias Krüger-21/+6
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes #125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
2024-05-30coverage: Instrument the RHS value of lazy logical operatorsZalathar-2/+63
When a lazy logical operator (`&&` or `||`) occurs outside of an `if` condition, it normally doesn't have any associated control-flow branch, so we don't have an existing way to track whether it was true or false. This patch adds special code to handle this case, by inserting extra MIR blocks in a diamond shape after evaluating the RHS. This gives us a place to insert the appropriate marker statements, which can then be given their own counters.
2024-05-30coverage: Rename MC/DC `conditions_num` to `num_conditions`Zalathar-17/+17
This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate.
2024-05-30Add `deprecated_safe` lintTobias Bucher-2/+36
It warns about usages of `std::env::{set_var, remove_var}` with an automatic fix wrapping the call in an `unsafe` block.
2024-05-29Make `std::env::{set_var, remove_var}` unsafe in edition 2024Tobias Bucher-4/+9
Allow calling these functions without `unsafe` blocks in editions up until 2021, but don't trigger the `unused_unsafe` lint for `unsafe` blocks containing these functions. Fixes #27970. Fixes #90308. CC #124866.
2024-05-29Rollup merge of #125700 - Zalathar:limit-overflow, r=nnethercoteMatthias Krüger-2/+3
coverage: Avoid overflow when the MC/DC condition limit is exceeded Fix for the test failure seen in https://github.com/rust-lang/rust/pull/124571#issuecomment-2099620869. If we perform this subtraction first, it can sometimes overflow to -1 before the addition can bring its value back to 0. That behaviour seems to be benign, but it nevertheless causes test failures in compiler configurations that check for overflow. ``@rustbot`` label +A-code-coverage
2024-05-29coverage: Avoid overflow when the MC/DC condition limit is exceededZalathar-2/+3
If we perform this subtraction and then add 1, the subtraction can sometimes overflow to -1 before the addition can bring its value back to 0. That behaviour seems to be benign, but it nevertheless causes test failures in compiler configurations that check for overflow. We can avoid the overflow by instead subtracting (N - 1), which is algebraically equivalent, and more closely matches what the code is actually trying to do.
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-21/+6
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-28Add custom mir support for `PtrMetadata`Scott McMurray-0/+1