1
Fork 0

Address review comment

This commit is contained in:
marmeladema 2020-09-23 23:38:38 +01:00
parent 601c284e1e
commit 35bad3edbf
6 changed files with 31 additions and 20 deletions

View file

@ -8,7 +8,6 @@ use crate::llvm;
use crate::llvm::debuginfo::DIScope; use crate::llvm::debuginfo::DIScope;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::definitions::DefPathData; use rustc_hir::definitions::DefPathData;
use rustc_span::symbol::Symbol;
pub fn mangled_name_of_instance<'a, 'tcx>( pub fn mangled_name_of_instance<'a, 'tcx>(
cx: &CodegenCx<'a, 'tcx>, cx: &CodegenCx<'a, 'tcx>,
@ -28,11 +27,18 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
.parent .parent
.map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent })); .map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent }));
let crate_name_as_str;
let name_to_string;
let namespace_name = match def_key.disambiguated_data.data { let namespace_name = match def_key.disambiguated_data.data {
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate), DefPathData::CrateRoot => {
data => Symbol::intern(&data.to_string()), crate_name_as_str = cx.tcx.crate_name(def_id.krate).as_str();
&*crate_name_as_str
}
data => {
name_to_string = data.to_string();
&*name_to_string
}
}; };
let namespace_name = namespace_name.as_str();
let scope = unsafe { let scope = unsafe {
llvm::LLVMRustDIBuilderCreateNameSpace( llvm::LLVMRustDIBuilderCreateNameSpace(

View file

@ -162,10 +162,10 @@ impl DisambiguatedDefPathData {
if Ident::with_dummy_span(name).is_raw_guess() { if Ident::with_dummy_span(name).is_raw_guess() {
writer.write_str("r#")?; writer.write_str("r#")?;
} }
if self.disambiguator == 0 || !verbose { if verbose && self.disambiguator != 0 {
writer.write_str(&name.as_str())
} else {
write!(writer, "{}#{}", name, self.disambiguator) write!(writer, "{}#{}", name, self.disambiguator)
} else {
writer.write_str(&name.as_str())
} }
} }
DefPathDataName::Anon { namespace } => { DefPathDataName::Anon { namespace } => {
@ -224,7 +224,7 @@ impl DefPath {
/// Returns a string representation of the `DefPath` without /// Returns a string representation of the `DefPath` without
/// the crate-prefix. This method is useful if you don't have /// the crate-prefix. This method is useful if you don't have
/// a `TyCtxt` available. /// a `TyCtxt` available.
pub fn to_string_no_crate(&self) -> String { pub fn to_string_no_crate_verbose(&self) -> String {
let mut s = String::with_capacity(self.data.len() * 16); let mut s = String::with_capacity(self.data.len() * 16);
for component in &self.data { for component in &self.data {
@ -466,6 +466,7 @@ impl fmt::Display for DefPathData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.name() { match self.name() {
DefPathDataName::Named(name) => f.write_str(&name.as_str()), DefPathDataName::Named(name) => f.write_str(&name.as_str()),
// FIXME(#70334): this will generate legacy {{closure}}, {{impl}}, etc
DefPathDataName::Anon { namespace } => write!(f, "{{{{{}}}}}", namespace), DefPathDataName::Anon { namespace } => write!(f, "{{{{{}}}}}", namespace),
} }
} }

View file

@ -244,7 +244,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
if hir_id.owner != self.current_dep_node_owner { if hir_id.owner != self.current_dep_node_owner {
let node_str = match self.definitions.opt_hir_id_to_local_def_id(hir_id) { let node_str = match self.definitions.opt_hir_id_to_local_def_id(hir_id) {
Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate(), Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate_verbose(),
None => format!("{:?}", node), None => format!("{:?}", node),
}; };
@ -254,9 +254,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})", current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
self.source_map.span_to_string(span), self.source_map.span_to_string(span),
node_str, node_str,
self.definitions.def_path(self.current_dep_node_owner).to_string_no_crate(), self.definitions
.def_path(self.current_dep_node_owner)
.to_string_no_crate_verbose(),
self.current_dep_node_owner, self.current_dep_node_owner,
self.definitions.def_path(hir_id.owner).to_string_no_crate(), self.definitions.def_path(hir_id.owner).to_string_no_crate_verbose(),
hir_id.owner, hir_id.owner,
) )
} }

View file

@ -1272,7 +1272,7 @@ impl<'tcx> TyCtxt<'tcx> {
// Don't print the whole crate disambiguator. That's just // Don't print the whole crate disambiguator. That's just
// annoying in debug output. // annoying in debug output.
&(crate_disambiguator.to_fingerprint().to_hex())[..4], &(crate_disambiguator.to_fingerprint().to_hex())[..4],
self.def_path(def_id).to_string_no_crate() self.def_path(def_id).to_string_no_crate_verbose()
) )
} }

View file

@ -7,7 +7,6 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX,
use rustc_hir::definitions::DefPathData; use rustc_hir::definitions::DefPathData;
use rustc_query_system::query::QueryCache; use rustc_query_system::query::QueryCache;
use rustc_query_system::query::QueryState; use rustc_query_system::query::QueryState;
use rustc_span::symbol::Symbol;
use std::fmt::Debug; use std::fmt::Debug;
use std::io::Write; use std::io::Write;
@ -56,18 +55,22 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
}; };
let dis_buffer = &mut [0u8; 16]; let dis_buffer = &mut [0u8; 16];
let crate_name;
let other_name;
let name; let name;
let dis; let dis;
let end_index; let end_index;
match def_key.disambiguated_data.data { match def_key.disambiguated_data.data {
DefPathData::CrateRoot => { DefPathData::CrateRoot => {
name = self.tcx.original_crate_name(def_id.krate); crate_name = self.tcx.original_crate_name(def_id.krate).as_str();
name = &*crate_name;
dis = ""; dis = "";
end_index = 3; end_index = 3;
} }
other => { other => {
name = Symbol::intern(&other.to_string()); other_name = other.to_string();
name = other_name.as_str();
if def_key.disambiguated_data.disambiguator == 0 { if def_key.disambiguated_data.disambiguator == 0 {
dis = ""; dis = "";
end_index = 3; end_index = 3;
@ -81,7 +84,6 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
} }
} }
let name = &*name.as_str();
let components = [ let components = [
StringComponent::Ref(parent_string_id), StringComponent::Ref(parent_string_id),
StringComponent::Value("::"), StringComponent::Value("::"),

View file

@ -112,14 +112,14 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
missing_items.push(format!( missing_items.push(format!(
"[local_id: {}, owner: {}]", "[local_id: {}, owner: {}]",
local_id, local_id,
self.hir_map.def_path(owner).to_string_no_crate() self.hir_map.def_path(owner).to_string_no_crate_verbose()
)); ));
} }
self.error(|| { self.error(|| {
format!( format!(
"ItemLocalIds not assigned densely in {}. \ "ItemLocalIds not assigned densely in {}. \
Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}", Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}",
self.hir_map.def_path(owner).to_string_no_crate(), self.hir_map.def_path(owner).to_string_no_crate_verbose(),
max, max,
missing_items, missing_items,
self.hir_ids_seen self.hir_ids_seen
@ -148,8 +148,8 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
format!( format!(
"HirIdValidator: The recorded owner of {} is {} instead of {}", "HirIdValidator: The recorded owner of {} is {} instead of {}",
self.hir_map.node_to_string(hir_id), self.hir_map.node_to_string(hir_id),
self.hir_map.def_path(hir_id.owner).to_string_no_crate(), self.hir_map.def_path(hir_id.owner).to_string_no_crate_verbose(),
self.hir_map.def_path(owner).to_string_no_crate() self.hir_map.def_path(owner).to_string_no_crate_verbose()
) )
}); });
} }