Commit Graph

5676 Commits

Author SHA1 Message Date
bors
e7c502d930 Auto merge of #109597 - cjgillot:gvn, r=oli-obk
Implement a global value numbering MIR optimization

The aim of this pass is to avoid repeated computations by reusing past assignments. It is based on an analysis of SSA locals, in order to perform a restricted form of common subexpression elimination.

By opportunity, this pass allows for some simplifications by combining assignments. For instance, this pass could be able to see through projections of aggregates to directly reuse the aggregate field (not in this PR).

We handle references by assigning a different "provenance" index to each `Ref`/`AddressOf` rvalue. This ensure that we do not spuriously merge borrows that should not be merged. Meanwhile, we consider all the derefs of an immutable reference to a freeze type to give the same value:
```rust
_a = *_b // _b is &Freeze
_c = *_b // replaced by _c = _a
```
2023-09-27 21:06:30 +00:00
bors
c4ce33cfbc Auto merge of #115887 - RalfJung:pat, r=oli-obk
thir::pattern: update some comments and error type names

Follow-up to [these comments](https://github.com/rust-lang/rust/pull/105750#pullrequestreview-1629697578). Please carefully fact-check, I'm new to this area of the compiler!
2023-09-27 13:20:53 +00:00
bors
6b99cf1d35 Auto merge of #116163 - compiler-errors:lazyness, r=oli-obk
Don't store lazyness in `DefKind::TyAlias`

1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query.
2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase.

r? `@oli-obk` cc `@fmease`
2023-09-27 01:48:53 +00:00
lcnr
3c52a3e280 subst -> instantiate 2023-09-26 09:37:55 +02:00
Michael Goulet
d6ce9ce115 Don't store lazyness in DefKind 2023-09-26 02:53:59 +00:00
Camille GILLOT
26cb34cd18 Remove span from BrAnon. 2023-09-24 09:46:55 +00:00
Camille GILLOT
8b848af325 Add global value numbering pass. 2023-09-24 09:09:04 +00:00
Camille GILLOT
44ac8dcc71 Remove GeneratorWitness and rename GeneratorWitnessMIR. 2023-09-23 13:47:30 +00:00
Camille GILLOT
286502c9ed Enable drop_tracking_mir by default. 2023-09-23 13:34:09 +00:00
bors
3050938abd Auto merge of #116081 - compiler-errors:closure-captures-sized, r=cjgillot
Check that closure/generator's interior/capture types are sized

check that closure upvars and generator interiors are sized. this check is only necessary when `unsized_fn_params` or `unsized_locals` is enabled, so only check if those are active.

Fixes #93622
Fixes #61335
Fixes #68543
2023-09-23 10:01:49 +00:00
bors
bf982631df Auto merge of #116052 - oli-obk:ceci_nest_pas_une_query, r=WaffleLapkin
Add a way to decouple the implementation and the declaration of a TyCtxt method.

properly addresses https://github.com/rust-lang/rust/pull/115819

accepted MCP: https://github.com/rust-lang/compiler-team/issues/395
2023-09-23 04:41:09 +00:00
Michael Goulet
79d685325c Check types live across yields in generators too 2023-09-23 04:19:14 +00:00
Michael Goulet
c21867f9f6 Check that closure's by-value captures are sized 2023-09-23 04:19:14 +00:00
Oli Scherer
4ed4913e67 Merge ExternProviders into the general Providers struct 2023-09-22 20:15:34 +00:00
Oli Scherer
2ba911c832 Have a single struct for queries and hook 2023-09-22 16:26:20 +00:00
bors
959b2c703d Auto merge of #115696 - RalfJung:closure-ty-print, r=oli-obk
adjust how closure/generator types are printed

I saw `&[closure@$DIR/issue-20862.rs:2:5]` and I thought it is a slice type, because that's usually what `&[_]` is... it took me a while to realize that this is just a confusing printer and actually there's no slice. Let's use something that cannot be mistaken for a regular type.
2023-09-22 15:19:38 +00:00
Matthias Krüger
1a18ec0dcf
Rollup merge of #116049 - RalfJung:future-incompat, r=Nilstrieb
give FutureIncompatibilityReason variants more explicit names

Also make the `reason` field mandatory when declaring a lint, to make sure this is a deliberate decision.
2023-09-22 12:15:28 +02:00
Matthias Krüger
66f272d6ca
Rollup merge of #116041 - compiler-errors:rigid-note, r=RalfJung
Add note to `is_known_rigid`

Adds a note requested by `@RalfJung` in https://github.com/rust-lang/rust/pull/114941#discussion_r1329963704

Let me know if there are any other fns that need documentation, I could throw them into this PR too :)
2023-09-22 12:15:28 +02:00
Oli Scherer
9defc971f1 Add tracing instrumentation, just like queries automatically add it 2023-09-22 09:25:38 +00:00
Oli Scherer
2157f31731 Add a way to decouple the implementation and the declaration of a TyCtxt method. 2023-09-22 09:23:15 +00:00
Ralf Jung
e888d470e9 give FutureIncompatibilityReason variants more explicit names 2023-09-22 08:51:18 +02:00
Michael Goulet
7fc081b4d9 Add note to is_known_rigid 2023-09-22 01:02:38 +00:00
bors
b757318718 Auto merge of #115920 - Zoxc:depkind-u16, r=cjgillot
Move `DepKind` to `rustc_query_system` and define it as `u16`

