- Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
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.
- Remove
opt_remap_env_constnessfromrustc_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.
- Simplify
QueryDescriptiontrait
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.
- Move
Valuetrait torustc_query_system(MakeHandleCycleErroran enum instead of a macro-generated closure #101303)
This would allow to replace the function pointer for handle_cycle_error by a simple enum.
- Refactor
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. 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.
- Move
DepKindStructtorustc_query_system(Move DepKindStruct from rustc_middle to rustc_query_system #101710)
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.
- Introduce an array of
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 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_jobsby a loop over function pointers; - replace the macro expansion in
alloc_self_profile_query_stringsby a loop over function pointers; - replace the macro expansion in
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_jobs and alloc_self_profile_query_strings function pointers in DepKindStruct instead.
Please contact me on Zulip for further information.