Skip to main content

Module queries

Module queries 

Source
Expand description

§The rustc Query System: Query Definitions and Modifiers

The core processes in rustc are shipped as queries. Each query is a demand-driven function from some key to a value. The execution result of the function is cached and directly read during the next request, thereby improving compilation efficiency. Some results are saved locally and directly read during the next compilation, which are core of incremental compilation.

§How to Read This Module

Each query block in this file defines a single query, specifying its key and value types, along with various modifiers. These query definitions are processed by the rustc_macros, which expands them into the necessary boilerplate code for the query system—including the Providers struct (a function table for all query implementations, where each field is a function pointer to the actual provider), caching, and dependency graph integration. Note: The Providers struct is not a Rust trait, but a struct generated by the rustc_macros to hold all provider functions. The rustc_macros also supports a set of query modifiers (see below) that control the behavior of each query.

The actual provider functions are implemented in various modules and registered into the Providers struct during compiler initialization (see rustc_interface::passes::DEFAULT_QUERY_PROVIDERS).

§Query Modifiers

Query modifiers are special flags that alter the behavior of a query. They are parsed and processed by the rustc_macros The main modifiers are:

  • desc { ... }: Sets the human-readable description for diagnostics and profiling. Required for every query.
  • arena_cache: Use an arena for in-memory caching of the query result.
  • cache_on_disk_if { ... }: Cache the query result to disk if the provided block evaluates to true.
  • cycle_fatal: If a dependency cycle is detected, abort compilation with a fatal error.
  • cycle_delay_bug: If a dependency cycle is detected, emit a delayed bug instead of aborting immediately.
  • cycle_stash: If a dependency cycle is detected, stash the error for later handling.
  • no_hash: Do not hash the query result for incremental compilation; just mark as dirty if recomputed.
  • anon: Make the query anonymous in the dependency graph (no dep node is created).
  • eval_always: Always evaluate the query, ignoring its dependencies and cached results.
  • depth_limit: Impose a recursion depth limit on the query to prevent stack overflows.
  • separate_provide_extern: Use separate provider functions for local and external crates.
  • feedable: Allow the query result to be set from another query (“fed” externally).
  • return_result_from_ensure_ok: When called via tcx.ensure_ok(), return Result<(), ErrorGuaranteed> instead of (). If the query needs to be executed and returns an error, the error is returned to the caller. Only valid for queries returning Result<_, ErrorGuaranteed>.

For the up-to-date list, see the QueryModifiers struct in rustc_macros/src/query.rs and for more details in incremental compilation, see the Query modifiers in incremental compilation section of the rustc-dev-guide.

§Query Expansion and Code Generation

The rustc_macros::rustc_queries macro expands each query definition into:

  • A method on TyCtxt (and crate::query::TyCtxtAt) for invoking the query.
  • Provider traits and structs for supplying the query’s value.
  • Caching and dependency graph integration.
  • Support for incremental compilation, disk caching, and arena allocation as controlled by the modifiers.

The macro-based approach allows the query system to be highly flexible and maintainable, while minimizing boilerplate.

For more details, see the rustc-dev-guide.

Modules§

