-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the query system to reduce the amount of macro-expanded functions #96524
Comments
@rustbot claim |
Update: I started working on this a while back but I got pulled away by other things. I will have more bandwidth in the next couple of weeks and hopefully have a PR. |
…tem, r=cjgillot Remove opt_remap_env_constness from rustc_query_impl 1st task off rust-lang#96524. r? `@cjgillot`
@kckeiks what parts of this issue are you currently working on? don't want to step on your toes, but I think there's enough work here we can split it up between us and have plenty of work for both :) |
@jyn514 I had started working on "Simplify QueryDescription trait" and looking into "Refactor make_query::$name functions to a generic version instead of a macro". I was planning on continuing working on these tasks in the next 1-2 weeks when I would have more bandwidth. Please let me know what you plan to pick up. |
Cool :) I've already done the |
I had an idea for how to change the 3 nested macros ( I've realized one of the reasons The tradeoff is that we'll have fewer layers of macros, at the cost of moving more code into the proc-macro, which makes it harder to refactor. Here are the uses of the macros I see today:
|
oh heh, this is what @eddyb suggested 4 years ago #56462 (comment) |
Simplify the `define_query` macro This moves a bunch of control flow out of the macro into generic functions, leaving the macro just to call the function with a new generic parameter for each query. It may be possible to improve compile-times / icache by instantiating the generic functions only with the query key, not the query type itself, but I'm going to leave that for a follow-up PR. Helps with rust-lang#96524. r? `@cjgillot`
…r=cjgillot Make `HandleCycleError` an enum instead of a macro-generated closure Helps with rust-lang#96524. Based on rust-lang#100943 to avoid merge conflicts, so it looks larger than it is (only the last commit is relevant). cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60Value.60.20to.20rustc_query_system.20.2396524 r? `@cjgillot`
…cjgillot Make `HandleCycleError` an enum instead of a macro-generated closure Helps with rust-lang#96524. Based on rust-lang#100943 to avoid merge conflicts, so it looks larger than it is (only the last commit is relevant). cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60Value.60.20to.20rustc_query_system.20.2396524 r? `@cjgillot`
I think this won't be possible after #101710, because DepKindStruct will be defined in rustc_query_system which doesn't have access to QueryCtxt. I guess it could use type parameters though. |
Move DepKindStruct from rustc_middle to rustc_query_system Helps with rust-lang#96524. cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60DepKindStruct.60.20to.20rustc_query_system.20.2396524 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 rust-lang#96524. Based on rust-lang#101173; only the last commit is relevant. r? `@cjgillot`
Get rid of `rustc_query_description!` **I am not entirely sure whether this is an improvement and would like to get your feedback on it.** Helps with rust-lang#96524. 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 mthere as well. r? `@cjgillot`
Releasing assignment due to inactivity, feel free to claim it again. @rustbot release-assignment |
Yeah sorry, I got busy with work :(. If no one picks it up in the summer, I should have some time to try to tackle it then. |
Make `HandleCycleError` an enum instead of a macro-generated closure Helps with rust-lang/rust#96524. Based on rust-lang/rust#100943 to avoid merge conflicts, so it looks larger than it is (only the last commit is relevant). cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60Value.60.20to.20rustc_query_system.20.2396524 r? `@cjgillot`
Make `HandleCycleError` an enum instead of a macro-generated closure Helps with rust-lang/rust#96524. Based on rust-lang/rust#100943 to avoid merge conflicts, so it looks larger than it is (only the last commit is relevant). cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60Value.60.20to.20rustc_query_system.20.2396524 r? `@cjgillot`
The current implementation of the query system relies on a lot of macro-expanded functions.
This issue tracks perspectives to reduce this use of macros.
The objective of this issue is to have the macros expand to a self-contained description of the query, instead of breadcrumbs in several files.
opt_remap_env_constness
fromrustc_query_impl
(Remove opt_remap_env_constness from rustc_query_impl #100243)The interface code in
rustc_middle::ty::query
can be made responsible for calling it, it already does.QueryDescription
traitTRY_LOAD_FROM_DISK
,cache_on_disk
anddescribe
are only used forthe
QueryVtable
andmake_query::$name
. They can be made inherentassociated constant and functions on the
queries::$name
types.Value
trait torustc_query_system
(MakeHandleCycleError
an enum instead of a macro-generated closure #101303)This would allow to replace the function pointer for
handle_cycle_error
by a simple enum.make_query::$name
functions to a generic version instead of a macro (Move most ofTyCtxtAt::$name
into a genericevaluate_query
function #101178)The call to
opt_remap_env_constness!
is unnecessary. TheDepKind
can be passed as a parameter.describe
can be passed as a function pointer.key
can be made animpl Key + HashStable
.We should consider moving part of the code into
QueryState::try_collect_active_jobs
which is the only user of these functions.DepKindStruct
torustc_query_system
(Move DepKindStruct from rustc_middle to rustc_query_system #101710)DepKindStruct
is defined inrustc_middle::dep_graph::dep_node
. It depends onTyCtxt
andDepKind
, but that can be replaced by a generic parameterCTX: DepContext
andCTX::DepKind
.rustc_query_system
would access it through a newDepContext::dep_kind_info
providingfingerprint_style
,is_eval_always
,try_force_from_dep_node
andtry_load_from_on_disk_cacke
, and replacingTyCtxt::query_kind
.If specialization allows it, we should aim to make most of the code in
rustc_middle::dep_graph::dep_node
generic overCTX: DepContext
, and move it torustc_query_system
.QueryStruct
with function pointers (Use function pointers instead of macro-unrolled loops in rustc_query_impl #101785)Having macro-unrolled loops prevents extension of the infrastructure to non-statically known instances. This struct is to be used in a similar way to
DepKindStruct
, but with types private torustc_query_impl
.This will be used to:
try_collect_active_jobs
by a loop over function pointers;alloc_self_profile_query_strings
by a loop over function pointers;encode_query_results
by a loop over function pointers.The array itself should be created using
make_dep_kind_array!
which handles the indices.Possible variant: put the
try_collect_active_jobs
andalloc_self_profile_query_strings
function pointers inDepKindStruct
instead.Please contact me on Zulip for further information.
The text was updated successfully, but these errors were encountered: