Commit Graph

2393 Commits

Author SHA1 Message Date
lcnr
9cba14b95b use TypingEnv when no infcx is available
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-18 10:38:56 +01:00
Matthias Krüger
5c81dbf4fa
Rollup merge of #132134 - nnethercote:rm-ResultsVisitable, r=cjgillot
Remove `ResultsVisitable`

`ResultsVisitable` has annoyed me for a while. This PR removes it. Details in the individual commits.

r? `@cjgillot.`
2024-11-16 21:05:44 +01:00
Trevor Gross
5d818914af Always inline functions signatures containing f16 or f128
There are a handful of tier 2 and tier 3 targets that cause a LLVM crash
or linker error when generating code that contains `f16` or `f128`. The
cranelift backend also does not support these types. To work around
this, every function in `std` or `core` that contains these types must
be marked `#[inline]` in order to avoid sending any code to the backend
unless specifically requested.

However, this is inconvenient and easy to forget. Introduce a check for
these types in the frontend that automatically inlines any function
signatures that take or return `f16` or `f128`.

Note that this is not a perfect fix because it does not account for the
types being passed by reference or as members of aggregate types, but
this is sufficient for what is currently needed in the standard library.

Fixes: https://github.com/rust-lang/rust/issues/133035
Closes: https://github.com/rust-lang/rust/pull/133037
2024-11-14 16:18:41 -06:00
clubby789
8c64e9d17d Rename PASS_NAMES to disambiguate 2024-11-12 13:28:05 +00:00
clubby789
12036830d0 Store known passes as an IndexSet 2024-11-12 13:28:05 +00:00
clubby789
94371d5a8c Validate and test -Zmir-enable-passes 2024-11-12 13:28:05 +00:00
clubby789
2a9cc8f4d6 Declare all MIR passes in a list 2024-11-12 13:28:00 +00:00
Matthias Krüger
b95232dabb
Rollup merge of #132675 - Zalathar:empty-spans, r=jieyouxu
coverage: Restrict empty-span expansion to only cover `{` and `}`

Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
2024-11-10 17:43:07 +01:00
Zalathar
3c30fe3423 coverage: Restrict empty-span expansion to only cover { and } 2024-11-08 20:43:08 +11:00
Zalathar
996bdabc2a coverage: Remove unhelpful code for handling multiple files per function
Functions currently can't have mappings in multiple files, and if that ever
changes (e.g. to properly support expansion regions), this code will need to be
completely overhauled anyway.
2024-11-08 20:43:08 +11:00
Zalathar
7c76995950 coverage: Pass ExtractedHirInfo to make_source_region
This isn't strictly necessary, but makes it easier to distinguish `body_span`
from the specific `span` being processed.
2024-11-08 20:38:35 +11:00
Stuart Cook
1b55244aa2
Rollup merge of #132389 - Zalathar:graph-tweaks, r=jieyouxu
coverage: Simplify parts of coverage graph creation

This is a combination of three semi-related simplifications to how coverage graphs are created, grouped into one PR to avoid conflicts.

There are no observable changes to the output of any of the coverage tests.
2024-11-08 18:51:29 +11:00
Nicholas Nethercote
c904c6aaff Remove ResultsVisitable.
Now that `Results` is the only impl of `ResultsVisitable`, the trait can
be removed. This simplifies things by removining unnecessary layers of
indirection and abstraction.

- `ResultsVisitor` is simpler.
  - Its type parameter changes from `R` (an analysis result) to the
    simpler `A` (an analysis).
  - It no longer needs the `Domain` associated type, because it can use
    `A::Domain`.
  - Occurrences of `R` become `Results<'tcx, A>`, because there is now
    only one kind of analysis results.

- `save_as_intervals` also changes type parameter from `R` to `A`.

- The `results.reconstruct_*` method calls are replaced with
  `results.analysis.apply_*` method calls, which are equivalent.

- `Direction::visit_results_in_block` is simpler, with a single generic
  param (`A`) instead of two (`D` and `R`/`F`, with a bound connecting
  them). Likewise for `visit_results`.

- The `ResultsVisitor` impls for `MirBorrowCtxt` and
  `StorageConflictVisitor` are now specific about the type of the
  analysis results they work with. They both used to have a type param
  `R` but they weren't genuinely generic. In both cases there was only a
  single results type that made sense to instantiate them with.
2024-11-05 10:18:03 +11:00
Jubilee Young
843b6e0859 compiler: Directly use rustc_abi in mir_transform 2024-11-03 13:38:47 -08:00
Zalathar
4a70f4bee0 coverage: Simplify logic for chaining multiple blocks into one BCB
We only need to take action when the next block cannot be added to the current
chain, but the logic is much simpler if we express it in terms of when the
block _can_ be added.
2024-11-01 20:04:01 +11:00
Jubilee
c57b351d38
Rollup merge of #132403 - lcnr:typing-mode, r=compiler-errors
continue `TypingMode` refactor

There are still quite a few places which (indirectly) rely on the `Reveal` of a `ParamEnv`, but we're slowly getting there

r? `@compiler-errors`
2024-10-31 17:50:43 -07:00
bors
a0d98ff0e5 Auto merge of #132356 - jieyouxu:unsound-simplify_aggregate_to_copy, r=cjgillot,DianQK
Mark `simplify_aggregate_to_copy` mir-opt as unsound

Mark the `simplify_aggregate_to_copy` mir-opt added in #128299 as unsound as it seems to miscompile the MCVE reported in https://github.com/rust-lang/rust/issues/132353. The mir-opt can be re-enabled once this case is fixed.

```rs
fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
    loop {
        if let Some(col) = score2head[0] {
            score2head[0] = None;
            return Some(col);
        }
    }
}

fn main() {
    let min = pop_min(vec![Some(1)]);
    println!("min: {:?}", min);
    // panic happens here on beta in release mode
    // but not in debug mode
    min.unwrap();
}
```

This MCVE is included as a `run-pass` ui regression test in the first commit. I built the ui test with a nightly manually, and can reproduce the behavioral difference with `-C opt-level=0` and `-C opt-level=1`. Locally, this ui test will fail unless it was run on a compiler built with the second commit marking the mir-opt as unsound thus disabling it by default.

This PR **partially reverts** commit e7386b3, reversing changes made to 02b1be1. The mir-opt implementation is just marked as unsound but **not** reverted to make reland reviews easier. Test changes are **reverted if they were not pure additions**. Tests added by the original PR received `-Z unsound-mir-opts` compile-flags.

