Commit Graph

255 Commits

Author SHA1 Message Date
bors
b5c8c329a7 Auto merge of #108058 - Zoxc:query-ctxtx-byval, r=cjgillot
Pass `DepContext` and `QueryContext` by value when practical

This removes some indirections for a minor performance improvement.

<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.8294s</td><td align="right">1.8255s</td><td align="right"> -0.21%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2667s</td><td align="right">0.2669s</td><td align="right"> 0.07%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">1.0080s</td><td align="right">1.0063s</td><td align="right"> -0.17%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.6335s</td><td align="right">1.6295s</td><td align="right"> -0.24%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.3633s</td><td align="right">6.3344s</td><td align="right"> -0.45%</td></tr><tr><td>Total</td><td align="right">11.1009s</td><td align="right">11.0627s</td><td align="right"> -0.34%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9980s</td><td align="right"> -0.20%</td></tr></table>
2023-02-17 08:23:53 +00:00
John Kåre Alsaker
067bf2ac13 Move provider fields back to rustc_query_impl 2023-02-16 14:55:05 +01:00
John Kåre Alsaker
a51a20531d Factor query arena allocation out from query caches 2023-02-16 14:54:53 +01:00
John Kåre Alsaker
b3a4fe7d4e Pass DepContext and QueryContext by value when practical 2023-02-14 17:21:18 +01:00
Nicholas Nethercote
f7b3e39502 Simplify tls::enter_context. 2023-02-09 15:25:45 +11:00
klensy
4f5f9f0a13 remove unused imports 2023-02-06 17:40:18 +03:00
Michael Goulet
64f5293956 Don't cause a cycle when formatting query description that references a FnDef 2023-02-02 05:49:07 +00:00
nils
fd7a159710 Fix uninlined_format_args for some compiler crates
Convert all the crates that have had their diagnostic migration
completed (except save_analysis because that will be deleted soon and
apfloat because of the licensing problem).
2023-01-05 19:01:12 +01:00
CarsonV
f98adb32f5 Enable query_impl doctests 2023-01-03 20:38:28 -06:00
Nilstrieb
9fe4efe115 Abolish QueryVTable in favour of more assoc items on QueryConfig
This may introduce additional mono _but_ may help const fold things
better and especially may help not constructing a `QueryVTable` anymore
which is cheap but not free.
2023-01-02 20:22:19 +01:00
Matthias Krüger
d23cb738d2
Rollup merge of #105975 - jeremystucki:rustc-remove-needless-lifetimes, r=eholk
rustc: Remove needless lifetimes
2022-12-24 00:31:41 +01:00
bors
c2ff8ad035 Auto merge of #105550 - gimbles:master, r=Nilstrieb
Use `DepKind` instead of `&'static str` in `QueryStackFrame`

`@rustbot` author

Fixes #105168
2022-12-23 16:57:21 +00:00
gimbles
f8b30084ac Use DepKind instead of &str 2022-12-23 18:39:49 +05:30
Jeremy Stucki
3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
Matthias Krüger
fec9e9ecf1 don't clone Copy types 2022-12-18 14:25:55 +01:00
bors
c97b539e40 Auto merge of #104940 - cjgillot:query-feed-simple, r=oli-obk
Allow to feed a value in another query's cache

Restricted version of https://github.com/rust-lang/rust/pull/96840

A query can create new definitions.

If those definitions are created after HIR lowering, they do not appear in the initial HIR map, and information for them cannot be provided in the normal pull-based way.

In order to make those definitions useful, we allow to feed values as query results for the newly created definition.

The API is as follows:
```rust
let feed = tcx.create_def(<parent def id>, <DefPathData>);
// `feed` is a TyCtxtFeed<'tcx>.

// Access the created definition.
let def_id: LocalDefId = feed.def_id;

// Assign `my_query(def_id) := my_value`.
feed.my_query(my_value).
```

This PR keeps the consistency checks introduced by https://github.com/rust-lang/rust/pull/96840, even if they are not reachable. This allows to extend the behaviour later without forgetting them.

