Skip to content

Allow recovering symbol_name query when there are no substs #92503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,11 @@ rustc_queries! {
cache_on_disk_if { true }
}

/// DO NOT call this directly - always use `symbol_name`
query symbol_name_for_plain_item(def_id: DefId) -> ty::SymbolName<'tcx> {
desc { "computing the symbol name for plain item `{}`", tcx.def_path_str(def_id) }
}

query opt_def_kind(def_id: DefId) -> Option<DefKind> {
desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
separate_provide_extern
Expand Down
42 changes: 38 additions & 4 deletions compiler/rustc_symbol_mangling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ use rustc_hir::Node;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::{self, Instance, InstanceDef, Ty, TyCtxt, WithOptConstParam};
use rustc_session::config::SymbolManglingVersion;
use rustc_span::def_id::DefId;
use rustc_target::abi::call::FnAbi;

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

pub fn provide(providers: &mut Providers) {
*providers = Providers { symbol_name: symbol_name_provider, ..*providers };
*providers = Providers {
symbol_name: symbol_name_provider,
symbol_name_for_plain_item: symbol_name_for_plain_item_provider,
..*providers
};
}

fn symbol_name_for_plain_item_provider<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
) -> ty::SymbolName<'tcx> {
symbol_name_provider_body(
tcx,
Instance {
def: InstanceDef::Item(WithOptConstParam::unknown(def_id)),
substs: InternalSubsts::empty(),
},
)
}

fn symbol_name_provider<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName<'tcx> {
if let Instance {
def: InstanceDef::Item(WithOptConstParam { did: def_id, const_param_did: None }),
substs,
} = instance
{
if substs.is_empty() {
return tcx.symbol_name_for_plain_item(def_id);
}
}
symbol_name_provider_body(tcx, instance)
}

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