Commit Graph

35520 Commits

Author SHA1 Message Date
David Koloski 1b934f3e8c Sort mutually-exclusive pairs, update fixed tests 2024-05-15 15:40:52 +00:00
David Koloski d7d3bd1221 Relax restrictions on multiple sanitizers
Most combinations of LLVM sanitizers are legal-enough to enable
simultaneously. This change will allow simultaneously enabling ASAN and
shadow call stacks on supported platforms.
2024-05-15 15:40:52 +00:00
bors 7a58674259 Auto merge of #124255 - RenjiSann:renji/mcdc-nested-expressions, r=Zalathar
MCDC coverage: support nested decision coverage

#123409 provided the initial MCDC coverage implementation.

As referenced in #124144, it does not currently support "nested" decisions, like the following example :

```rust
fn nested_if_in_condition(a: bool, b: bool, c: bool) {
    if a && if b || c { true } else { false } {
        say("yes");
    } else {
        say("no");
    }
}
```

Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression.

This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one.
When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions.

On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
2024-04-29 11:54:49 +00:00
Dorian Péron 60ca9b6e29 mcdc-coverage: Get decision_depth from THIR lowering
Use decision context stack to handle nested decisions:
- Introduce MCDCDecisionCtx
- Use a stack of MCDCDecisionCtx to handle nested decisions
2024-04-29 09:13:40 +00:00
Dorian Péron ae8c023983 mcdc-coverage: Add decision_depth field in structs
Add decision_depth field to TVBitmapUpdate/CondBitmapUpdate statements
Add decision_depth field to BcbMappingKinds MCDCBranch and MCDCDecision
Add decision_depth field to MCDCBranchSpan and MCDCDecisionSpan
2024-04-29 09:13:40 +00:00
Dorian Péron 3c2f48ede9 mcdc-coverage: Add possibility for codegen llvm to handle several condition bitmaps 2024-04-29 08:41:15 +00:00
bors 1fffb2a355 Auto merge of #124431 - chenyukang:yukang-fix-rustdoc-124363, r=Nadrieril
Fix the assertion crash from rustdoc document indent widths

Fixes #124363
2024-04-28 21:20:07 +00:00
Matthias Krüger 7ab3997970
Rollup merge of #124463 - gurry:rename-func, r=TaKO8Ki
Rename `inhibit_union_abi_opt()` to `inhibits_union_abi_opt()`

`inihibit` seems to suggest that this function will inhibit optimizations whereas `inhibits` correctly indicates that it will merely _check_ that. With `inhibits` if conditions read more naturally e.g.:

```rust
if repr.inhibits_union_abi_opt() {
}
```
2024-04-28 13:34:42 +02:00
Matthias Krüger a7771385e5
Rollup merge of #124444 - compiler-errors:eval, r=lcnr
Record certainty of `evaluate_added_goals_and_make_canonical_response` call in candidate

Naming subject to bikeshedding, but I will need this when moving `select` to a proof tree visitor.

r? lcnr
2024-04-28 13:34:41 +02:00
Gurinder Singh 4aafec1bc1 Rename `inihibit_union_abi_opt()` to `inihibits_union_abi_opt()`
The present tense makes it read more naturally at use site i.e.
"this repr _inhibits_ optimizations"
2024-04-28 13:09:36 +05:30
yukang 6faedd381b Fix the assertion crash from rustdoc document indent widths 2024-04-28 11:17:09 +08:00
Michael Goulet 17728a9bb2 Record certainty of evaluate_added_goals_and_make_canonical_response call in candidate 2024-04-27 17:46:29 -04:00
Matthias Krüger 9c634f95bf
Rollup merge of #124437 - linyihai:doc-link-typeck, r=compiler-errors
doc: Make the `mod.rs` in the comment point to the correct location

The origin `mod.rs` had moved to `rustc_hir_analysis::check`, but the annotation doesn't point to it.

See [the origin PR](https://github.com/rust-lang/rust/pull/61857/files#diff-b65997b61ccd8d8e08238c925d631207671aca506e93ce7c5cfa0bec134c0a8e).
2024-04-27 20:46:09 +02:00
Matthias Krüger 0430e743e4
Rollup merge of #124425 - saethlin:ceci-nest-pas-une-ice, r=compiler-errors
Do not ICE on invalid consts when walking mono-reachable blocks

The `bug!` here was written under the logic of "this condition is impossible, right?" except that of course, if the compiler is given code that results in an compile error, then the situation is possible.

So now we just direct errors into the already-existing path for when we can't do a mono-time optimization.
2024-04-27 20:46:08 +02:00
Matthias Krüger aeb4c0413c
Rollup merge of #124394 - gurry:123863-ice-unexpected-region, r=lcnr
Fix ICE on invalid const param types

Fixes ICE #123863 which occurs because the const param has a type which is not a `bool`, `char` or an integral type.

The ICEing code path begins here in `typeck_with_fallback`: cb3752d20e/compiler/rustc_hir_typeck/src/lib.rs (L167)

The `fallback` invokes the `type_of` query and that eventually ends up calling `ct_infer` from the lowering code over here:
cb3752d20e/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs (L561) and `ct_infer` ICEs at this location: cb3752d20e/compiler/rustc_hir_analysis/src/collect.rs (L392)

To fix the ICE it I'm triggering a `span_delayed_bug` before we hit `ct_infer` if the type of the const param is not one of the supported types

### Edit
On `@lcnr's` suggestion I've changed the approach to not let `ReStatic` region hit the `bug!` in `ct_infer` instead of triggering a `span_delayed_bug`.
2024-04-27 20:46:08 +02:00
Matthias Krüger 52ce43e9ac
Rollup merge of #124370 - ShE3py:substitution-part-offset, r=fee1-dead
Fix substitution parts having a shifted underline in some cases

If two suggestions parts are side by side, the underline's offset:
(WIP PR as an example, not yet pushed)
```
error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++
```
The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.)

```
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~ +++++++++++++
```

``@rustbot`` label +A-suggestion-diagnostics
2024-04-27 20:46:07 +02:00
Lin Yihai 4faaa53392 doc: Replace mod.rs with the appropriate link 2024-04-27 21:22:04 +08:00
Matthias Krüger cf07246ae9
Rollup merge of #124382 - petrochenkov:itemvisit, r=lcnr
ast: Generalize item kind visiting

And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).

The diff is better viewed with whitespace ignored.
2024-04-27 07:55:37 +02:00
Gurinder Singh c62bc31b16 Fix ICE on invalid const param types 2024-04-27 09:36:38 +05:30
Ben Kimock 82cc02a60b Do not ICE on invalid consts when walking mono-reachable blocks 2024-04-26 23:06:21 -04:00
Jacob Pratt 608f71ec66
Rollup merge of #124391 - nnethercote:builtin_macros-cleanups, r=fee1-dead
`rustc_builtin_macros` cleanups

Some improvements I found while looking over this code.

r? ``@fee1-dead``
2024-04-26 19:25:55 -04:00
Jacob Pratt 645a4d34fb
Rollup merge of #124341 - petrochenkov:nomacvisit, r=compiler-errors
resolve: Remove two cases of misleading macro call visiting

Macro calls are ephemeral, they should not add anything to the definition tree, even if their AST could contains something with identity.
Thankfully, macro call AST cannot contain anything like that, so these walks are just noops.
In majority of other places in def_collector / build_reduced_graph they are already not visited.

(Also, a minor match reformatting is included.)
2024-04-26 19:25:54 -04:00
bors 1b3a32958b Auto merge of #122385 - lcnr:analyze-obligations-for-infer, r=compiler-errors
`obligations_for_self_ty`: use `ProofTreeVisitor` for nested goals

As always, dealing with proof trees continues to be a hacked together mess. After this PR and #124380 the only remaining blocker for core is https://github.com/rust-lang/trait-system-refactor-initiative/issues/90. There is also a `ProofTreeVisitor` issue causing an ICE when compiling `alloc` which I will handle in a separate PR. This issue likely affects coherence diagnostics more generally.

The core idea is to extend the proof tree visitor to support visiting nested candidates without using a `probe`. We then simply recurse into nested candidates if they are the only potentially applicable candidate for a given goal and check whether the self type matches the expected one.