cc `@oli-obk` `@spastorino`
2022-11-30 17:20:14 +00:00
Camille GILLOT
9f2c6b0b09 Sanity check computed value for feeable queries. 2022-11-29 18:42:23 +00:00
Camille GILLOT
7c45772bc9 Make verbose query description more useful. 2022-11-29 18:36:53 +00:00
Santiago Pastorino
537488efd6
Make inferred_outlives_crate return Clause 2022-11-29 12:01:58 -03:00
Matthias Krüger
42010a23f5
Rollup merge of #104675 - SarthakSingh31:issue-101666, r=jyn514
Unsupported query error now specifies if its unsupported for local or external crate

Fixes #101666.
I had to move `keys.rs` from `rustc_query_impl` to `rustc_middle`. I don't know if that is problematic. I couldn't think of any other way to get the needed information inside `rustc_middle`.

r? ```@jyn514```
2022-11-26 10:39:10 +01:00
kadmin
f9750c1554 Add empty ConstKind::Abstract
Initial pass at expr/abstract const/s

Address comments

Switch to using a list instead of &[ty::Const], rm `AbstractConst`

Remove try_unify_abstract_consts

Update comments

Add edits

Recurse more

More edits

Prevent equating associated consts

Move failing test to ui

Changes this test from incremental to ui, and mark it as failing and a known bug.
Does not cause the compiler to ICE, so should be ok.
2022-11-25 09:28:43 +00:00
Sarthak Singh
1767f9f9bf Unsupported query error now specifies if its unsupported for local or external crate 2022-11-24 19:05:17 +05:30
bors
341d8b8a2c Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Ki
Use an IndexVec to cache queries with index-like key

Revival of an old idea. Let's see if it has more effect.

r? `@ghost`
2022-11-24 06:32:23 +00:00
Camille GILLOT
c49e2501bf Make AbsoluteBytePos a u64. 2022-11-08 18:47:26 +00:00
Nilstrieb
df3187260f
Remove one lifetime from QueryKeyStringBuilder 2022-11-06 13:10:35 +01:00
Nilstrieb
36be251a35
Merge QueryDescription into QueryConfig
`QueryDescription` has gone through a lot of refactoring and doesn't
make sense anymore.
2022-11-05 16:24:13 +01:00
Michael Howell
03968a802c rustdoc: use ThinVec for cleaned generics 2022-11-02 16:17:22 -07:00
Camille GILLOT
ade5cffc2b Move keys module. 2022-11-01 17:02:51 +00:00
Michael Woerister
9117ea9758 Introduce UnordMap, UnordSet, and UnordBag (see MCP 533)
MCP 533: https://github.com/rust-lang/compiler-team/issues/533

Also, as an example, substitute UnordMap for FxHashMap in
used_trait_imports query result.
2022-10-27 13:23:26 +00:00
Patrick Walton
da630ac79d Introduce deduced parameter attributes, and use them for deducing readonly on
indirect immutable freeze by-value function parameters.

Right now, `rustc` only examines function signatures and the platform ABI when
determining the LLVM attributes to apply to parameters. This results in missed
optimizations, because there are some attributes that can be determined via
analysis of the MIR making up the function body. In particular, `readonly`
could be applied to most indirectly-passed by-value function arguments
(specifically, those that are freeze and are observed not to be mutated), but
it currently is not.

This patch introduces the machinery that allows `rustc` to determine those
attributes. It consists of a query, `deduced_param_attrs`, that, when
evaluated, analyzes the MIR of the function to determine supplementary
attributes. The results of this query for each function are written into the
crate metadata so that the deduced parameter attributes can be applied to
cross-crate functions. In this patch, we simply check the parameter for
mutations to determine whether the `readonly` attribute should be applied to
parameters that are indirect immutable freeze by-value.  More attributes could
conceivably be deduced in the future: `nocapture` and `noalias` come to mind.

