summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/query
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
commitcec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch)
tree47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /compiler/rustc_middle/src/query
parentAdding debian version 1.74.1+dfsg1-1. (diff)
downloadrustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz
rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/query')
-rw-r--r--compiler/rustc_middle/src/query/erase.rs26
-rw-r--r--compiler/rustc_middle/src/query/keys.rs33
-rw-r--r--compiler/rustc_middle/src/query/mod.rs66
-rw-r--r--compiler/rustc_middle/src/query/plumbing.rs58
4 files changed, 101 insertions, 82 deletions
diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 8ba3764bc..cdde6a596 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -2,7 +2,8 @@ use crate::mir;
use crate::query::CyclePlaceholder;
use crate::traits;
use crate::ty::{self, Ty};
-use std::mem::{size_of, transmute_copy, MaybeUninit};
+use std::intrinsics::transmute_unchecked;
+use std::mem::{size_of, MaybeUninit};
#[derive(Copy, Clone)]
pub struct Erased<T: Copy> {
@@ -29,8 +30,15 @@ pub fn erase<T: EraseType>(src: T) -> Erase<T> {
};
Erased::<<T as EraseType>::Result> {
+ // `transmute_unchecked` is needed here because it does not have `transmute`'s size check
+ // (and thus allows to transmute between `T` and `MaybeUninit<T::Result>`) (we do the size
+ // check ourselves in the `const` block above).
+ //
+ // `transmute_copy` is also commonly used for this (and it would work here since
+ // `EraseType: Copy`), but `transmute_unchecked` better explains the intent.
+ //
// SAFETY: It is safe to transmute to MaybeUninit for types with the same sizes.
- data: unsafe { transmute_copy(&src) },
+ data: unsafe { transmute_unchecked::<T, MaybeUninit<T::Result>>(src) },
}
}
@@ -38,22 +46,24 @@ pub fn erase<T: EraseType>(src: T) -> Erase<T> {
#[inline(always)]
pub fn restore<T: EraseType>(value: Erase<T>) -> T {
let value: Erased<<T as EraseType>::Result> = value;
+ // See comment in `erase` for why we use `transmute_unchecked`.
+ //
// SAFETY: Due to the use of impl Trait in `Erase` the only way to safely create an instance
// of `Erase` is to call `erase`, so we know that `value.data` is a valid instance of `T` of
// the right size.
- unsafe { transmute_copy(&value.data) }
+ unsafe { transmute_unchecked::<MaybeUninit<T::Result>, T>(value.data) }
}
impl<T> EraseType for &'_ T {
- type Result = [u8; size_of::<*const ()>()];
+ type Result = [u8; size_of::<&'static ()>()];
}
impl<T> EraseType for &'_ [T] {
- type Result = [u8; size_of::<*const [()]>()];
+ type Result = [u8; size_of::<&'static [()]>()];
}
impl<T> EraseType for &'_ ty::List<T> {
- type Result = [u8; size_of::<*const ()>()];
+ type Result = [u8; size_of::<&'static ty::List<()>>()];
}
impl<I: rustc_index::Idx, T> EraseType for &'_ rustc_index::IndexSlice<I, T> {
@@ -210,7 +220,7 @@ trivial! {
Option<rustc_attr::Stability>,
Option<rustc_data_structures::svh::Svh>,
Option<rustc_hir::def::DefKind>,
- Option<rustc_hir::GeneratorKind>,
+ Option<rustc_hir::CoroutineKind>,
Option<rustc_hir::HirId>,
Option<rustc_middle::middle::stability::DeprecationEntry>,
Option<rustc_middle::ty::Destructor>,
@@ -239,7 +249,7 @@ trivial! {
rustc_hir::def::DefKind,
rustc_hir::Defaultness,
rustc_hir::definitions::DefKey,
- rustc_hir::GeneratorKind,
+ rustc_hir::CoroutineKind,
rustc_hir::HirId,
rustc_hir::IsAsync,
rustc_hir::ItemLocalId,
diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs
index b1f837968..113763450 100644
--- a/compiler/rustc_middle/src/query/keys.rs
+++ b/compiler/rustc_middle/src/query/keys.rs
@@ -12,7 +12,6 @@ use rustc_hir::hir_id::{HirId, OwnerId};
use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCacheSelector};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
-use rustc_target::abi::FieldIdx;
/// Placeholder for `CrateNum`'s "local" counterpart
#[derive(Copy, Clone, Debug)]
@@ -360,30 +359,6 @@ impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::TraitRef<'tcx>) {
}
}
-impl<'tcx> Key for (ty::Const<'tcx>, FieldIdx) {
- type CacheSelector = DefaultCacheSelector<Self>;
-
- fn default_span(&self, _: TyCtxt<'_>) -> Span {
- DUMMY_SP
- }
-}
-
-impl<'tcx> Key for (mir::ConstValue<'tcx>, Ty<'tcx>) {
- type CacheSelector = DefaultCacheSelector<Self>;
-
- fn default_span(&self, _: TyCtxt<'_>) -> Span {
- DUMMY_SP
- }
-}
-
-impl<'tcx> Key for mir::ConstAlloc<'tcx> {
- type CacheSelector = DefaultCacheSelector<Self>;
-
- fn default_span(&self, _: TyCtxt<'_>) -> Span {
- DUMMY_SP
- }
-}
-
impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
type CacheSelector = DefaultCacheSelector<Self>;
@@ -416,14 +391,6 @@ impl<'tcx> Key for GenericArg<'tcx> {
}
}
-impl<'tcx> Key for mir::Const<'tcx> {
- type CacheSelector = DefaultCacheSelector<Self>;
-
- fn default_span(&self, _: TyCtxt<'_>) -> Span {
- DUMMY_SP
- }
-}
-
impl<'tcx> Key for ty::Const<'tcx> {
type CacheSelector = DefaultCacheSelector<Self>;
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 340c5a769..f9ec36836 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -25,7 +25,9 @@ use crate::mir::interpret::{
use crate::mir::interpret::{LitToConstError, LitToConstInput};
use crate::mir::mono::CodegenUnit;
use crate::query::erase::{erase, restore, Erase};
-use crate::query::plumbing::{query_ensure, query_get_at, CyclePlaceholder, DynamicQuery};
+use crate::query::plumbing::{
+ query_ensure, query_ensure_error_guaranteed, query_get_at, CyclePlaceholder, DynamicQuery,
+};
use crate::thir;
use crate::traits::query::{
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
@@ -249,6 +251,7 @@ rustc_queries! {
"computing type of opaque `{path}`",
path = tcx.def_path_str(key),
}
+ cycle_stash
}
query type_alias_is_lazy(key: DefId) -> bool {
@@ -339,7 +342,7 @@ rustc_queries! {
query opaque_types_defined_by(
key: LocalDefId
- ) -> &'tcx [LocalDefId] {
+ ) -> &'tcx ty::List<LocalDefId> {
desc {
|tcx| "computing the opaque types defined by `{}`",
tcx.def_path_str(key.to_def_id())
@@ -541,28 +544,28 @@ rustc_queries! {
}
}
- /// Returns names of captured upvars for closures and generators.
+ /// Returns names of captured upvars for closures and coroutines.
///
/// Here are some examples:
/// - `name__field1__field2` when the upvar is captured by value.
/// - `_ref__name__field` when the upvar is captured by reference.
///
- /// For generators this only contains upvars that are shared by all states.
+ /// For coroutines this only contains upvars that are shared by all states.
query closure_saved_names_of_captured_variables(def_id: DefId) -> &'tcx IndexVec<abi::FieldIdx, Symbol> {
arena_cache
desc { |tcx| "computing debuginfo for closure `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}
- query mir_generator_witnesses(key: DefId) -> &'tcx Option<mir::GeneratorLayout<'tcx>> {
+ query mir_coroutine_witnesses(key: DefId) -> &'tcx Option<mir::CoroutineLayout<'tcx>> {
arena_cache
- desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
+ desc { |tcx| "coroutine witness types for `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
separate_provide_extern
}
- query check_generator_obligations(key: LocalDefId) {
- desc { |tcx| "verify auto trait bounds for generator interior type `{}`", tcx.def_path_str(key) }
+ query check_coroutine_obligations(key: LocalDefId) {
+ desc { |tcx| "verify auto trait bounds for coroutine interior type `{}`", tcx.def_path_str(key) }
}
/// MIR after our optimization passes have run. This is MIR that is ready
@@ -573,22 +576,12 @@ rustc_queries! {
separate_provide_extern
}
- /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
- /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
- query coverageinfo(key: ty::InstanceDef<'tcx>) -> &'tcx mir::CoverageInfo {
- desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
- arena_cache
- }
-
- /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
- /// function was optimized out before codegen, and before being added to the Coverage Map.
- query covered_code_regions(key: DefId) -> &'tcx Vec<&'tcx mir::coverage::CodeRegion> {
- desc {
- |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
- tcx.def_path_str(key)
- }
+ /// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
+ /// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
+ /// have had a chance to potentially remove some of them.
+ query coverage_ids_info(key: ty::InstanceDef<'tcx>) -> &'tcx mir::CoverageIdsInfo {
+ desc { |tcx| "retrieving coverage IDs info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
arena_cache
- cache_on_disk_if { key.is_local() }
}
/// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
@@ -753,9 +746,9 @@ rustc_queries! {
desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
}
- /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
- query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
- desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
+ /// Returns `Some(coroutine_kind)` if the node pointed to by `def_id` is a coroutine.
+ query coroutine_kind(def_id: DefId) -> Option<hir::CoroutineKind> {
+ desc { |tcx| "looking up coroutine kind of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
}
@@ -975,8 +968,9 @@ rustc_queries! {
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
}
- query check_mod_type_wf(key: LocalModDefId) -> () {
+ query check_mod_type_wf(key: LocalModDefId) -> Result<(), ErrorGuaranteed> {
desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
+ ensure_forwards_result_if_red
}
query collect_mod_item_types(key: LocalModDefId) -> () {
@@ -1107,10 +1101,6 @@ rustc_queries! {
desc { "destructuring type level constant"}
}
- query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> mir::ConstValue<'tcx> {
- desc { "getting a &core::panic::Location referring to a span" }
- }
-
// FIXME get rid of this with valtrees
query lit_to_const(
key: LitToConstInput<'tcx>
@@ -1509,8 +1499,9 @@ rustc_queries! {
feedable
}
- query check_well_formed(key: hir::OwnerId) -> () {
+ query check_well_formed(key: hir::OwnerId) -> Result<(), ErrorGuaranteed> {
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key) }
+ ensure_forwards_result_if_red
}
// The `DefId`s of all non-generic functions and statics in the given crate
@@ -1892,12 +1883,6 @@ rustc_queries! {
desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
}
- /// All items participating in code generation together with items inlined into them.
- query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
- eval_always
- desc { "collecting codegened and inlined items" }
- }
-
query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
desc { "getting codegen unit `{sym}`" }
}
@@ -2202,6 +2187,11 @@ rustc_queries! {
query generics_require_sized_self(def_id: DefId) -> bool {
desc { "check whether the item has a `where Self: Sized` bound" }
}
+
+ query cross_crate_inlinable(def_id: DefId) -> bool {
+ desc { "whether the item should be made inlinable across crates" }
+ separate_provide_extern
+ }
}
rustc_query_append! { define_callbacks! }
diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs
index 34e5b02ba..f4a8ada8f 100644
--- a/compiler/rustc_middle/src/query/plumbing.rs
+++ b/compiler/rustc_middle/src/query/plumbing.rs
@@ -173,6 +173,45 @@ pub fn query_ensure<'tcx, Cache>(
}
}
+#[inline]
+pub fn query_ensure_error_guaranteed<'tcx, Cache>(
+ tcx: TyCtxt<'tcx>,
+ execute_query: fn(TyCtxt<'tcx>, Span, Cache::Key, QueryMode) -> Option<Cache::Value>,
+ query_cache: &Cache,
+ key: Cache::Key,
+ check_cache: bool,
+) -> Result<(), ErrorGuaranteed>
+where
+ Cache: QueryCache<Value = super::erase::Erase<Result<(), ErrorGuaranteed>>>,
+{
+ let key = key.into_query_param();
+ if let Some(res) = try_get_cached(tcx, query_cache, &key) {
+ super::erase::restore(res)
+ } else {
+ execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache })
+ .map(super::erase::restore)
+ // Either we actually executed the query, which means we got a full `Result`,
+ // or we can just assume the query succeeded, because it was green in the
+ // incremental cache. If it is green, that means that the previous compilation
+ // that wrote to the incremental cache compiles successfully. That is only
+ // possible if the cache entry was `Ok(())`, so we emit that here, without
+ // actually encoding the `Result` in the cache or loading it from there.
+ .unwrap_or(Ok(()))
+ }
+}
+
+macro_rules! query_ensure {
+ ([]$($args:tt)*) => {
+ query_ensure($($args)*)
+ };
+ ([(ensure_forwards_result_if_red) $($rest:tt)*]$($args:tt)*) => {
+ query_ensure_error_guaranteed($($args)*)
+ };
+ ([$other:tt $($modifiers:tt)*]$($args:tt)*) => {
+ query_ensure!([$($modifiers)*]$($args)*)
+ };
+}
+
macro_rules! query_helper_param_ty {
(DefId) => { impl IntoQueryParam<DefId> };
(LocalDefId) => { impl IntoQueryParam<LocalDefId> };
@@ -220,6 +259,18 @@ macro_rules! separate_provide_extern_decl {
};
}
+macro_rules! ensure_result {
+ ([][$ty:ty]) => {
+ ()
+ };
+ ([(ensure_forwards_result_if_red) $($rest:tt)*][$ty:ty]) => {
+ Result<(), ErrorGuaranteed>
+ };
+ ([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
+ ensure_result!([$($modifiers)*][$($args)*])
+ };
+}
+
macro_rules! separate_provide_extern_default {
([][$name:ident]) => {
()
@@ -343,14 +394,15 @@ macro_rules! define_callbacks {
impl<'tcx> TyCtxtEnsure<'tcx> {
$($(#[$attr])*
#[inline(always)]
- pub fn $name(self, key: query_helper_param_ty!($($K)*)) {
- query_ensure(
+ pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> ensure_result!([$($modifiers)*][$V]) {
+ query_ensure!(
+ [$($modifiers)*]
self.tcx,
self.tcx.query_system.fns.engine.$name,
&self.tcx.query_system.caches.$name,
key.into_query_param(),
false,
- );
+ )
})*
}