Skip to content

Commit 9e755d9

Browse files
committed
Merge some query impl modules into one
1 parent d3f416d commit 9e755d9

File tree

1 file changed

+125
-143
lines changed

1 file changed

+125
-143
lines changed

compiler/rustc_query_impl/src/plumbing.rs

+125-143
Original file line numberDiff line numberDiff line change
@@ -506,169 +506,151 @@ macro_rules! define_queries {
506506
(
507507
$($(#[$attr:meta])*
508508
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
509-
mod get_query_incr {
510-
use super::*;
511509

512-
$(
510+
pub(crate) mod query_impl { $(pub mod $name {
511+
use super::super::*;
512+
use std::marker::PhantomData;
513+
514+
pub mod get_query_incr {
515+
use super::*;
516+
513517
// Adding `__rust_end_short_backtrace` marker to backtraces so that we emit the frames
514518
// when `RUST_BACKTRACE=1`, add a new mod with `$name` here is to allow duplicate naming
515-
pub mod $name {
516-
use super::*;
517-
#[inline(never)]
518-
pub fn __rust_end_short_backtrace<'tcx>(
519-
tcx: TyCtxt<'tcx>,
520-
span: Span,
521-
key: queries::$name::Key<'tcx>,
522-
mode: QueryMode,
523-
) -> Option<Erase<queries::$name::Value<'tcx>>> {
524-
get_query_incr(
525-
query_config::$name::config(tcx),
526-
QueryCtxt::new(tcx),
527-
span,
528-
key,
529-
mode
519+
#[inline(never)]
520+
pub fn __rust_end_short_backtrace<'tcx>(
521+
tcx: TyCtxt<'tcx>,
522+
span: Span,
523+
key: queries::$name::Key<'tcx>,
524+
mode: QueryMode,
525+
) -> Option<Erase<queries::$name::Value<'tcx>>> {
526+
get_query_incr(
527+
QueryType::config(tcx),
528+
QueryCtxt::new(tcx),
529+
span,
530+
key,
531+
mode
532+
)
533+
}
534+
}
535+
536+
pub mod get_query_non_incr {
537+
use super::*;
538+
539+
#[inline(never)]
540+
pub fn __rust_end_short_backtrace<'tcx>(
541+
tcx: TyCtxt<'tcx>,
542+
span: Span,
543+
key: queries::$name::Key<'tcx>,
544+
__mode: QueryMode,
545+
) -> Option<Erase<queries::$name::Value<'tcx>>> {
546+
Some(get_query_non_incr(
547+
QueryType::config(tcx),
548+
QueryCtxt::new(tcx),
549+
span,
550+
key,
551+
))
552+
}
553+
}
554+
555+
pub fn dynamic_query<'tcx>() -> DynamicQuery<'tcx, queries::$name::Storage<'tcx>> {
556+
DynamicQuery {
557+
name: stringify!($name),
558+
eval_always: is_eval_always!([$($modifiers)*]),
559+
dep_kind: dep_graph::DepKind::$name,
560+
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
561+
query_state: offset_of!(QueryStates<'tcx> => $name),
562+
query_cache: offset_of!(QueryCaches<'tcx> => $name),
563+
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
564+
execute_query: |tcx, key| erase(tcx.$name(key)),
565+
compute: |tcx, key| {
566+
__rust_begin_short_backtrace(||
567+
queries::$name::provided_to_erased(
568+
tcx,
569+
call_provider!([$($modifiers)*][tcx, $name, key])
570+
)
530571
)
531-
}
572+
},
573+
can_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] true false),
574+
try_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] {
575+
|tcx, key, prev_index, index| {
576+
if ::rustc_middle::query::cached::$name(tcx, key) {
577+
let value = $crate::plumbing::try_load_from_disk::<
578+
queries::$name::ProvidedValue<'tcx>
579+
>(
580+
tcx,
581+
prev_index,
582+
index,
583+
);
584+
value.map(|value| queries::$name::provided_to_erased(tcx, value))
585+
} else {
586+
None
587+
}
588+
}
589+
} {
590+
|_tcx, _key, _prev_index, _index| None
591+
}),
592+
value_from_cycle_error: |tcx, cycle| {
593+
let result: queries::$name::Value<'tcx> = Value::from_cycle_error(tcx, cycle);
594+
erase(result)
595+
},
596+
loadable_from_disk: |_tcx, _key, _index| {
597+
should_ever_cache_on_disk!([$($modifiers)*] {
598+
::rustc_middle::query::cached::$name(_tcx, _key) &&
599+
$crate::plumbing::loadable_from_disk(_tcx, _index)
600+
} {
601+
false
602+
})
603+
},
604+
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
605+
format_value: |value| format!("{:?}", restore::<queries::$name::Value<'tcx>>(*value)),
532606
}
533-
)*
534-
}
607+
}
535608

536-
mod get_query_non_incr {
537-
use super::*;
609+
#[derive(Copy, Clone, Default)]
610+
pub struct QueryType<'tcx> {
611+
data: PhantomData<&'tcx ()>
612+
}
538613

539-
$(
540-
pub mod $name {
541-
use super::*;
542-
#[inline(never)]
543-
pub fn __rust_end_short_backtrace<'tcx>(
544-
tcx: TyCtxt<'tcx>,
545-
span: Span,
546-
key: queries::$name::Key<'tcx>,
547-
__mode: QueryMode,
548-
) -> Option<Erase<queries::$name::Value<'tcx>>> {
549-
Some(get_query_non_incr(
550-
query_config::$name::config(tcx),
551-
QueryCtxt::new(tcx),
552-
span,
553-
key,
554-
))
614+
impl<'tcx> QueryConfigRestored<'tcx> for QueryType<'tcx> {
615+
type RestoredValue = queries::$name::Value<'tcx>;
616+
type Config = DynamicConfig<
617+
'tcx,
618+
queries::$name::Storage<'tcx>,
619+
{ is_anon!([$($modifiers)*]) },
620+
{ depth_limit!([$($modifiers)*]) },
621+
{ feedable!([$($modifiers)*]) },
622+
>;
623+
624+
#[inline(always)]
625+
fn config(tcx: TyCtxt<'tcx>) -> Self::Config {
626+
DynamicConfig {
627+
dynamic: &tcx.query_system.dynamic_queries.$name,
555628
}
556629
}
557-
)*
558-
}
630+
631+
#[inline(always)]
632+
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
633+
restore::<queries::$name::Value<'tcx>>(value)
634+
}
635+
}
636+
})*}
559637