_analyzer_hints 🔒
_cache_on_disk_if_fns
_description_fns
Functions that format a human-readable description of each query and its key, as specified by the desc query modifier.
adt_async_destructor
adt_async_drop_tys
adt_def
adt_destructor
adt_drop_tys
adt_dtorck_constraint
adt_significant_drop_tys
adt_sizedness_constraint
all_diagnostic_items
all_local_trait_impls
alloc_error_handler_kind
allocator_kind
analysis
anon_const_kind
asm_target_features
associated_item
associated_item_def_ids
associated_items
associated_types_for_impl_traits_in_trait_or_impl
assumed_wf_types
assumed_wf_types_for_rpitit
asyncness
attrs_for_def
backend_optimization_level
check_coroutine_obligations
check_expectations
check_externally_implementable_items
check_liveness
check_match
check_mod_attrs
check_mod_deathness
check_mod_privacy
check_mod_unstable_api_usage
check_mono_item
check_potentially_region_dependent_goals
check_private_in_public
check_tail_calls
check_transmutes
check_type_wf
check_unsafety
check_unused_traits
check_validity_requirement
check_well_formed
clashing_extern_declarations
closure_saved_names_of_captured_variables
closure_typeinfo
codegen_fn_attrs
codegen_select_candidate
codegen_unit
coerce_unsized_info
coherent_trait
collect_and_partition_mono_items
collect_return_position_impl_trait_in_trait_tys
compare_impl_item
const_conditions
const_of_item
const_param_default
constness
coroutine_by_move_body_def_id
coroutine_for_closure
coroutine_hidden_types
coroutine_kind
coverage_attr_on
coverage_ids_info
crate_extern_paths
crate_for_resolver
crate_hash
crate_host_hash
crate_incoherent_impls
crate_inherent_impls
crate_inherent_impls_overlap_check
crate_inherent_impls_validity_check
crate_name
crate_variances
crates
cross_crate_inlinable
debugger_visualizers
deduced_param_attrs
def_ident_span
def_kind
def_span
default_field
defaultness
defined_lang_items
dep_kind
dependency_formats
derive_macro_expansion
diagnostic_hir_wf_check
diagnostic_items
doc_link_resolutions
doc_link_traits_in_scope
dropck_outlives
duplicate_crate_names
dylib_dependency_formats
dyn_compatibility_violations
early_lint_checks
effective_visibilities
enforce_impl_non_lifetime_params_are_constrained
entry_fn
env_var_os
erase_and_anonymize_regions_ty
eval_static_initializer
eval_to_allocation_raw
eval_to_const_value_raw
eval_to_valtree
evaluate_obligation
evaluate_root_goal_for_proof_tree_raw
explicit_implied_const_bounds
explicit_implied_predicates_of
explicit_item_bounds
explicit_item_self_bounds
explicit_predicates_of
explicit_super_predicates_of
explicit_supertraits_containing_assoc_item
expn_that_defined
exportable_items
exported_generic_symbols
exported_non_generic_symbols
extern_crate
externally_implementable_items
extra_filename
features_query
first_method_vtable_slot
fn_abi_of_fn_ptr
fn_abi_of_instance
fn_arg_idents
fn_sig
foreign_modules
generics_of
generics_require_sized_self
get_lang_items
global_backend_features
has_alloc_error_handler
has_ffi_unwind_calls
has_global_allocator
has_panic_handler
has_significant_drop_raw
has_structural_eq_impl
hir_attr_map
hir_crate
hir_crate_items
hir_module_items
hir_owner_parent_q
impl_item_implementor_ids
impl_parent
impl_self_is_guaranteed_unsized
impl_super_outlives
impl_trait_header
implementations_of_trait
implied_outlives_bounds
implied_target_features
in_scope_traits_map
incoherent_impls
inferred_outlives_crate
inferred_outlives_of
inhabited_predicate_adt
inhabited_predicate_type
inherent_impls
inherit_sig_for_delegation_item
inherited_align
instantiate_and_check_impossible_predicates
intrinsic_raw
is_async_drop_raw
is_codegened_item
is_compiler_builtins
is_copy_raw
is_doc_hidden
is_doc_notable_trait
is_dyn_compatible
is_freeze_raw
is_impossible_associated_item
is_late_bound_map
is_mir_available
is_no_builtins
is_panic_runtime
is_private_dep
is_profiler_runtime
is_promotable_const_fn
is_reachable_non_generic
is_rhs_type_const
is_sized_raw
is_unpin_raw
is_unreachable_local_definition
is_use_cloned_raw
item_bounds
item_non_self_bounds
item_self_bounds
items_of_instance
late_bound_vars_map
layout_of
lib_features
limits
lint_expectations
lint_mod
lints_that_dont_need_to_run
list_significant_drop_tys
lit_to_const
live_symbols_and_ignored_derived_traits
local_def_id_to_hir_id
local_trait_impls
lookup_const_stability
lookup_default_body_stability
lookup_deprecation_entry
lookup_stability
method_autoderef_steps
mir_borrowck
mir_built
mir_callgraph_cyclic
mir_const_qualif
mir_coroutine_witnesses
mir_drops_elaborated_and_const_checked
mir_for_ctfe
mir_inliner_callees
mir_keys
mir_promoted
mir_shims
missing_extern_crate_item
missing_lang_items
module_children
named_variable_map
native_libraries
native_library
needs_async_drop_raw
needs_drop_raw
nested_bodies_within
normalize_canonicalized_free_alias
normalize_canonicalized_inherent_projection
normalize_canonicalized_projection
num_extern_def_ids
object_lifetime_default
opaque_captured_lifetimes
opaque_ty_origin
opaque_types_defined_by
opt_ast_lowering_delayed_lints
opt_hir_owner_nodes
optimized_mir
orphan_check_impl
output_filenames
own_existential_vtable_entries
panic_in_drop_strategy
param_env
params_in_repr
postorder_cnums
predicates_of
proc_macro_decls_static
promoted_mir
reachable_non_generics
reachable_set
region_scope_tree
registered_tools
rendered_const
rendered_precise_capturing_args
representability
representability_adt_ty
required_panic_strategy
resolutions
resolve_bound_vars
resolve_instance_raw
resolver_for_lowering_raw
reveal_opaque_types_in_bounds
rust_target_features
sanitizer_settings_for
shallow_lint_levels_on
should_inherit_track_caller
size_estimate
skip_move_check_fns
source_span
specialization_enabled_in
specialization_graph_of
specializes
stability_implications
stable_order_of_exportable_impls
stripped_cfg_items
supertrait_vtable_slot
symbol_mangling_version
symbol_name
tag_for_variant
thir_abstract_const
thir_body
trait_def
trait_explicit_predicates_and_bounds
trait_impls_in_crate
trait_impls_of
traits
trigger_delayed_bug
trimmed_def_paths
trivial_const
try_normalize_generic_arg_after_erasing_regions
ty_span
type_alias_is_lazy
type_of
type_of_opaque
type_of_opaque_hir_typeck
type_op_ascribe_user_type
type_op_normalize_clause
type_op_normalize_fn_sig
type_op_normalize_poly_fn_sig
type_op_normalize_ty
type_op_prove_predicate
type_param_predicates
typeck
typing_env_normalized_for_post_analysis
unsizing_params_for_adt
upstream_async_drop_glue_for
upstream_drop_glue_for
upstream_monomorphizations
upstream_monomorphizations_for
upvars_mentioned
used_crate_source
used_crates
used_trait_imports
valtree_to_const_val
variances_of
visibility
visible_parent_map
vtable_allocation
vtable_entries
wasm_import_module_map

Macros§

rustc_feedable_queries 🔒

Structs§

ExternProviders
PerQueryVTables
Holds a QueryVTable for each query.
Providers
QueryArenas
Holds per-query arenas for queries with the arena_cache modifier.
QueryCaches
QueryEngine
QueryStates