For that to work, we need to improve `CanonicalState` to also handle unconstrained inference variables created inside of the trait solver. This is done by extending the `var_values` of `CanoncalState` with each fresh inference variables. Furthermore, we also store the state of all inference variables at the end of each probe. When recursing into `InspectCandidates` we then unify the values of all these states.

r? `@compiler-errors`
2024-04-26 15:37:05 +00:00
Nicholas Nethercote 30d6f63b4e Adjust some `pub`s. 2024-04-26 13:29:20 +10:00
bors 6acb9e75eb Auto merge of #120845 - petrochenkov:debmac, r=oli-obk
debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and `#[collapse_debuginfo]`

`-Z debug-macros` is "stabilized" by enabling it by default and removing.

`-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`.
It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no.

Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local) - https://github.com/rust-lang/rust/issues/100758#issuecomment-1935815625 describes some debugging scenarios that motivate this default as reasonable.
`#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.

Stabilization report: https://github.com/rust-lang/rust/pull/120845#issuecomment-1939145242

Closes https://github.com/rust-lang/rust/issues/100758
Closes https://github.com/rust-lang/rust/issues/41743
Closes https://github.com/rust-lang/rust/issues/39153
2024-04-26 02:13:08 +00:00
Michael Goulet 88eae31261
Rollup merge of #124381 - compiler-errors:derived-for-wf, r=lcnr
Renamed `DerivedObligation` to `WellFormedDeriveObligation`

It's used when computing `WellFormed` obligations, so let's give it a less ambiguous name.
2024-04-25 20:07:41 -04:00
Michael Goulet 4494140244
Rollup merge of #124379 - compiler-errors:remove-new-solver-lookup-behavior, r=lcnr
Remove special-casing for `SimplifiedType` for next solver

It's unnecessary due to the way that we fully normalize the self type before assembly begins.

r? lcnr
2024-04-25 20:07:41 -04:00
Nicholas Nethercote 8dc84fa7d1 Move some functions from `rustc_expand` to `rustc_builtin_macros`.
These functions are only used in `rustc_builtin_macros`, so it makes
sense for them to live there. This allows them to be changed from `pub`
to `pub(crate)`.
2024-04-26 09:24:33 +10:00
Nicholas Nethercote e2d2b1c698 Introduce `DeriveResolution`.
Making this a proper struct, and giving its fields names, makes things
easier to understand.
2024-04-26 07:55:21 +10:00
Michael Goulet 132f8ce3dc Renamed DerivedObligation to WellFormedDeriveObligation 2024-04-25 16:55:15 -04:00
bors 3a36386dc1 Auto merge of #124386 - matthiaskrgr:rollup-0a6yr00, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #124313 (Detect borrow error involving sub-slices and suggest `split_at_mut`)
 - #124374 (Don't ICE when `codegen_select_candidate` returns ambiguity in new solver)
 - #124380 (`Range` iteration specialization: remove trivial bounds)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-25 20:31:14 +00:00
lcnr b64f687cb0 use `EagerResolver` 2024-04-25 20:19:01 +00:00
Vadim Petrochenkov 7517a4f882 ast: Visit item components in "natural" order 2024-04-25 22:50:06 +03:00
Vadim Petrochenkov 5be9fdd636 ast: Generalize item kind visiting
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-25 22:49:58 +03:00
lcnr 03878c682a hir typeck: look into nested goals
uses a `ProofTreeVisitor` to look into nested
goals when looking at the pending obligations
during hir typeck. Used by closure signature
inference, coercion, and for async functions.
2024-04-25 19:44:00 +00:00
Vadim Petrochenkov 98804c1786 debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and `#[collapse_debuginfo]`
`-Z debug-macros` is "stabilized" by enabling it by default and removing.

`-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`.
It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no.

Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local).
`#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.
2024-04-25 22:14:47 +03:00
Matthias Krüger 6c21abf291
Rollup merge of #124374 - compiler-errors:fix-ambiguity-ice, r=lcnr
Don't ICE when `codegen_select_candidate` returns ambiguity in new solver

Because we merge identical candidates, we may have >1 impl candidate to in `codegen_select_error` but *not* have a trait error.

r? lcnr
2024-04-25 21:12:17 +02:00
Matthias Krüger 60c825f1e1
Rollup merge of #124313 - estebank:split-at-mut, r=fee1-dead
Detect borrow error involving sub-slices and suggest `split_at_mut`

```
error[E0499]: cannot borrow `foo` as mutable more than once at a time
  --> $DIR/suggest-split-at-mut.rs:13:18
   |