560638
pub(crate) fn engine(incremental: bool) -> QueryEngine {
561639
if incremental {
562640
QueryEngine {
563-
$($name: get_query_incr::$name::__rust_end_short_backtrace,)*
641+
$($name: query_impl::$name::get_query_incr::__rust_end_short_backtrace,)*
564642
}
565643
} else {
566644
QueryEngine {
567-
$($name: get_query_non_incr::$name::__rust_end_short_backtrace,)*
645+
$($name: query_impl::$name::get_query_non_incr::__rust_end_short_backtrace,)*
568646
}
569647
}
570648
}
571649

572-
#[allow(nonstandard_style)]
573-
mod query_config {
574-
use std::marker::PhantomData;
575-
576-
$(
577-
#[derive(Copy, Clone, Default)]
578-
pub struct $name<'tcx> {
579-
data: PhantomData<&'tcx ()>
580-
}
581-
)*
582-
}
583-
584-
#[allow(nonstandard_style)]
585-
mod dynamic_query {
586-
use super::*;
587-
588-
$(
589-
pub(super) fn $name<'tcx>() -> DynamicQuery<'tcx, queries::$name::Storage<'tcx>> {
590-
DynamicQuery {
591-
name: stringify!($name),
592-
eval_always: is_eval_always!([$($modifiers)*]),
593-
dep_kind: dep_graph::DepKind::$name,
594-
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
595-
query_state: offset_of!(QueryStates<'tcx> => $name),
596-
query_cache: offset_of!(QueryCaches<'tcx> => $name),
597-
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
598-
execute_query: |tcx, key| erase(tcx.$name(key)),
599-
compute: |tcx, key| {
600-
__rust_begin_short_backtrace(||
601-
queries::$name::provided_to_erased(
602-
tcx,
603-
call_provider!([$($modifiers)*][tcx, $name, key])
604-
)
605-
)
606-
},
607-
can_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] true false),
608-
try_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] {
609-
|tcx, key, prev_index, index| {
610-
if ::rustc_middle::query::cached::$name(tcx, key) {
611-
let value = $crate::plumbing::try_load_from_disk::<
612-
queries::$name::ProvidedValue<'tcx>
613-
>(
614-
tcx,
615-
prev_index,
616-
index,
617-
);
618-
value.map(|value| queries::$name::provided_to_erased(tcx, value))
619-
} else {
620-
None
621-
}
622-
}
623-
} {
624-
|_tcx, _key, _prev_index, _index| None
625-
}),
626-
value_from_cycle_error: |tcx, cycle| {
627-
let result: queries::$name::Value<'tcx> = Value::from_cycle_error(tcx, cycle);
628-
erase(result)
629-
},
630-
loadable_from_disk: |_tcx, _key, _index| {
631-
should_ever_cache_on_disk!([$($modifiers)*] {
632-
::rustc_middle::query::cached::$name(_tcx, _key) &&
633-
$crate::plumbing::loadable_from_disk(_tcx, _index)
634-
} {
635-
false
636-
})
637-
},
638-
hash_result: hash_result!([$($modifiers)*][queries::$name::Value<'tcx>]),
639-
format_value: |value| format!("{:?}", restore::<queries::$name::Value<'tcx>>(*value)),
640-
}
641-
}
642-
)*
643-
}
644-
645-
$(impl<'tcx> QueryConfigRestored<'tcx> for query_config::$name<'tcx> {
646-
type RestoredValue = queries::$name::Value<'tcx>;
647-
type Config = DynamicConfig<
648-
'tcx,
649-
queries::$name::Storage<'tcx>,
650-
{ is_anon!([$($modifiers)*]) },
651-
{ depth_limit!([$($modifiers)*]) },
652-
{ feedable!([$($modifiers)*]) },
653-
>;
654-
655-
#[inline(always)]
656-
fn config(tcx: TyCtxt<'tcx>) -> Self::Config {
657-
DynamicConfig {
658-
dynamic: &tcx.query_system.dynamic_queries.$name,
659-
}
660-
}
661-
662-
#[inline(always)]
663-
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
664-
restore::<queries::$name::Value<'tcx>>(value)
665-
}
666-
})*
667-
668650
pub fn dynamic_queries<'tcx>() -> DynamicQueries<'tcx> {
669651
DynamicQueries {
670652
$(
671-
$name: dynamic_query::$name(),
653+
$name: query_impl::$name::dynamic_query(),
672654
)*
673655
}
674656
}
@@ -731,7 +713,7 @@ macro_rules! define_queries {
731713
}
732714

733715
$(pub(crate) fn $name<'tcx>()-> DepKindStruct<'tcx> {
734-
$crate::plumbing::query_callback::<query_config::$name<'tcx>>(
716+
$crate::plumbing::query_callback::<query_impl::$name::QueryType<'tcx>>(
735717
is_anon!([$($modifiers)*]),
736718
is_eval_always!([$($modifiers)*]),
737719
)
@@ -786,8 +768,8 @@ macro_rules! define_queries {
786768
)
787769
},
788770
encode_query_results: expand_if_cached!([$($modifiers)*], |tcx, encoder, query_result_index|
789-
$crate::plumbing::encode_query_results::<super::query_config::$name<'tcx>>(
790-
super::query_config::$name::config(tcx),
771+
$crate::plumbing::encode_query_results::<query_impl::$name::QueryType<'tcx>>(
772+
query_impl::$name::QueryType::config(tcx),
791773
QueryCtxt::new(tcx),
792774
encoder,
793775
query_result_index,

0 commit comments

Comments
 (0)