This moves the `DepKind` type to `rustc_query_system` where it's defined with an inner `u16` field. This decouples it from `rustc_middle` and is a step towards letting other crates define dep kinds. It also allows some type parameters to be removed. The `DepKind` trait is replaced with a `Deps` trait. That's used when some operations or information about dep kinds which is unavailable in `rustc_query_system` are still needed.

r? `@cjgillot`
2023-09-22 00:46:13 +00:00
bors
99b63d068b Auto merge of #115897 - eduardosm:check-fn-sig, r=compiler-errors
rustc_hir_analysis: add a helper to check function the signature mismatches

This function is now used to check `#[panic_handler]`, `start` lang item, `main`, `#[start]` and intrinsic functions.

The diagnosis produced are now closer to the ones produced by trait/impl method signature mismatch.

This is the first time I do anything with rustc_hir_analysis/rustc_hir_typeck, so comments and suggestions about things I did wrong or that could be improved will be appreciated.
2023-09-21 22:59:13 +00:00
bors
b3aa8e7168 Auto merge of #115864 - compiler-errors:rpitit-sugg, r=estebank
Suggest desugaring to return-position `impl Future` when an `async fn` in trait fails an auto trait bound

First commit allows us to store the span of the `async` keyword in HIR.

Second commit implements a suggestion to desugar an `async fn` to a return-position `impl Future` in trait to slightly improve the `Send` situation being discussed in #115822.

This suggestion is only made when `#![feature(return_type_notation)]` is not enabled -- if it is, we should instead suggest an appropriate where-clause bound.
2023-09-21 21:12:32 +00:00
Ralf Jung
c4ec12f4b7 adjust how closure/generator types and rvalues are printed 2023-09-21 22:20:58 +02:00
Michael Goulet
087a571e70 Record asyncness span in HIR 2023-09-21 19:18:14 +00:00
bors
24b45c3bdc Auto merge of #114399 - Zalathar:no-renumber, r=jackh726
coverage: Don't bother renumbering expressions on the Rust side

The LLVM API that we use to encode coverage mappings already has its own code for removing unused coverage expressions and renumbering the rest.

This lets us get rid of our own complex renumbering code, making it easier to change our coverage code in other ways.

---

