Add tag_for_variant query

This query allows for sharing code between `rustc_const_eval` and
`rustc_transmutability`.

Also moves `DummyMachine` to `rustc_const_eval`.
This commit is contained in:
Jack Wrenn
2024-03-20 17:45:14 +00:00
parent 9023f908cf
commit 2de9010f66
13 changed files with 347 additions and 292 deletions

View File

@@ -234,6 +234,7 @@ trivial! {
Option<rustc_middle::middle::stability::DeprecationEntry>,
Option<rustc_middle::ty::Destructor>,
Option<rustc_middle::ty::ImplTraitInTraitData>,
Option<rustc_middle::ty::ScalarInt>,
Option<rustc_span::def_id::CrateNum>,
Option<rustc_span::def_id::DefId>,
Option<rustc_span::def_id::LocalDefId>,

View File

@@ -13,6 +13,7 @@ use rustc_query_system::query::DefIdCacheSelector;
use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCacheSelector};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi;
/// Placeholder for `CrateNum`'s "local" counterpart
#[derive(Copy, Clone, Debug)]
@@ -502,6 +503,14 @@ impl<'tcx> Key for (DefId, Ty<'tcx>, GenericArgsRef<'tcx>, ty::ParamEnv<'tcx>) {
}
}
impl<'tcx> Key for (Ty<'tcx>, abi::VariantIdx) {
type CacheSelector = DefaultCacheSelector<Self>;
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
DUMMY_SP
}
}
impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) {
type CacheSelector = DefaultCacheSelector<Self>;

View File

@@ -1042,6 +1042,13 @@ rustc_queries! {
}
}
/// Computes the tag (if any) for a given type and variant.
query tag_for_variant(
key: (Ty<'tcx>, abi::VariantIdx)
) -> Option<ty::ScalarInt> {
desc { "computing variant tag for enum" }
}
/// Evaluates a constant and returns the computed allocation.
///
/// **Do not use this** directly, use the `eval_to_const_value` or `eval_to_valtree` instead.