diff options
| author | b-naber <bn263@gmx.de> | 2022-04-21 16:37:24 +0200 |
|---|---|---|
| committer | b-naber <bn263@gmx.de> | 2022-04-21 16:37:24 +0200 |
| commit | 28af967bb9165999294250dc3f3a56c2193c35d9 (patch) | |
| tree | 4bcf75ebc87cacb01617a41da466405ab771e8b7 | |
| parent | 1157dc7167d13a9bdcafd30b8ad0ecf5ae5faa7f (diff) | |
| download | rust-28af967bb9165999294250dc3f3a56c2193c35d9.tar.gz rust-28af967bb9165999294250dc3f3a56c2193c35d9.zip | |
implement (as of now still unused) query for valtree -> constvalue conversion
| -rw-r--r-- | compiler/rustc_const_eval/src/lib.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/keys.rs | 11 |
3 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index d688331ae0a..34a00452519 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -35,6 +35,7 @@ pub mod transform; pub mod util; use rustc_middle::ty::query::Providers; +use rustc_middle::ty::ParamEnv; pub fn provide(providers: &mut Providers) { const_eval::provide(providers); @@ -49,6 +50,9 @@ pub fn provide(providers: &mut Providers) { let (param_env, raw) = param_env_and_value.into_parts(); const_eval::const_to_valtree(tcx, param_env, raw) }; + providers.valtree_to_const_val = |tcx, (ty, valtree)| { + const_eval::valtree_to_const_value(tcx, ParamEnv::empty().and(ty), valtree) + }; providers.deref_const = |tcx, param_env_and_value| { let (param_env, value) = param_env_and_value.into_parts(); const_eval::deref_const(tcx, param_env, value) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 78a33832433..2834db26131 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -936,6 +936,11 @@ rustc_queries! { remap_env_constness } + /// Converts a type level constant value into `ConstValue` + query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> { + desc { "convert type-level constant value to mir constant value"} + } + /// Destructure a constant ADT or array into its variant index and its /// field values or return `None` if constant is invalid. /// diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index f1f83a7299c..3f0f856b5dd 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -502,3 +502,14 @@ impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) { self.0.default_span(tcx) } } + +impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) { + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true + } + + fn default_span(&self, _: TyCtxt<'_>) -> Span { + DUMMY_SP + } +} |