Now that we have tests for coverage mappings (#114843), I've been able to verify that this PR doesn't make the coverage mappings worse, thanks to an explicit simplification step.
2023-09-21 17:29:30 +00:00
John Kåre Alsaker
1806efe7f2 Move DepKind to rustc_query_system and define it as u16 2023-09-21 17:06:14 +02:00
Guillaume Gomez
208f6ed95c
Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const

Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`.

Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all.

However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish...

``@oli-obk`` any ideas?
2023-09-21 13:25:39 +02:00
Guillaume Gomez
d05c5fecde
Rollup merge of #115936 - oli-obk:inline_const_promotion, r=RalfJung
Prevent promotion of const fn calls in inline consts

We don't wanna make that mistake we did for statics and consts worse by letting more code use it.

r? ``@RalfJung``

cc https://github.com/rust-lang/rust/issues/76001
2023-09-21 13:25:38 +02:00
Oli Scherer
9c762b58ba Prevent promotion of const fn calls in inline consts 2023-09-21 09:00:22 +00:00
Zalathar
041a232b62 coverage: Don't bother renumbering expressions on the Rust side
The LLVM API that we use to encode coverage mappings already has its own code
for removing unused coverage expressions and renumbering the rest.

This lets us get rid of our own complex renumbering code, making it easier to
change our coverage code in other ways.
2023-09-21 18:32:49 +10:00
lcnr
de53877f8b proof trees: use for intercrate_ambiguity_causes 2023-09-21 08:17:58 +02:00
Ralf Jung
c94410c145 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
bors
9da3e81785 Auto merge of #115870 - RalfJung:const-value-slice, r=oli-obk
adjust ConstValue::Slice to work for arbitrary slice types

valtrees have already been assuming that this works; this PR makes it a reality. Also further restrict `ConstValue::Slice` to what it is actually used for; this even shrinks `ConstValue` from 32 to 24 bytes which is a nice win. :)

The alternative to this approach is to make `ConstValue::Slice` work really only for `&str`/`&[u8]` literals, and never return it in `op_to_const`. That would make `op_to_const` very clean. We could then even remove the `meta` field; the length would always be `data.inner().len()`. We could *almost* just use a `Symbol` instead of a `ConstAllocation`, but we have to support byte strings and there doesn't seem to be an interned representation of them (or rather, `ConstAllocation` *is* their interned representation). In this world, valtrees of slice reference types would then become noticeably more expensive to turn into a `ConstValue` -- but does that matter? Specifically for `&str`/`&[u8]` we could still use the optimized representation if we wanted.

If byte strings were already interned somewhere I'd gravitate towards the alternative, but the way things stand, we need a `ConstAllocation` case anyway to support byte strings, and then we might as well support arbitrary slices. (Or we say that byte strings don't get an optimized representation at all. Such a performance cliff between `str` and byte strings is probably unexpected, though due to the lack of interning for byte strings I think there might already be a performance cliff there.)
2023-09-20 18:06:48 +00:00
Guillaume Gomez
4e8f637783
Rollup merge of #115566 - zirconium-n:issue-107250-clean-up-unused-to-predicate, r=oli-obk
clean up unneeded `ToPredicate` impls

Part of #107250.
Removed all totally unused impls. And inlined two impls not need to satisify trait bound.

r? `@oli-obk`
2023-09-20 17:33:16 +02:00
bors
78e74d959b Auto merge of #115827 - eduardosm:miri-sse-reduce-code-dup, r=RalfJung
miri: reduce code duplication in some SSE/SSE2 intrinsics

Reduces code duplication in the Miri implementation of some SSE and SSE2 using generics and rustc_const_eval helper functions.

There are also some other minor changes.

r? `@RalfJung`
2023-09-20 12:07:26 +00:00
Ralf Jung
a2374e65aa the Const::eval_bits methods don't need to be given the Ty 2023-09-20 07:27:21 +02:00
bors
bdb0fa3ee5 Auto merge of #113955 - cjgillot:name-apit, r=WaffleLapkin
Pretty-print argument-position impl trait to name it.

This removes a corner case.

RPIT and TAIT keep having no name, and it would be wrong to use the one in HIR (Ident::empty), so I make this case ICE.
2023-09-19 21:23:39 +00:00
Ziru Niu
3c69a107d0 remove impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> 2023-09-20 04:03:02 +08:00
Ziru Niu
2694b84fbf remove unneeded ToPredicate impls 2023-09-20 04:02:55 +08:00
Guillaume Gomez
edd7be59da
Rollup merge of #115499 - msizanoen1:riscv-fix-transparent-union-abi, r=bjorn3
rustc_target/riscv: Fix passing of transparent unions with only one non-ZST member

This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed through an `extern "C"` function.

Fixes https://github.com/rust-lang/rust/issues/115481.

r? `@RalfJung`
2023-09-19 20:23:19 +02:00
Ralf Jung
ea22adbabd adjust constValue::Slice to work for arbitrary slice types 2023-09-19 20:17:43 +02:00
Eduardo Sánchez Muñoz
c599761140 rustc_hir_analysis: add a helper to check function the signature mismatches
This function is now used to check `#[panic_handler]`, `start` lang item, `main`, `#[start]` and intrinsic functions.

The diagnosis produced are now closer to the ones produced by trait/impl method signature mismatch.
2023-09-19 18:15:23 +02:00
bors
0692db1a90 Auto merge of #115865 - RalfJung:mir-mod, r=oli-obk
move things out of mir/mod.rs

This moves a bunch of things out of `mir/mod.rs`:
- all const-related stuff to a new file consts.rs
- all statement/place/operand-related stuff to a new file statement.rs
- all pretty-printing related stuff to pretty.rs

`mod.rs` started out with 3100 lines and ends up with 1600. :)

Also there was some pretty-printing stuff in terminator.rs, that also got moved to pretty.rs, and I reordered things in pretty.rs so that it can be grouped by functionality.

Only the commit "use pretty_print_const_value from MIR constant 'extra' printing" has any behavior changes; it resolves the issue of having a fancy and a very crude pretty-printer for `ConstValue`.

r? `@oli-obk`
2023-09-19 13:22:48 +00:00
msizanoen
751ecde064 rustc_target/riscv: Fix passing of transparent unions with only one non-ZST member
This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed
through an `extern "C"` function.

Fixes https://github.com/rust-lang/rust/issues/115481.
2023-09-19 12:06:33 +02:00
Ralf Jung
d14e601661 comment on the difference between mir::ConstantKind::Unevaluated and mir::ConstantKind::Ty(ty::ConstKind::Unevaluated) 2023-09-19 11:11:03 +02:00
Ralf Jung
5a0a1ff0cd move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
Ralf Jung
be8f5f6e7f organize mir pretty.rs and move more things into it; move statement-related things out of mir/mod.rs 2023-09-19 11:06:32 +02:00