1use std::fmt;
2use std::ops::Deref;
34use rustc_data_structures::fingerprint::Fingerprint;
5use rustc_data_structures::fx::FxIndexMap;
6use rustc_data_structures::hash_table::HashTable;
7use rustc_data_structures::sharded::Sharded;
8use rustc_data_structures::sync::{AtomicU64, Lock, WorkerLocal};
9use rustc_errors::Diag;
10use rustc_hir::def_id::LocalDefId;
11use rustc_span::Span;
1213use crate::dep_graph::{DepKind, DepNodeIndex, QuerySideEffect, SerializedDepNodeIndex};
14use crate::ich::StableHashingContext;
15use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables, TaggedQueryKey};
16use crate::query::on_disk_cache::OnDiskCache;
17use crate::query::{IntoQueryKey, QueryCache, QueryJob, QueryStackFrame};
18use crate::ty::{self, TyCtxt};
1920/// For a particular query, keeps track of "active" keys, i.e. keys whose
21/// evaluation has started but has not yet finished successfully.
22///
23/// (Successful query evaluation for a key is represented by an entry in the
24/// query's in-memory cache.)
25pub struct QueryState<'tcx, K> {
26pub active: Sharded<HashTable<(K, ActiveKeyStatus<'tcx>)>>,
27}
2829impl<'tcx, K> Defaultfor QueryState<'tcx, K> {
30fn default() -> QueryState<'tcx, K> {
31QueryState { active: Default::default() }
32 }
33}
3435/// For a particular query and key, tracks the status of a query evaluation
36/// that has started, but has not yet finished successfully.
37///
38/// (Successful query evaluation for a key is represented by an entry in the
39/// query's in-memory cache.)
40pub enum ActiveKeyStatus<'tcx> {
41/// Some thread is already evaluating the query for this key.
42 ///
43 /// The enclosed [`QueryJob`] can be used to wait for it to finish.
44Started(QueryJob<'tcx>),
4546/// The query panicked. Queries trying to wait on this will raise a fatal error which will
47 /// silently panic.
48Poisoned,
49}
5051#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Cycle<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "Cycle",
"usage", &self.usage, "frames", &&self.frames)
}
}Debug)]
52pub struct Cycle<'tcx> {
53/// The query and related span that uses the cycle.
54pub usage: Option<QueryStackFrame<'tcx>>,
5556/// The span here corresponds to the reason for which this query was required.
57pub frames: Vec<QueryStackFrame<'tcx>>,
58}
5960#[derive(#[automatically_derived]
impl ::core::fmt::Debug for QueryMode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
QueryMode::Get => ::core::fmt::Formatter::write_str(f, "Get"),
QueryMode::Ensure { ensure_mode: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Ensure", "ensure_mode", &__self_0),
}
}
}Debug)]
61pub enum QueryMode {
62/// This is a normal query call to `tcx.$query(..)` or `tcx.at(span).$query(..)`.
63Get,
64/// This is a call to `tcx.ensure_ok().$query(..)` or `tcx.ensure_done().$query(..)`.
65Ensure { ensure_mode: EnsureMode },
66}
6768/// Distinguishes between `tcx.ensure_ok()` and `tcx.ensure_done()` in shared
69/// code paths that handle both modes.
70#[derive(#[automatically_derived]
impl ::core::fmt::Debug for EnsureMode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
EnsureMode::Ok => "Ok",
EnsureMode::Done => "Done",
})
}
}Debug)]
71pub enum EnsureMode {
72/// Corresponds to [`TyCtxt::ensure_ok`].
73Ok,
74/// Corresponds to [`TyCtxt::ensure_done`].
75Done,
76}
7778/// Stores data and metadata (e.g. function pointers) for a particular query.
79pub struct QueryVTable<'tcx, C: QueryCache> {
80pub name: &'static str,
8182/// True if this query has the `eval_always` modifier.
83pub eval_always: bool,
84/// True if this query has the `depth_limit` modifier.
85pub depth_limit: bool,
86/// True if this query has the `feedable` modifier.
87pub feedable: bool,
8889pub dep_kind: DepKind,
90pub state: QueryState<'tcx, C::Key>,
91pub cache: C,
9293/// Function pointer that actually calls this query's provider.
94 /// Also performs some associated secondary tasks; see the macro-defined
95 /// implementation in `mod invoke_provider_fn` for more details.
96 ///
97 /// This should be the only code that calls the provider function.
98pub invoke_provider_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
99100pub will_cache_on_disk_for_key_fn: fn(key: C::Key) -> bool,
101102/// Function pointer that tries to load a query value from disk.
103 ///
104 /// This should only be called after a successful check of `will_cache_on_disk_for_key_fn`.
105pub try_load_from_disk_fn:
106fn(tcx: TyCtxt<'tcx>, prev_index: SerializedDepNodeIndex) -> Option<C::Value>,
107108/// Function pointer that hashes this query's result values.
109 ///
110 /// For `no_hash` queries, this function pointer is None.
111pub hash_value_fn: Option<fn(&mut StableHashingContext<'_>, &C::Value) -> Fingerprint>,
112113/// Function pointer that handles a cycle error. `error` must be consumed, e.g. with `emit` (if
114 /// it should be emitted) or `delay_as_bug` (if it need not be emitted because an alternative
115 /// error is created and emitted). A value may be returned, or (more commonly) the function may
116 /// just abort after emitting the error.
117pub handle_cycle_error_fn:
118fn(tcx: TyCtxt<'tcx>, key: C::Key, cycle: Cycle<'tcx>, error: Diag<'_>) -> C::Value,
119120pub format_value: fn(&C::Value) -> String,
121122pub create_tagged_key: fn(C::Key) -> TaggedQueryKey<'tcx>,
123124/// Function pointer that is called by the query methods on [`TyCtxt`] and
125 /// friends[^1], after they have checked the in-memory cache and found no
126 /// existing value for this key.
127 ///
128 /// Transitive responsibilities include trying to load a disk-cached value
129 /// if possible (incremental only), invoking the query provider if necessary,
130 /// and putting the obtained value into the in-memory cache.
131 ///
132 /// [^1]: [`TyCtxt`], [`TyCtxtAt`], [`TyCtxtEnsureOk`], [`TyCtxtEnsureDone`]
133pub execute_query_fn: fn(TyCtxt<'tcx>, Span, C::Key, QueryMode) -> Option<C::Value>,
134}
135136impl<'tcx, C: QueryCache> fmt::Debugfor QueryVTable<'tcx, C> {
137fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
138// When debug-printing a query vtable (e.g. for ICE or tracing),
139 // just print the query name to know what query we're dealing with.
140 // The other fields and flags are probably just unhelpful noise.
141 //
142 // If there is need for a more detailed dump of all flags and fields,
143 // consider writing a separate dump method and calling it explicitly.
144f.write_str(self.name)
145 }
146}
147148pub struct QuerySystem<'tcx> {
149pub arenas: WorkerLocal<QueryArenas<'tcx>>,
150pub query_vtables: QueryVTables<'tcx>,
151152/// Side-effect associated with each [`DepKind::SideEffect`] node in the
153 /// current incremental-compilation session. Side effects will be written
154 /// to disk, and loaded by [`OnDiskCache`] in the next session.
155 ///
156 /// Always empty if incremental compilation is off.
157pub side_effects: Lock<FxIndexMap<DepNodeIndex, QuerySideEffect>>,
158159/// This provides access to the incremental compilation on-disk cache for query results.
160 /// Do not access this directly. It is only meant to be used by
161 /// `DepGraph::try_mark_green()` and the query infrastructure.
162 /// This is `None` if we are not incremental compilation mode
163pub on_disk_cache: Option<OnDiskCache>,
164165pub local_providers: Providers,
166pub extern_providers: ExternProviders,
167168pub jobs: AtomicU64,
169170pub cycle_handler_nesting: Lock<u8>,
171}
172173#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TyCtxtAt<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for TyCtxtAt<'tcx> {
#[inline]
fn clone(&self) -> TyCtxtAt<'tcx> {
let _: ::core::clone::AssertParamIsClone<TyCtxt<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Span>;
*self
}
}Clone)]
174pub struct TyCtxtAt<'tcx> {
175pub tcx: TyCtxt<'tcx>,
176pub span: Span,
177}
178179impl<'tcx> Dereffor TyCtxtAt<'tcx> {
180type Target = TyCtxt<'tcx>;
181#[inline(always)]
182fn deref(&self) -> &Self::Target {
183&self.tcx
184 }
185}
186187#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TyCtxtEnsureOk<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for TyCtxtEnsureOk<'tcx> {
#[inline]
fn clone(&self) -> TyCtxtEnsureOk<'tcx> {
let _: ::core::clone::AssertParamIsClone<TyCtxt<'tcx>>;
*self
}
}Clone)]
188#[must_use]
189pub struct TyCtxtEnsureOk<'tcx> {
190pub tcx: TyCtxt<'tcx>,
191}
192193#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TyCtxtEnsureResult<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for TyCtxtEnsureResult<'tcx> {
#[inline]
fn clone(&self) -> TyCtxtEnsureResult<'tcx> {
let _: ::core::clone::AssertParamIsClone<TyCtxt<'tcx>>;
*self
}
}Clone)]
194#[must_use]
195pub struct TyCtxtEnsureResult<'tcx> {
196pub tcx: TyCtxt<'tcx>,
197}
198199#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for TyCtxtEnsureDone<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for TyCtxtEnsureDone<'tcx> {
#[inline]
fn clone(&self) -> TyCtxtEnsureDone<'tcx> {
let _: ::core::clone::AssertParamIsClone<TyCtxt<'tcx>>;
*self
}
}Clone)]
200#[must_use]
201pub struct TyCtxtEnsureDone<'tcx> {
202pub tcx: TyCtxt<'tcx>,
203}
204205impl<'tcx> TyCtxtEnsureOk<'tcx> {
206pub fn typeck(self, def_id: impl IntoQueryKey<LocalDefId>) {
207self.typeck_root(
208self.tcx.typeck_root_def_id(def_id.into_query_key().to_def_id()).expect_local(),
209 )
210 }
211}
212213impl<'tcx> TyCtxt<'tcx> {
214pub fn typeck(self, def_id: impl IntoQueryKey<LocalDefId>) -> &'tcx ty::TypeckResults<'tcx> {
215self.typeck_root(
216self.typeck_root_def_id(def_id.into_query_key().to_def_id()).expect_local(),
217 )
218 }
219220/// Returns a transparent wrapper for `TyCtxt` which uses
221 /// `span` as the location of queries performed through it.
222#[inline(always)]
223pub fn at(self, span: Span) -> TyCtxtAt<'tcx> {
224TyCtxtAt { tcx: self, span }
225 }
226227/// FIXME: `ensure_ok`'s effects are subtle. Is this comment fully accurate?
228 ///
229 /// Wrapper that calls queries in a special "ensure OK" mode, for callers
230 /// that don't need the return value and just want to invoke a query for
231 /// its potential side-effect of emitting fatal errors.
232 ///
233 /// This can be more efficient than a normal query call, because if the
234 /// query's inputs are all green, the call can return immediately without
235 /// needing to obtain a value (by decoding one from disk or by executing
236 /// the query).
237 ///
238 /// (As with all query calls, execution is also skipped if the query result
239 /// is already cached in memory.)
240 ///
241 /// ## WARNING
242 /// A subsequent normal call to the same query might still cause it to be
243 /// executed! This can occur when the inputs are all green, but the query's
244 /// result is not cached on disk, so the query must be executed to obtain a
245 /// return value.
246 ///
247 /// Therefore, this call mode is not appropriate for callers that want to
248 /// ensure that the query is _never_ executed in the future.
249#[inline(always)]
250pub fn ensure_ok(self) -> TyCtxtEnsureOk<'tcx> {
251TyCtxtEnsureOk { tcx: self }
252 }
253254/// This is a variant of `ensure_ok` only usable with queries that return
255 /// `Result<_, ErrorGuaranteed>`. Queries calls through this function will
256 /// return `Result<(), ErrorGuaranteed>`. I.e. the error status is returned
257 /// but nothing else. As with `ensure_ok`, this can be more efficient than
258 /// a normal query call.
259#[inline(always)]
260pub fn ensure_result(self) -> TyCtxtEnsureResult<'tcx> {
261TyCtxtEnsureResult { tcx: self }
262 }
263264/// Wrapper that calls queries in a special "ensure done" mode, for callers
265 /// that don't need the return value and just want to guarantee that the
266 /// query won't be executed in the future, by executing it now if necessary.
267 ///
268 /// This is useful for queries that read from a [`Steal`] value, to ensure
269 /// that they are executed before the query that will steal the value.
270 ///
271 /// Unlike [`Self::ensure_ok`], a query with all-green inputs will only be
272 /// skipped if its return value is stored in the disk-cache. This is still
273 /// more efficient than a regular query, because in that situation the
274 /// return value doesn't necessarily need to be decoded.
275 ///
276 /// (As with all query calls, execution is also skipped if the query result
277 /// is already cached in memory.)
278 ///
279 /// [`Steal`]: rustc_data_structures::steal::Steal
280#[inline(always)]
281pub fn ensure_done(self) -> TyCtxtEnsureDone<'tcx> {
282TyCtxtEnsureDone { tcx: self }
283 }
284}
285286macro_rules!maybe_into_query_key {
287 (DefId) => { impl $crate::query::IntoQueryKey<DefId> };
288 (LocalDefId) => { impl $crate::query::IntoQueryKey<LocalDefId> };
289 ($K:ty) => { $K };
290}
291292macro_rules!define_callbacks {
293 (
294// You might expect the key to be `$K:ty`, but it needs to be `$($K:tt)*` so that
295 // `maybe_into_query_key!` can match on specific type names.
296queries {
297 $(
298 $(#[$attr:meta])*
299fn $name:ident($($K:tt)*) -> $V:ty
300 {
301// Search for (QMODLIST) to find all occurrences of this query modifier list.
302arena_cache: $arena_cache:literal,
303 cache_on_disk: $cache_on_disk:literal,
304 depth_limit: $depth_limit:literal,
305 desc: $desc:expr,
306 eval_always: $eval_always:literal,
307 feedable: $feedable:literal,
308 handle_cycle_error: $handle_cycle_error:literal,
309 no_force: $no_force:literal,
310 no_hash: $no_hash:literal,
311 returns_error_guaranteed: $returns_error_guaranteed:literal,
312 separate_provide_extern: $separate_provide_extern:literal,
313 }
314 )*
315 }
316// Non-queries are unused here.
317non_queries { $($_:tt)* }
318 ) => {
319 $(
320pub mod $name {
321use super::*;
322use $crate::query::erase::{self, Erased};
323324pub type Key<'tcx> = $($K)*;
325pub type Value<'tcx> = $V;
326327/// Key type used by provider functions in `local_providers`.
328 /// This query has the `separate_provide_extern` modifier.
329#[cfg($separate_provide_extern)]
330pub type LocalKey<'tcx> =
331 <Key<'tcx> as $crate::query::AsLocalQueryKey>::LocalQueryKey;
332/// Key type used by provider functions in `local_providers`.
333#[cfg(not($separate_provide_extern))]
334pub type LocalKey<'tcx> = Key<'tcx>;
335336/// Type returned from query providers and loaded from disk-cache.
337#[cfg($arena_cache)]
338pub type ProvidedValue<'tcx> =
339 <Value<'tcx> as $crate::query::arena_cached::ArenaCached<'tcx>>::Provided;
340/// Type returned from query providers and loaded from disk-cache.
341#[cfg(not($arena_cache))]
342pub type ProvidedValue<'tcx> = Value<'tcx>;
343344pub type Cache<'tcx> =
345 <Key<'tcx> as $crate::query::QueryKey>::Cache<Erased<Value<'tcx>>>;
346347/// This helper function takes a value returned by the query provider
348 /// (or loaded from disk, or supplied by query feeding), allocates
349 /// it in an arena if requested by the `arena_cache` modifier, and
350 /// then returns an erased copy of it.
351#[inline(always)]
352pub fn provided_to_erased<'tcx>(
353 tcx: TyCtxt<'tcx>,
354 provided_value: ProvidedValue<'tcx>,
355 ) -> Erased<Value<'tcx>> {
356// For queries with the `arena_cache` modifier, store the
357 // provided value in an arena and get a reference to it.
358#[cfg($arena_cache)]
359let value: Value<'tcx> = {
360use $crate::query::arena_cached::ArenaCached;
361 <Value<'tcx> as ArenaCached>::alloc_in_arena(
362 tcx,
363&tcx.query_system.arenas.$name,
364 provided_value,
365 )
366 };
367368// Otherwise, the provided value is the value (and `tcx` is unused).
369#[cfg(not($arena_cache))]
370let value: Value<'tcx> = {
371let _ = tcx;
372 provided_value
373 };
374375 erase::erase_val(value)
376 }
377378// Ensure that keys grow no larger than 88 bytes by accident.
379 // Increase this limit if necessary, but do try to keep the size low if possible
380#[cfg(target_pointer_width = "64")]
381const _: () = {
382if size_of::<Key<'static>>() > 88 {
383panic!("{}", concat!(
384"the query `",
385stringify!($name),
386"` has a key type `",
387stringify!($($K)*),
388"` that is too large"
389));
390 }
391 };
392393// Ensure that values grow no larger than 64 bytes by accident.
394 // Increase this limit if necessary, but do try to keep the size low if possible
395#[cfg(target_pointer_width = "64")]
396 #[cfg(not(feature = "rustc_randomized_layouts"))]
397const _: () = {
398if size_of::<Value<'static>>() > 64 {
399panic!("{}", concat!(
400"the query `",
401stringify!($name),
402"` has a value type `",
403stringify!($V),
404"` that is too large"
405));
406 }
407 };
408 }
409 )*
410411/// Identifies a query by kind and key. This is in contrast to `QueryJobId` which is just a
412 /// number.
413#[allow(non_camel_case_types)]
414 #[derive(Clone, Copy, Debug)]
415pub enum TaggedQueryKey<'tcx> {
416 $(
417$name($name::Key<'tcx>),
418 )*
419 }
420421impl<'tcx> TaggedQueryKey<'tcx> {
422/// Returns the name of the query this key is tagged with.
423 ///
424 /// This is useful for error/debug output, but don't use it to check for
425 /// specific query names. Instead, match on the `TaggedQueryKey` variant.
426pub fn query_name(&self) -> &'static str {
427match self {
428 $(
429 TaggedQueryKey::$name(_) => stringify!($name),
430 )*
431 }
432 }
433434/// Formats a human-readable description of this query and its key, as
435 /// specified by the `desc` query modifier.
436 ///
437 /// Used when reporting query cycle errors and similar problems.
438pub fn description(&self, tcx: TyCtxt<'tcx>) -> String {
439let (name, description) = ty::print::with_no_queries!(match self {
440 $(
441 TaggedQueryKey::$name(key) => (stringify!($name), ($desc)(tcx, *key)),
442 )*
443 });
444if tcx.sess.verbose_internals() {
445format!("{description} [{name:?}]")
446 } else {
447 description
448 }
449 }
450451/// Calls `self.description` or returns a fallback if there was a fatal error
452pub fn catch_description(&self, tcx: TyCtxt<'tcx>) -> String {
453 catch_fatal_errors(|| self.description(tcx)).unwrap_or_else(|_| format!("<error describing {}>", self.query_name()))
454 }
455456/// Returns the default span for this query if `span` is a dummy span.
457pub fn default_span(&self, tcx: TyCtxt<'tcx>, span: Span) -> Span {
458if !span.is_dummy() {
459return span
460 }
461if let TaggedQueryKey::def_span(..) = self {
462// The `def_span` query is used to calculate `default_span`,
463 // so exit to avoid infinite recursion.
464return DUMMY_SP
465 }
466match self {
467 $(
468 TaggedQueryKey::$name(key) =>
469$crate::query::QueryKey::default_span(key, tcx),
470 )*
471 }
472 }
473474/// Calls `self.default_span` or returns `DUMMY_SP` if there was a fatal error
475pub fn catch_default_span(&self, tcx: TyCtxt<'tcx>, span: Span) -> Span {
476 catch_fatal_errors(|| self.default_span(tcx, span)).unwrap_or(DUMMY_SP)
477 }
478 }
479480/// Holds a `QueryVTable` for each query.
481pub struct QueryVTables<'tcx> {
482 $(
483pub $name: $crate::query::QueryVTable<'tcx, $name::Cache<'tcx>>,
484 )*
485 }
486487/// Holds per-query arenas for queries with the `arena_cache` modifier.
488#[derive(Default)]
489pub struct QueryArenas<'tcx> {
490 $(
491// Use the `ArenaCached` helper trait to determine the arena's value type.
492#[cfg($arena_cache)]
493pub $name: TypedArena<
494 <$V as $crate::query::arena_cached::ArenaCached<'tcx>>::Allocated,
495 >,
496 )*
497 }
498499pub struct Providers {
500 $(
501/// This is the provider for the query. Use `Find references` on this to
502 /// navigate between the provider assignment and the query definition.
503pub $name: for<'tcx> fn(
504TyCtxt<'tcx>,
505$name::LocalKey<'tcx>,
506 ) -> $name::ProvidedValue<'tcx>,
507 )*
508 }
509510pub struct ExternProviders {
511 $(
512#[cfg($separate_provide_extern)]
513pub $name: for<'tcx> fn(
514TyCtxt<'tcx>,
515$name::Key<'tcx>,
516 ) -> $name::ProvidedValue<'tcx>,
517 )*
518 }
519520impl Default for Providers {
521fn default() -> Self {
522 Providers {
523 $(
524$name: |_, key| {
525$crate::query::plumbing::default_query(stringify!($name), &key)
526 },
527 )*
528 }
529 }
530 }
531532impl Default for ExternProviders {
533fn default() -> Self {
534 ExternProviders {
535 $(
536#[cfg($separate_provide_extern)]
537$name: |_, key| $crate::query::plumbing::default_extern_query(
538stringify!($name),
539&key,
540 ),
541 )*
542 }
543 }
544 }
545546impl Copy for Providers {}
547impl Clone for Providers {
548fn clone(&self) -> Self { *self }
549 }
550551impl Copy for ExternProviders {}
552impl Clone for ExternProviders {
553fn clone(&self) -> Self { *self }
554 }
555556impl<'tcx> TyCtxt<'tcx> {
557 $(
558 $(#[$attr])*
559#[inline(always)]
560 #[must_use]
561pub fn $name(self, key: maybe_into_query_key!($($K)*)) -> $V {
562self.at(DUMMY_SP).$name(key)
563 }
564 )*
565 }
566567impl<'tcx> $crate::query::TyCtxtAt<'tcx> {
568 $(
569 $(#[$attr])*
570#[inline(always)]
571pub fn $name(self, key: maybe_into_query_key!($($K)*)) -> $V {
572use $crate::query::{erase, inner};
573574 erase::restore_val::<$V>(inner::query_get_at(
575self.tcx,
576self.span,
577&self.tcx.query_system.query_vtables.$name,
578$crate::query::IntoQueryKey::into_query_key(key),
579 ))
580 }
581 )*
582 }
583584impl<'tcx> $crate::query::TyCtxtEnsureOk<'tcx> {
585 $(
586 $(#[$attr])*
587#[inline(always)]
588pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
589$crate::query::inner::query_ensure_ok_or_done(
590self.tcx,
591&self.tcx.query_system.query_vtables.$name,
592$crate::query::IntoQueryKey::into_query_key(key),
593$crate::query::EnsureMode::Ok,
594 )
595 }
596 )*
597 }
598599// Only defined when the `returns_error_guaranteed` modifier is present.
600impl<'tcx> $crate::query::TyCtxtEnsureResult<'tcx> {
601 $(
602#[cfg($returns_error_guaranteed)]
603$(#[$attr])*
604#[inline(always)]
605pub fn $name(
606self,
607 key: maybe_into_query_key!($($K)*),
608 ) -> Result<(), rustc_errors::ErrorGuaranteed> {
609$crate::query::inner::query_ensure_result(
610self.tcx,
611&self.tcx.query_system.query_vtables.$name,
612$crate::query::IntoQueryKey::into_query_key(key),
613 )
614 }
615 )*
616 }
617618impl<'tcx> $crate::query::TyCtxtEnsureDone<'tcx> {
619 $(
620 $(#[$attr])*
621#[inline(always)]
622pub fn $name(self, key: maybe_into_query_key!($($K)*)) {
623$crate::query::inner::query_ensure_ok_or_done(
624self.tcx,
625&self.tcx.query_system.query_vtables.$name,
626$crate::query::IntoQueryKey::into_query_key(key),
627$crate::query::EnsureMode::Done,
628 );
629 }
630 )*
631 }
632633 $(
634// Only defined when the `feedable` modifier is present.
635#[cfg($feedable)]
636impl<'tcx, K: $crate::query::IntoQueryKey<$name::Key<'tcx>> + Copy>
637TyCtxtFeed<'tcx, K>
638 {
639 $(#[$attr])*
640#[inline(always)]
641pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
642$crate::query::inner::query_feed(
643self.tcx,
644&self.tcx.query_system.query_vtables.$name,
645self.key().into_query_key(),
646$name::provided_to_erased(self.tcx, value),
647 );
648 }
649 }
650 )*
651 };
652}
653654// Re-export `macro_rules!` macros as normal items, so that they can be imported normally.
655pub(crate) use define_callbacks;
656pub(crate) use maybe_into_query_key;
657658#[cold]
659pub(crate) fn default_query(name: &str, key: &dyn std::fmt::Debug) -> ! {
660crate::util::bug::bug_fmt(format_args!("`tcx.{0}({1:?})` is not supported for this key;\nhint: Queries can be either made to the local crate, or the external crate. This error means you tried to use it for one that\'s not supported.\nIf that\'s not the case, {0} was likely never assigned to a provider function.\n",
name, key))bug!(
661"`tcx.{name}({key:?})` is not supported for this key;\n\
662 hint: Queries can be either made to the local crate, or the external crate. \
663 This error means you tried to use it for one that's not supported.\n\
664 If that's not the case, {name} was likely never assigned to a provider function.\n",
665 )666}
667668#[cold]
669pub(crate) fn default_extern_query(name: &str, key: &dyn std::fmt::Debug) -> ! {
670crate::util::bug::bug_fmt(format_args!("`tcx.{0}({1:?})` unsupported by its crate; perhaps the `{0}` query was never assigned a provider function",
name, key))bug!(
671"`tcx.{name}({key:?})` unsupported by its crate; \
672 perhaps the `{name}` query was never assigned a provider function",
673 )674}