LL |     let a = &mut foo[..2];
   |                  --- first mutable borrow occurs here
LL |     let b = &mut foo[2..];
   |                  ^^^ second mutable borrow occurs here
LL |     a[0] = 5;
   |     ---- first borrow later used here
   |
   = help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```

Address most of #58792.

For follow up work, we should emit a structured suggestion for cases where we can identify the exact `let (a, b) = foo.split_at_mut(2);` call that is needed.
2024-04-25 21:12:17 +02:00
Michael Goulet f2518cd798 Remove special-casing for SimplifiedType for next solver 2024-04-25 14:27:39 -04:00
Esteban Küber 64a4cdcfd4 review comment: rename method 2024-04-25 18:26:36 +00:00
bors 38dd569150 Auto merge of #124377 - matthiaskrgr:rollup-ajxjq35, r=matthiaskrgr
Rollup of 2 pull requests

Successful merges:

 - #124287 (Improved code with clippy)
 - #124326 (tests: remove few ignore-stage2)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-25 17:12:29 +00:00
Matthias Krüger b28721fd96
Rollup merge of #124287 - 41Leahcim:master, r=fmease
Improved code with clippy

I haven't used the bootstrapped compiler, but I think I have made some improvements using clippy. I have already made the following changes to the compiler:
Replaced `self.first().is_digit(10)` with `self.first().is_ascii_digit()` on lines 633, 664, and 680 of compiler/rust_lexer/src/lib.rs.

Removed unnecessary cast on line 262 of compiler/rustc_lexer/src/unescape.rs

Replaced ok_or_else with ok_or on line 303 of compiler/rustc_lexer/src/unescape.rs

Replaced `!std::env::var("RUSTC_BOOTSTRAP").is_ok()` with `std::env::var("RUSTC_BOOTSTRAP").is_err()` on line 4 of compiler/rustc_macros/build.rs

Removed needless borrow for generic argument `env`on line 53 of compiler/rust_llvm/build.rs
2024-04-25 18:57:56 +02:00
Esteban Küber abdb64d4ea Check equivalence of indices in more cases 2024-04-25 16:55:33 +00:00
Esteban Küber ad6ae61246 Don't suggest `split_at_mut` when the multiple borrows have the same index 2024-04-25 16:55:33 +00:00
Esteban Küber 9f9f0aa534 Mention `split_at_mut` when mixing mutability in indexing ops
Emit suggestion when encountering

```rust
let a = &mut foo[0];
let b = &foo[1];
a.use_mut();
```
2024-04-25 16:55:33 +00:00
Esteban Küber dbaa4e2148 Only suggest `split_at_mut` on indexing borrowck errors for std types 2024-04-25 16:55:32 +00:00
Esteban Küber 386236f289 Detect borrow error involving sub-slices and suggest `split_at_mut`
```
error[E0499]: cannot borrow `foo` as mutable more than once at a time
  --> $DIR/suggest-split-at-mut.rs:13:18
   |
LL |     let a = &mut foo[..2];
   |                  --- first mutable borrow occurs here
LL |     let b = &mut foo[2..];
   |                  ^^^ second mutable borrow occurs here
LL |     a[0] = 5;
   |     ---- first borrow later used here
   |
   = help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```

Address most of #58792.

For follow up work, we should emit a structured suggestion for cases where we can identify the exact `let (a, b) = foo.split_at_mut(2);` call that is needed.
2024-04-25 16:55:32 +00:00
Michael Goulet cc606174a6 Don't ICE when codegen_select returns ambiguity in new solver 2024-04-25 11:49:12 -04:00
lcnr 662eadbafb `pub(in super::super)` to `pub(crate)`
`super::super` of `rustc_hir_typeck::fn_ctxt::_impl`
is just `rustc_hir_typeck`.
2024-04-25 15:21:46 +00:00
lcnr 2293f1ed6a `obligations_for_self_ty` to sub module 2024-04-25 15:21:46 +00:00