Adding `readonly` to indirect function parameters where applicable enables some
potential optimizations in LLVM that are discussed in [issue 103103] and [PR
103070] around avoiding stack-to-stack memory copies that appear in functions
like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These
functions pass a large structure unchanged by value to a subfunction that also
doesn't mutate it. Since the structure in this case is passed as an indirect
parameter, it's a pointer from LLVM's perspective. As a result, the
intermediate copy of the structure that our codegen emits could be optimized
away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly
nocapture noalias` in both the caller and callee. We already pass `nocapture
noalias`, but we're missing `readonly`, as we can't determine whether a
by-value parameter is mutated by examining the signature in Rust. I didn't have
much success with having LLVM infer the `readonly` attribute, even with fat
LTO; it seems that deducing it at the MIR level is necessary.

No large benefits should be expected from this optimization *now*; LLVM needs
some changes (discussed in [PR 103070]) to more aggressively use the `noalias
nocapture readonly` combination in its alias analysis. I have some LLVM patches
for these optimizations and have had them looked over. With all the patches
applied locally, I enabled LLVM to remove all the `memcpy`s from the following
code:

```rust
fn main() {
    println!("Hello {}", 3);
}
```

which is a significant codegen improvement over the status quo. I expect that
if this optimization kicks in in multiple places even for such a simple
program, then it will apply to Rust code all over the place.

[issue 103103]: https://github.com/rust-lang/rust/issues/103103

[PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-21 02:33:15 -07:00
nils
24ce4cfa20
Remove the describe method from the QueryDescription trait
It was called directly already, but now it's even more useless since it
just forwards to the free function. Call it directly.
2022-10-14 22:35:56 +02:00
Nilstrieb
167b3bd3b2
Get rid of rustc_query_description!
Queries can provide an arbitrary expression for their description and
their caching behavior. Before, these expressions where stored in a
`rustc_query_description` macro emitted by the `rustc_queries` macro,
and then used in `rustc_query_impl` to fill out the methods for the
`QueryDescription` trait.

Instead, we now emit two new modules from `rustc_queries` containing the
functions with the expressions. `rustc_query_impl` calls these functions
now instead of invoking the macro.

Since we are now defining some of the functions in
`rustc_middle::query`, we now need all the imports for the key types
there as well.
2022-10-14 22:35:56 +02:00
Cameron Steffen
ff940db666 Rewrite representability 2022-10-07 09:33:46 -05:00
Nicholas Nethercote
9110d925d0 Remove -Ztime option.
The compiler currently has `-Ztime` and `-Ztime-passes`. I've used
`-Ztime-passes` for years but only recently learned about `-Ztime`.

What's the difference? Let's look at the `-Zhelp` output:
```
  -Z        time=val -- measure time of rustc processes (default: no)
  -Z time-passes=val -- measure time of each rustc pass (default: no)
```
The `-Ztime-passes` description is clear, but the `-Ztime` one is less so.
Sounds like it measures the time for the entire process?

No. The real difference is that `-Ztime-passes` prints out info about passes,
and `-Ztime` does the same, but only for a subset of those passes. More
specifically, there is a distinction in the profiling code between a "verbose
generic activity" and an "extra verbose generic activity". `-Ztime-passes`
prints both kinds, while `-Ztime` only prints the first one. (It took me
a close reading of the source code to determine this difference.)

In practice this distinction has low value. Perhaps in the past the "extra
verbose" output was more voluminous, but now that we only print stats for a
pass if it exceeds 5ms or alters the RSS, `-Ztime-passes` is less spammy. Also,
a lot of the "extra verbose" cases are for individual lint passes, and you need
to also use `-Zno-interleave-lints` to see those anyway.

Therefore, this commit removes `-Ztime` and the associated machinery. One thing
to note is that the existing "extra verbose" activities all have an extra
string argument, so the commit adds the ability to accept an extra argument to
the "verbose" activities.
2022-10-06 15:49:44 +11:00
Camille GILLOT
6e76599f5f Correct Key impl for HirId. 2022-10-01 16:20:08 +02:00
Deadbeef
3cb1811e45 Compute lint_levels by definition 2022-10-01 16:12:50 +02:00
bors
3288d3a305 Auto merge of #101785 - jyn514:query-struct-fn-ptrs, r=cjgillot
Use function pointers instead of macro-unrolled loops in rustc_query_impl

By making these standalone functions, we
a) allow making them extensible in the future with a new `QueryStruct`
b) greatly decrease the amount of code in each individual function, avoiding exponential blowup in llvm

Helps with https://github.com/rust-lang/rust/issues/96524. Based on https://github.com/rust-lang/rust/pull/101173; only the last commit is relevant.

r? `@cjgillot`
2022-09-26 00:17:59 +00:00
Joshua Nelson
00cde6d4b9 Move the codegen_unit debug assert from rustc_query_system to query_impl
This allows removing a function from the `DepKind` trait.
2022-09-25 12:08:36 -05:00
Joshua Nelson
7a8369096c Use function pointers instead of macro-unrolled loops in rustc_query_impl
By making these standalone functions, we
a) allow making them extensible in the future with a new `QueryStruct`
b) greatly decrease the amount of code in each individual function, avoiding exponential blowup in llvm
2022-09-25 11:27:12 -05:00
Takayuki Maeda
8fe936099a separate definitions and HIR owners
fix a ui test

use `into`

fix clippy ui test

fix a run-make-fulldeps test

implement `IntoQueryParam<DefId>` for `OwnerId`

use `OwnerId` for more queries

change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-24 23:21:19 +09:00
bors
bb5a016175 Auto merge of #102064 - cjgillot:revert, r=Mark-Simulacrum
Revert perf-regression 101620

Reverts #101862 #101620

r? `@Mark-Simulacrum`
2022-09-24 09:36:29 +00:00
b-naber
a705e65605 rename Unevaluated to UnevaluatedConst 2022-09-23 14:27:34 +02:00
Camille GILLOT
fc43df0333 Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"
This reverts commit 2cb9a65684, reversing
changes made to 750bd1a7ff.
2022-09-22 19:36:11 +02:00
b-naber
9f3784df89 introduce mir::Unevaluated 2022-09-22 12:35:28 +02:00
Matthias Krüger
4757d2d57e
Rollup merge of #101801 - SparrowLii:query_depth_note, r=estebank
add note for `layout_of` when query depth overflows

Fixes #101747
Added `try_find_layout_root` function to add a note for `layout_of` when query depth overflows. This would make the error in #101747 look like this:
```
error: queries overflow the depth limit!
   |
note: Query depth increased by 66 when computing layout of `core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<alloc::boxed::Box<alloc::string::String>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`!
  --> D:\rust-backup\parallel_rust\query_depth.rs:40:1
   |
40 | fn main() {
   | ^^^^^^^^^

error: aborting due to previous error
```

cc ``@semicoleon``
2022-09-17 19:27:06 +02:00
Dylan DPC
28b4c62382
Rollup merge of #101787 - compiler-errors:cache-rpitit, r=petrochenkov
cache `collect_trait_impl_trait_tys`

Micro-optimization for RPITITs
2022-09-16 11:17:01 +05:30
bors
294f0eef73 Auto merge of #101173 - jyn514:simplify-macro-arguments, r=cjgillot
Further simplify the macros generated by `rustc_queries`

This doesn't actually move anything outside the macros, but it makes them simpler to read.

- Add a new `rustc_query_names` macro. This allows a much simpler syntax for the matchers in the macros passed to it as a callback.
- Convert `define_dep_nodes` and `alloc_once` to use `rustc_query_names`. This is possible because they only use the names
  (despite the quite complicated matchers in `define_dep_nodes`, none of the other arguments are used).
- Get rid of `rustc_dep_node_append`.

r? `@cjgillot`
2022-09-15 11:54:03 +00:00
SparrowLii
89fd6ae458 correct span, add help message and add UI test when query depth overflows 2022-09-15 16:05:44 +08:00
SparrowLii
44506f38e0 add note for layout_of when query depth overflows 2022-09-15 16:05:00 +08:00
Michael Goulet
4cdf264e6f cache collect_trait_impl_trait_tys 2022-09-14 20:50:52 +00:00