cc `@DianQK` `@cjgillot` (PR author and reviewer of #128299)
2024-10-31 15:29:14 +00:00
lcnr
2cde638ac0 stop using ParamEnv::reveal while handling MIR 2024-10-31 14:55:53 +01:00
lcnr
aab149b58c ConstCx stop using ParamEnv::reveal 2024-10-31 12:43:22 +01:00
Zalathar
899d89f64c coverage: Use a standard depth-first search on a custom subgraph 2024-10-31 17:31:16 +11:00
Zalathar
8834b5ad51 coverage: Make CoverageSuccessors a struct 2024-10-31 16:49:00 +11:00
许杰友 Jieyou Xu (Joe)
10b8ba4ecb Mark simplify_aggregate_to_copy mir-opt as unsound
Co-authored-by: DianQK <dianqk@dianqk.net>
2024-10-31 13:48:06 +08:00
Nicholas Nethercote
846e20c3b6 Reduce some visibilities. 2024-10-31 12:46:30 +11:00
Nicholas Nethercote
911edbfe42 Remove ValueAnalysis and ValueAnalysisWrapper.
They represent a lot of abstraction and indirection, but they're only
used for `ConstAnalysis`, and apparently won't be used for any other
analyses in the future. This commit inlines and removes them, which
makes `ConstAnalysis` easier to read and understand.
2024-10-31 12:46:26 +11:00
Jubilee
847b6fe6b0
Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errors
Rename `rustc_abi::Abi` to `BackendRepr`

Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights.

Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-30 14:01:37 -07:00
Matthias Krüger
2055237e8f
Rollup merge of #132338 - nnethercote:rm-Engine, r=nnethercote
Remove `Engine`

It's just unnecessary plumbing. Removing it results in less code, and simpler code.

r? ``@cjgillot``
2024-10-30 06:40:37 +01:00
Nicholas Nethercote
e54c177118 Remove Analysis::into_engine.
This is a standard pattern:
```
MyAnalysis.into_engine(tcx, body).iterate_to_fixpoint()
```
`into_engine` and `iterate_to_fixpoint` are always called in pairs, but
sometimes with a builder-style `pass_name` call between them. But a
builder-style interface is overkill here. This has been bugging me a for
a while.

This commit:
- Merges `Engine::new` and `Engine::iterate_to_fixpoint`. This removes
  the need for `Engine` to have fields, leaving it as a trivial type
  that the next commit will remove.
- Renames `Analysis::into_engine` as `Analysis::iterate_to_fixpoint`,
  gives it an extra argument for the optional pass name, and makes it
  call `Engine::iterate_to_fixpoint` instead of `Engine::new`.

This turns the pattern from above into this:
```
MyAnalysis.iterate_to_fixpoint(tcx, body, None)
```
which is shorter at every call site, and there's less plumbing required
to support it.
2024-10-30 09:41:46 +11:00
Jubilee Young
7086dd83cc compiler: rustc_abi::Abi => BackendRepr
The initial naming of "Abi" was an awful mistake, conveying wrong ideas
about how psABIs worked and even more about what the enum meant.
It was only meant to represent the way the value would be described to
a codegen backend as it was lowered to that intermediate representation.
It was never meant to mean anything about the actual psABI handling!
The conflation is because LLVM typically will associate a certain form
with a certain ABI, but even that does not hold when the special cases
that actually exist arise, plus the IR annotations that modify the ABI.

Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename
`BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to
the persistent misunderstandings, this too is now incorrect:
- Scattered ABI-relevant code is entangled with BackendRepr
- We do not always pre-compute a correct BackendRepr that reflects how
  we "actually" want this value to be handled, so we leave the backend
  interface to also inject various special-cases here
- In some cases `BackendRepr::Memory` is a "real" aggregate, but in
  others it is in fact using memory, and in some cases it is a scalar!

Our rustc-to-backend lowering code handles this sort of thing right now.
That will eventually be addressed by lifting duplicated lowering code
to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-29 14:56:00 -07:00
lcnr
f51ec110a7 TypingMode 🤔 2024-10-29 17:01:24 +01:00
Jubilee Young
88a9edc091 compiler: Add is_uninhabited and use LayoutS accessors
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-28 09:58:30 -07:00
bors
e454c45f13 Auto merge of #132091 - Zalathar:graph-loops, r=saethlin
coverage: Don't rely on the custom traversal to find enclosing loops

This opens up the possibility of modifying or removing the custom graph traversal used in coverage counter creation, without losing access to the heuristics that care about a node's enclosing loops.

Actually changing the traversal is left for future work, because this PR on its own doesn't change the emitted coverage mappings at all.
2024-10-27 08:19:16 +00:00
Matthias Krüger
56463df1be
Rollup merge of #132168 - fee1-dead-contrib:fxclean, r=compiler-errors
Effects cleanup

- removed extra bits from predicates queries that are no longer needed in the new system
- removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers

r? compiler-errors
2024-10-26 06:29:48 +02:00
Deadbeef
f6fea83342 Effects cleanup
- removed extra bits from predicates queries that are no longer needed in the new system
- removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
2024-10-26 10:19:07 +08:00
Zalathar
19b2142d18 coverage: Don't rely on the custom traversal to find enclosing loops 2024-10-26 09:38:47 +11:00
Ralf Jung
8849ac6042 tcx.is_const_fn doesn't work the way it is described, remove it
Then we can rename the _raw functions to drop their suffix, and instead
explicitly use is_stable_const_fn for the few cases where that is really what
you want.
2024-10-25 20:52:39 +02:00
Matthias Krüger
dab76eccdf fix a couple clippy:complexitys
double_parens
 filter_map_identity
 needless_question_mark
 redundant_guards
2024-10-23 22:15:59 +02:00
Ralf Jung
ad3991d303 nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
Matthias Krüger
f5aa456646
Rollup merge of #132022 - Zalathar:dominator-order, r=tmiasko
Move `cmp_in_dominator_order` out of graph dominator computation

Dominator-order information is only needed for coverage graphs, and is easy enough to collect by just traversing the graph again.

This avoids wasted work when computing graph dominators for any other purpose.
2024-10-22 15:28:50 +02:00
Zalathar
7f4dd9bb81 Move cmp_in_dominator_order out of graph dominator computation
Dominator-order information is only needed for coverage graphs, and is easy
enough to collect by just traversing the graph again.

This avoids wasted work when computing graph dominators for any other purpose.
2024-10-22 20:44:09 +11:00
Matthias Krüger
703b042be8
Rollup merge of #131918 - Zalathar:counters, r=nnethercote
coverage: Make counter creation handle node/edge counters more uniformly

Similar to #130380, this is another round of small improvements informed by my ongoing attempts to overhaul coverage counter creation.

One of the big benefits is getting rid of the awkward special-case that would sometimes attach an edge counter to a node instead. That was needed by the code that chooses which out-edge should be given a counter expression, but we can avoid that by making the corresponding check a little smarter.

I've also renamed several things to be simpler and more consistent, which should help with future changes.
2024-10-22 10:08:46 +02:00
bors
f2ba41113d Auto merge of #130950 - compiler-errors:yeet-eval, r=BoxyUwU
Continue to get rid of `ty::Const::{try_}eval*`

This PR mostly does:

* Removes all of the `try_eval_*` and `eval_*` helpers from `ty::Const`, and replace their usages with `try_to_*`.
* Remove `ty::Const::eval`.
* Rename `ty::Const::normalize` to `ty::Const::normalize_internal`. This function is still used in the normalization code itself.
* Fix some weirdness around the `TransmuteFrom` goal.

I'm happy to split it out further; for example, I could probably land the first part which removes the helpers, or the changes to codegen which are more obvious than the changes to tools.

r? BoxyUwU

Part of https://github.com/rust-lang/rust/issues/130704
2024-10-21 03:46:28 +00:00
Michael Goulet
e83e4e8112 Get rid of const eval_* and try_eval_* helpers 2024-10-19 18:07:35 +00:00
Zalathar
4b8f7f547a coverage: Streamline several names of things in counter creation 2024-10-19 18:42:55 +11:00
Zalathar
a400d7fb76 coverage: Make counter creation handle nodes/edges more uniformly 2024-10-19 18:42:54 +11:00
Ralf Jung
eea74be5c1 interpret errors: add map_err_kind, rename InterpError -> InterpErrorKind 2024-10-19 09:22:38 +02:00
许杰友 Jieyou Xu (Joe)
aae4730c78
Rollup merge of #131802 - compiler-errors:fnonce-coverage, r=Zalathar
Dont ICE when computing coverage of synthetic async closure body

I'm not totally certain if this is *right*, but at least it doesn't ICE.

The issue is that we end up generating two MIR bodies for each async closure, since the `FnOnce` and `Fn`/`FnMut` implementations have different borrowing behavior of their captured variables. They should ideally both contribute to the coverage, since those MIR bodies are (*to the user*) the same code and should have no behavioral differences.

This PR at least suppresses the ICEs, and then I guess worst case we can fix this the right way later.

r? Zalathar or re-roll

Fixes #131190
2024-10-18 12:00:51 +01:00
Michael Goulet
cdbf28af76 Dont ICE when computing coverage of synthetic async closure body 2024-10-18 20:14:02 +11:00
bors
06d261daf6 Auto merge of #129582 - nbdd0121:unwind, r=nnethercote
Make destructors on `extern "C"` frames to be executed

This would make the example in #123231 print "Noisy Drop". I didn't mark this as fixing the issue because the behaviour is yet to be spec'ed.

Tracking:

- https://github.com/rust-lang/rust/issues/74990
2024-10-17 04:34:51 +00:00
Matthias Krüger
b6a085a16e
Rollup merge of #130989 - compiler-errors:unsize-opaque, r=estebank
Don't check unsize goal in MIR validation when opaques remain

Similarly to `mir_assign_valid_types`, let's just skip when there are opaques. Fixes #130921.
2024-10-16 20:15:52 +02:00
Michael Goulet
c7730989de Don't check unsize goal in MIR validation when opaques remain 2024-10-15 21:01:42 -04:00