Skip to content

Commit 86d3b47

Browse files
committed
Allow recovering symbol_name query when there are no substs
This is accomplished by creating a new `symbol_name_for_plain_item` query, which is automatically called when `symbol_name` is invoked with a supported key. The `symbol_name_for_plain_item` query just uses a `DefId` as its argument, so it can be recovered.
1 parent 8f3238f commit 86d3b47

File tree

2 files changed

+43
-4
lines changed
  • compiler

2 files changed

+43
-4
lines changed

compiler/rustc_middle/src/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,11 @@ rustc_queries! {
965965
cache_on_disk_if { true }
966966
}
967967

968+
/// DO NOT call this directly - always use `symbol_name`
969+
query symbol_name_for_plain_item(def_id: DefId) -> ty::SymbolName<'tcx> {
970+
desc { "computing the symbol name for plain item `{}`", tcx.def_path_str(def_id) }
971+
}
972+
968973
query opt_def_kind(def_id: DefId) -> Option<DefKind> {
969974
desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
970975
separate_provide_extern

compiler/rustc_symbol_mangling/src/lib.rs

+38-4
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ use rustc_hir::Node;
100100
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
101101
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
102102
use rustc_middle::ty::query::Providers;
103-
use rustc_middle::ty::subst::SubstsRef;
104-
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
103+
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
104+
use rustc_middle::ty::{self, Instance, InstanceDef, Ty, TyCtxt, WithOptConstParam};
105105
use rustc_session::config::SymbolManglingVersion;
106+
use rustc_span::def_id::DefId;
106107
use rustc_target::abi::call::FnAbi;
107108

108109
use tracing::debug;
@@ -124,13 +125,46 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
124125
}
125126

126127
pub fn provide(providers: &mut Providers) {
127-
*providers = Providers { symbol_name: symbol_name_provider, ..*providers };
128+
*providers = Providers {
129+
symbol_name: symbol_name_provider,
130+
symbol_name_for_plain_item: symbol_name_for_plain_item_provider,
131+
..*providers
132+
};
133+
}
134+
135+
fn symbol_name_for_plain_item_provider<'tcx>(
136+
tcx: TyCtxt<'tcx>,
137+
def_id: DefId,
138+
) -> ty::SymbolName<'tcx> {
139+
symbol_name_provider_body(
140+
tcx,
141+
Instance {
142+
def: InstanceDef::Item(WithOptConstParam::unknown(def_id)),
143+
substs: InternalSubsts::empty(),
144+
},
145+
)
146+
}
147+
148+
fn symbol_name_provider<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName<'tcx> {
149+
if let Instance {
150+
def: InstanceDef::Item(WithOptConstParam { did: def_id, const_param_did: None }),
151+
substs,
152+
} = instance
153+
{
154+
if substs.is_empty() {
155+
return tcx.symbol_name_for_plain_item(def_id);
156+
}
157+
}
158+
symbol_name_provider_body(tcx, instance)
128159
}
129160

130161
// The `symbol_name` query provides the symbol name for calling a given
131162
// instance from the local crate. In particular, it will also look up the
132163
// correct symbol name of instances from upstream crates.
133-
fn symbol_name_provider<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName<'tcx> {
164+
fn symbol_name_provider_body<'tcx>(
165+
tcx: TyCtxt<'tcx>,
166+
instance: Instance<'tcx>,
167+
) -> ty::SymbolName<'tcx> {
134168
let symbol_name = compute_symbol_name(tcx, instance, || {
135169
// This closure determines the instantiating crate for instances that
136170
// need an instantiating-crate-suffix for their symbol name, in order

0 commit comments

Comments
 (0)