about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/query
AgeCommit message (Collapse)AuthorLines
2022-10-25rustc_middle: Rearrange resolver outputs structures slightlyVadim Petrochenkov-1/+1
2022-10-23Auto merge of #102660 - camsteffen:uninhabited-perf, r=oli-obkbors-8/+7
Remove ParamEnv from uninhabited query
2022-10-22Introduce InhabitedPredicateCameron Steffen-8/+7
2022-10-22Auto merge of #103196 - Nilstrieb:no-meta-query, r=cjgillotbors-10/+0
Get rid of native_library projection queries They don't seem particularly useful as I don't expect native libraries to change frequently. Maybe they do provide significant value of keeping incremental compilation green though, I'm not sure.
2022-10-21Introduce deduced parameter attributes, and use them for deducing `readonly` onPatrick Walton-0/+5
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-19Don't call `own_existential_vtable_entries` on unresolved trait refMichael Goulet-2/+2
2022-10-19Get rid of native_library projection queriesnils-10/+0
They don't seem particularly useful as I don't expect native libraries to change frequently.
2022-10-18Clean up query descriptionsnils-89/+92
Use the same tense everywhere and prefer display over debug, as these descriptions are user facing.
2022-10-17rm `try_normalize_mir_const_after_erasing_regions`lcnr-8/+0
2022-10-14Get rid of `rustc_query_description!`Nilstrieb-1/+4
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-10Check representability in adt_sized_constraintCameron Steffen-9/+1
2022-10-07Rewrite representabilityCameron Steffen-0/+26
2022-10-06Rollup merge of #98496 - BoxyUwU:instancers_bad_equality, r=lcnrMatthias Krüger-0/+6
make `compare_const_impl` a query and use it in `instance.rs` Fixes #88365 the bug in #88365 was caused by some `instance.rs` code using the `PartialEq` impl on `Ty` to check that the type of the associated const in an impl is the same as the type of the associated const in the trait definition. This was wrong for two reasons: - the check typeck does is that the impl type is a subtype of the trait definition's type (see `mismatched_impl_ty_2.rs` which [was ICEing](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f6d60ebe6745011f0d52ab2bc712025d) before this PR on stable) - it assumes that if two types are equal then the `PartialEq` impl will reflect that which isnt true for higher ranked types or type level constants when `feature(generic_const_exprs)` is enabled (see `mismatched_impl_ty_3.rs` for higher ranked types which was [ICEing on stable](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d7af131a655ed515b035624626c62c71)) r? `@lcnr`
2022-10-01Compute by owner instead of HirId.Camille GILLOT-2/+3
2022-10-01Move lint level computation to rustc_middle::lint.Camille GILLOT-1/+1
2022-10-01Compute `lint_levels` by definitionDeadbeef-3/+7
2022-09-30make query take `(LocalDefId, DefId)`Boxy-2/+2
2022-09-30make `compare_const_impl` a query and use it in `instance.rs`Boxy-0/+6
2022-09-27rustdoc: Queryify `is_notable_trait`Noah Lev-0/+5
This might help with #102375.
2022-09-24separate definitions and `HIR` ownersTakayuki Maeda-8/+8
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-7/+3
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-7/+3
This reverts commit 2cb9a65684dba47c52de8fa938febf97a73e70a9, reversing changes made to 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c.
2022-09-22introduce mir::Unevaluatedb-naber-1/+1
2022-09-19`DestructuredConst` split mir and tylcnr-1/+3
2022-09-16Rollup merge of #101787 - compiler-errors:cache-rpitit, r=petrochenkovDylan DPC-1/+2
cache `collect_trait_impl_trait_tys` Micro-optimization for RPITITs
2022-09-14cache collect_trait_impl_trait_tysMichael Goulet-1/+2
2022-09-14Move some code and add comments.Camille GILLOT-1/+1
2022-09-14Compute `lint_levels` by definitionDeadbeef-3/+7
2022-09-14Auto merge of #101307 - jyn514:simplify-storage, r=cjgillotbors-56/+49
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-13Rollup merge of #101765 - GuillaumeGomez:tyctxt-visibility-doc, r=jyn514Matthias Krüger-0/+10
Add documentation for TyCtxt::visibility We encountered this issue while working on https://github.com/rust-lang/rust/pull/98450. cc ``@lqd`` r? ``@cjgillot``
2022-09-13Auto merge of #101615 - compiler-errors:rpitit-perf, r=oli-obkbors-1/+1
Make `compare_predicate_entailment` no longer a query Make `compare_predicate_entailment` so it's no longer a query (again), and splits out the new logic (that equates the return types to infer RPITITs) into its own query. This means that this new query (now called `collect_trait_impl_trait_tys`) is no longer executed for non-RPITIT cases. This should improve perf (https://github.com/rust-lang/rust/pull/101224#issuecomment-1241682203), though in practice we see that these some crates remain from the primary regressions list on the original report... They are all <= 0.43% regression and seemingly only on the incr-full scenario for all of them. I am at a loss for what might be causing this regression other than what I fixed here, since we don't introduce much new non-RPITIT logic except for some `def_kind` query calls in some places, for example, like projection. Maybe that's it? ---- Originally this PR was opened to test enabling `cache_on_disk` (62164aaaa11) but that didn't turn out to be very useful (https://github.com/rust-lang/rust/pull/101615#issuecomment-1242403205), so that led me to just split the query (and rename the PR).
2022-09-13Add documentation for TyCtxt::visibilityGuillaume Gomez-0/+10
2022-09-10split compare_predicate_entailment and collect_trait_impl_trait_tys outMichael Goulet-1/+1
2022-09-09Don't use a custom disk loader for diagnostic_only_typeckJoshua Nelson-7/+0
This uses exactly the same types for query results as `typeck`, which doesn't have custom code. It's not clear to me why this code exists (it goes back even before queries used a proc macro), but it compiles fine without the custom loader. Remove it for simplicity.
2022-09-09Make the `storage` query modifier less generalJoshua Nelson-49/+49
In practice, it was only ever used with `ArenaCacheSelector`. Change it to a single boolean `arena_cache` rather than allowing queries to specify an arbitrary type.
2022-09-09rename `codegen_fulfill_obligation`lcnr-5/+2
2022-09-09Deeply check that method signatures match, and allow for nested RPITITsMichael Goulet-0/+7
2022-09-07rustc: Parameterize `ty::Visibility` over used IDVadim Petrochenkov-1/+1
It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
2022-09-03Do not call object_lifetime_default on lifetime params.Camille GILLOT-5/+6
2022-08-31Fix a bunch of typoDezhi Wu-1/+1
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-29Rollup merge of #99821 - cjgillot:ast-lifetimes-2, r=compiler-errorsDylan DPC-2/+3
Remove separate indexing of early-bound regions ~Based on https://github.com/rust-lang/rust/pull/99728.~ This PR copies some modifications from https://github.com/rust-lang/rust/pull/97839 around object lifetime defaults. These modifications allow to stop counting generic parameters during lifetime resolution, and rely on the indexing given by `rustc_typeck::collect`.
2022-08-26Implementation of import_name_typeDaniel Paoliello-0/+3
2022-08-25Auto merge of #100748 - SparrowLii:query_depth, r=cjgillotbors-0/+1
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-24add `depth_limit` in `QueryVTable`SparrowLii-0/+1
2022-08-23Use par_body_owners for livenessSeo Sanghyeon-2/+2
2022-08-22Auto merge of #100676 - lcnr:implied-bounds-yay, r=nikomatsakisbors-0/+8
implied bounds: explicitly state which types are assumed to be wf Adds a new query which maps each definition to the types which that definition assumes to be well formed. The intent is to make it easier to reason about implied bounds. This change should not influence the user-facing behavior of rustc. Notably, `borrowck` still only assumes that the function signature of associated functions is well formed while `wfcheck` assumes that the both the function signature and the impl trait ref is well formed. Not sure if that by itself can trigger UB or whether it's just annoying. As a next step, we can add `WellFormed` predicates to `predicates_of` of these items and can stop adding the wf bounds at each place which uses them. I also intend to move the computation from `assumed_wf_types` to `implied_bounds` into the `param_env` computation. This requires me to take a deeper look at `compare_predicate_entailment` which is currently somewhat weird wrt implied bounds so I am not touching this here. r? `@nikomatsakis`
2022-08-17implied_bounds: clarify our assumptionslcnr-0/+8
2022-08-16Do not report cycle error when inferring return type for suggestionMichael Goulet-0/+1
2022-08-09Rollup merge of #100221 - compiler-errors:impossible-trait-items, ↵Dylan DPC-0/+8
r=lcnr,notriddle,camelid Don't document impossible to call default trait items on impls Closes #100176 This only skips documenting _default_ trait items on impls, not ones that are written inside the impl block. This is a conservative approach, since I think we should document all items written in an impl block (I guess unless hidden or whatever), but the existence of this new query I added makes this easy to extend to other rustdoc cases.