-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Refactor the query system to reduce the amount of macro-expanded functions #96524
Copy link
Copy link
Closed
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationA-query-systemArea: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationA-query-systemArea: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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_constnessfromrustc_query_impl(Remove opt_remap_env_constness from rustc_query_impl #100243)The interface code in
rustc_middle::ty::querycan be made responsible for calling it, it already does.QueryDescriptiontraitTRY_LOAD_FROM_DISK,cache_on_diskanddescribeare only used forthe
QueryVtableandmake_query::$name. They can be made inherentassociated constant and functions on the
queries::$nametypes.Valuetrait torustc_query_system(MakeHandleCycleErroran enum instead of a macro-generated closure #101303)This would allow to replace the function pointer for
handle_cycle_errorby a simple enum.make_query::$namefunctions to a generic version instead of a macro (Move most ofTyCtxtAt::$nameinto a genericevaluate_queryfunction #101178)The call to
opt_remap_env_constness!is unnecessary. TheDepKindcan be passed as a parameter.describecan be passed as a function pointer.keycan be made animpl Key + HashStable.We should consider moving part of the code into
QueryState::try_collect_active_jobswhich is the only user of these functions.DepKindStructtorustc_query_system(Move DepKindStruct from rustc_middle to rustc_query_system #101710)DepKindStructis defined inrustc_middle::dep_graph::dep_node. It depends onTyCtxtandDepKind, but that can be replaced by a generic parameterCTX: DepContextandCTX::DepKind.rustc_query_systemwould access it through a newDepContext::dep_kind_infoprovidingfingerprint_style,is_eval_always,try_force_from_dep_nodeandtry_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_nodegeneric overCTX: DepContext, and move it torustc_query_system.QueryStructwith 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_jobsby a loop over function pointers;alloc_self_profile_query_stringsby a loop over function pointers;encode_query_resultsby 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_jobsandalloc_self_profile_query_stringsfunction pointers inDepKindStructinstead.Please contact me on Zulip for further information.