about summary refs log tree commit diff
path: root/compiler/rustc_query_impl/src
AgeCommit message (Collapse)AuthorLines
2022-11-08Make AbsoluteBytePos a u64.Camille GILLOT-3/+2
2022-11-06Remove one lifetime from `QueryKeyStringBuilder`Nilstrieb-36/+15
2022-11-05Merge `QueryDescription` into `QueryConfig`Nilstrieb-18/+15
`QueryDescription` has gone through a lot of refactoring and doesn't make sense anymore.
2022-10-27Introduce UnordMap, UnordSet, and UnordBag (see MCP 533)Michael Woerister-2/+3
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-21Introduce deduced parameter attributes, and use them for deducing `readonly` onPatrick Walton-0/+1
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-14Remove the `describe` method from the `QueryDescription` traitnils-8/+4
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-14Get rid of `rustc_query_description!`Nilstrieb-11/+9
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-07Rewrite representabilityCameron Steffen-4/+14
2022-10-06Remove `-Ztime` option.Nicholas Nethercote-1/+1
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-01Correct Key impl for HirId.Camille GILLOT-2/+2
2022-10-01Compute `lint_levels` by definitionDeadbeef-1/+17
2022-09-26Auto merge of #101785 - jyn514:query-struct-fn-ptrs, r=cjgillotbors-56/+95
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-25Move the `codegen_unit` debug assert from `rustc_query_system` to `query_impl`Joshua Nelson-0/+18
This allows removing a function from the `DepKind` trait.
2022-09-25Use function pointers instead of macro-unrolled loops in rustc_query_implJoshua Nelson-56/+95
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-24separate definitions and `HIR` ownersTakayuki Maeda-0/+14
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-24Auto merge of #102064 - cjgillot:revert, r=Mark-Simulacrumbors-17/+0
Revert perf-regression 101620 Reverts #101862 #101620 r? `@Mark-Simulacrum`
2022-09-23rename Unevaluated to UnevaluatedConstb-naber-1/+1
2022-09-22Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk"Camille GILLOT-17/+0
This reverts commit 2cb9a65684dba47c52de8fa938febf97a73e70a9, reversing changes made to 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c.
2022-09-22introduce mir::Unevaluatedb-naber-1/+1
2022-09-17Rollup merge of #101801 - SparrowLii:query_depth_note, r=estebankMatthias Krüger-2/+27
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-16Rollup merge of #101787 - compiler-errors:cache-rpitit, r=petrochenkovDylan DPC-0/+6
cache `collect_trait_impl_trait_tys` Micro-optimization for RPITITs
2022-09-15Auto merge of #101173 - jyn514:simplify-macro-arguments, r=cjgillotbors-8/+20
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-15correct span, add help message and add UI test when query depth overflowsSparrowLii-1/+26
2022-09-15add note for `layout_of` when query depth overflowsSparrowLii-1/+1
2022-09-14cache collect_trait_impl_trait_tysMichael Goulet-0/+6
2022-09-14Correct Key impl for HirId.Camille GILLOT-2/+2
2022-09-14Compute `lint_levels` by definitionDeadbeef-0/+17
2022-09-14Auto merge of #101307 - jyn514:simplify-storage, r=cjgillotbors-3/+26
Simplify caching and storage for queries I highly recommend reviewing commit-by-commit; each individual commit is quite small but it can be hard to see looking at the overall diff that the behavior is the same. Each commit depends on the previous. r? `@cjgillot`
2022-09-10Rollup merge of #101635 - jyn514:queries-new-derived, r=cjgillotDylan DPC-15/+20
Move `Queries::new` out of the macro Split out from https://github.com/rust-lang/rust/pull/101178 to make sure it's not contributing to the perf impact. r? `@cjgillot`
2022-09-09Remove unnecessary `TRY_LOAD_FROM_DISK` constantJoshua Nelson-5/+1
2022-09-09Move `TRY_LOAD_FROM_DISK` out of `rustc_queries` to `rustc_query_impl`Joshua Nelson-0/+3
We want to refer to `crate::plumbing::try_load_from_disk` in the const, but hard-coding it in rustc_queries, where we don't yet know the crate this macro will be called in, seems kind of hacky. Do it in query_impl instead.
2022-09-09Remove `cache_on_disk` from `QueryVTable`Joshua Nelson-2/+1
This is not only simpler, but removes a generic function and unwrap. I have hope it will see compile time and bootstrap time improvements.
2022-09-09Don't create a new `try_load_from_disk` closure for each queryJoshua Nelson-1/+26
Instead, define a single function, parameterized only by the return type.
2022-09-06Get rid of the emitted `rustc_query_names` and `rustc_cached_queries` macroJoshua Nelson-9/+21
We can avoid these by adding slightly more information to `rustc_query_append` instead.
2022-09-06Support doc-comments in `define_dep_nodes`Joshua Nelson-2/+2
2022-09-06Further simplify the macros generated by `rustc_queries`Joshua Nelson-2/+2
- 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`.
2022-09-06Move `Queries::new` out of the macroJoshua Nelson-15/+20
2022-09-06Make `HandleCycleError` an enum instead of a macro-generated closureJoshua Nelson-81/+11
- Add a `HandleCycleError` enum to rustc_query_system, along with a `handle_cycle_error` function - Move `Value` to rustc_query_system, so `handle_cycle_error` can use it - Move the `Value` impls from rustc_query_impl to rustc_middle. This is necessary due to orphan rules.
2022-09-01Don't create two new closures for each queryJoshua Nelson-30/+21
- Parameterize DepKindStruct over `'tcx` This allows passing in an invariant function pointer in `query_callback`, rather than having to try and make it work for any lifetime. - Add a new `execute_query` function to `QueryDescription` so we can call `tcx.$name` without needing to be in a macro context
2022-09-01Simplify `try_load_from_on_disk_cache`Joshua Nelson-8/+9
2022-09-01Move almost all of the function in `query_callbacks` to a generic functionJoshua Nelson-28/+47
2022-09-01Get rid of `fn recover`Joshua Nelson-18/+8
2022-09-01Move `force_with_dep_node` outside the giant macroJoshua Nelson-16/+26
2022-09-01Move `try_on_disk_cache` out of the giant macroJoshua Nelson-11/+19
2022-09-01Get rid of `make_query` moduleJoshua Nelson-13/+6
2022-09-01tracing::instrument cleanupOli Scherer-1/+1
2022-08-29Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`.Nicholas Nethercote-6/+4
`rustc_data_structures::thin_vec::ThinVec` looks like this: ``` pub struct ThinVec<T>(Option<Box<Vec<T>>>); ``` It's just a zero word if the vector is empty, but requires two allocations if it is non-empty. So it's only usable in cases where the vector is empty most of the time. This commit removes it in favour of `thin_vec::ThinVec`, which is also word-sized, but stores the length and capacity in the same allocation as the elements. It's good in a wider variety of situation, e.g. in enum variants where the vector is usually/always non-empty. The commit also: - Sorts some `Cargo.toml` dependency lists, to make additions easier. - Sorts some `use` item lists, to make additions easier. - Changes `clean_trait_ref_with_bindings` to take a `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this avoid some unnecessary allocations.
2022-08-27Auto merge of #100946 - jyn514:query-system-3, r=cjgillotbors-3/+3
Simplify the arguments to macros generated by the `rustc_queries` proc macro Very small cleanup. Based on https://github.com/rust-lang/rust/pull/100436 which modifies some of the same code. r? `@cjgillot`
2022-08-25Auto merge of #100748 - SparrowLii:query_depth, r=cjgillotbors-1/+19
add `depth_limit` in `QueryVTable` to avoid entering a new tcx in `layout_of` Fixes #49735 Updates #48685 The `layout_of` query needs to check whether it overflows the depth limit, and the current implementation needs to create a new `ImplicitCtxt` inside `layout_of`. However, `start_query` will already create a new `ImplicitCtxt`, so we can check the depth limit in `start_query`. We can tell whether we need to check the depth limit simply by whether the return value of `to_debug_str` of the query is `layout_of`. But I think adding the `depth_limit` field in `QueryVTable` may be more elegant and more scalable.
2022-08-25Auto merge of #100436 - jyn514:macro-query-system, r=cjgillotbors-80/+89
try and simplify some things in the query system