Skip to content

Commit 28af967

Browse files
committed
implement (as of now still unused) query for valtree -> constvalue conversion
1 parent 1157dc7 commit 28af967

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

compiler/rustc_const_eval/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub mod transform;
3535
pub mod util;
3636

3737
use rustc_middle::ty::query::Providers;
38+
use rustc_middle::ty::ParamEnv;
3839

3940
pub fn provide(providers: &mut Providers) {
4041
const_eval::provide(providers);
@@ -49,6 +50,9 @@ pub fn provide(providers: &mut Providers) {
4950
let (param_env, raw) = param_env_and_value.into_parts();
5051
const_eval::const_to_valtree(tcx, param_env, raw)
5152
};
53+
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
54+
const_eval::valtree_to_const_value(tcx, ParamEnv::empty().and(ty), valtree)
55+
};
5256
providers.deref_const = |tcx, param_env_and_value| {
5357
let (param_env, value) = param_env_and_value.into_parts();
5458
const_eval::deref_const(tcx, param_env, value)

compiler/rustc_middle/src/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,11 @@ rustc_queries! {
936936
remap_env_constness
937937
}
938938

939+
/// Converts a type level constant value into `ConstValue`
940+
query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
941+
desc { "convert type-level constant value to mir constant value"}
942+
}
943+
939944
/// Destructure a constant ADT or array into its variant index and its
940945
/// field values or return `None` if constant is invalid.
941946
///

compiler/rustc_query_impl/src/keys.rs

+11
Original file line numberDiff line numberDiff line change
@@ -502,3 +502,14 @@ impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) {
502502
self.0.default_span(tcx)
503503
}
504504
}
505+
506+
impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) {
507+
#[inline(always)]
508+
fn query_crate_is_local(&self) -> bool {
509+
true
510+
}
511+
512+
fn default_span(&self, _: TyCtxt<'_>) -> Span {
513+
DUMMY_SP
514+
}
515+
}

0 commit comments

Comments
 (0)