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.
The interface code in rustc_middle::ty::query can be made responsible for calling it, it already does.
TRY_LOAD_FROM_DISK, cache_on_disk and describe are only used for
the QueryVtable and make_query::$name. They can be made inherent
associated constant and functions on the queries::$name types.
This would allow to replace the function pointer for handle_cycle_error by a simple enum.
The call to opt_remap_env_constness! is unnecessary. The DepKind can be passed as a parameter. describe can be passed as a function pointer. key can be made an impl 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 is defined in rustc_middle::dep_graph::dep_node. It depends on TyCtxt and DepKind, but that can be replaced by a generic parameter CTX: DepContext and CTX::DepKind.
rustc_query_system would access it through a new DepContext::dep_kind_info providing fingerprint_style, is_eval_always, try_force_from_dep_node and try_load_from_on_disk_cacke, and replacing TyCtxt::query_kind.
If specialization allows it, we should aim to make most of the code in rustc_middle::dep_graph::dep_node generic over CTX: DepContext, and move it to rustc_query_system.
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 to rustc_query_impl.
struct QueryStruct {
try_collect_active_jobs: fn(QueryCtxt<'_>, &mut QueryMap) -> Option<()>,
alloc_self_profile_query_strings: fn(QueryCtxt<'tcx>, &mut QueryKeyStringCache),
encode_query_results: Option<fn(QueryCtxt<'_>, &mut CacheEncoder<...>, &mut EncodedDepNodeIndex)>
}
This will be used to:
- replace the macro expansion in
try_collect_active_jobs by a loop over function pointers;
- replace the macro expansion in
alloc_self_profile_query_strings by a loop over function pointers;
- replace the macro expansion in
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 and alloc_self_profile_query_strings function pointers in DepKindStruct instead.
Please contact me on Zulip for further information.
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.