From 0f822d775f046df87713edf8ffb4e308fc77b3ef Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Sun, 2 Jun 2019 23:20:36 -0500 Subject: [PATCH] query-fy type_name --- Cargo.lock | 1 - src/librustc/query/mod.rs | 9 +++++++++ src/librustc_codegen_llvm/intrinsic.rs | 2 +- src/librustc_mir/interpret/mod.rs | 2 +- src/librustc_mir/lib.rs | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9c4d6b3bad64..d7191743c36f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2684,7 +2684,6 @@ dependencies = [ "rustc_errors 0.0.0", "rustc_fs_util 0.0.0", "rustc_incremental 0.0.0", - "rustc_mir 0.0.0", "rustc_target 0.0.0", "serialize 0.0.0", "syntax 0.0.0", diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 00856041edf46..10efef54526a6 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -441,6 +441,15 @@ rustc_queries! { no_force desc { "extract field of const" } } + + /// Produces an absolute path representation of the given type. See also the documentation + /// on `std::any::type_name`. + query type_name(key: Ty<'tcx>) -> &'tcx ty::Const<'tcx> { + eval_always + no_force + desc { "get absolute path of type" } + } + } TypeChecking { diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 060c295eb7af1..98a829b2affec 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -212,7 +212,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { } "type_name" => { let tp_ty = substs.type_at(0); - let ty_name = rustc_mir::interpret::type_name(self.tcx, tp_ty); + let ty_name = self.tcx.type_name(tp_ty); OperandRef::from_const(self, ty_name).immediate_or_packed_pair(self) } "type_id" => { diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs index ed389a8df94ab..d59bee6943a51 100644 --- a/src/librustc_mir/interpret/mod.rs +++ b/src/librustc_mir/interpret/mod.rs @@ -33,4 +33,4 @@ pub use self::visitor::{ValueVisitor, MutValueVisitor}; pub use self::validity::RefTracking; -pub use self::intrinsics::type_name; +pub(super) use self::intrinsics::type_name; diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 46bda28c13c5c..9213a009ea740 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -67,6 +67,7 @@ pub fn provide(providers: &mut Providers<'_>) { let (param_env, (value, field)) = param_env_and_value.into_parts(); const_eval::const_field(tcx, param_env, None, field, value) }; + providers.type_name = interpret::type_name; } __build_diagnostic_array! { librustc_mir, DIAGNOSTICS }