summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_symbol_mangling/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_symbol_mangling/src')
-rw-r--r--compiler/rustc_symbol_mangling/src/legacy.rs13
-rw-r--r--compiler/rustc_symbol_mangling/src/lib.rs3
-rw-r--r--compiler/rustc_symbol_mangling/src/test.rs2
-rw-r--r--compiler/rustc_symbol_mangling/src/typeid.rs24
-rw-r--r--compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs43
-rw-r--r--compiler/rustc_symbol_mangling/src/v0.rs10
6 files changed, 54 insertions, 41 deletions
diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs
index c60a2f467..23ff6b333 100644
--- a/compiler/rustc_symbol_mangling/src/legacy.rs
+++ b/compiler/rustc_symbol_mangling/src/legacy.rs
@@ -175,7 +175,7 @@ impl SymbolPath {
fn finish(mut self, hash: u64) -> String {
self.finalize_pending_component();
// E = end name-sequence
- let _ = write!(self.result, "17h{:016x}E", hash);
+ let _ = write!(self.result, "17h{hash:016x}E");
self.result
}
}
@@ -216,8 +216,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
match *ty.kind() {
// Print all nominal types as paths (unlike `pretty_print_type`).
ty::FnDef(def_id, substs)
- | ty::Opaque(def_id, substs)
- | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs })
+ | ty::Alias(_, ty::AliasTy { def_id, substs, .. })
| ty::Closure(def_id, substs)
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
@@ -228,7 +227,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
self = self.print_type(ty)?;
self.write_str("; ")?;
if let Some(size) = size.kind().try_to_bits(self.tcx().data_layout.pointer_size) {
- write!(self, "{}", size)?
+ write!(self, "{size}")?
} else if let ty::ConstKind::Param(param) = size.kind() {
self = param.print(self)?
} else {
@@ -287,11 +286,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
// Similar to `pretty_path_qualified`, but for the other
// types that are printed as paths (see `print_type` above).
match self_ty.kind() {
- ty::FnDef(..)
- | ty::Opaque(..)
- | ty::Projection(_)
- | ty::Closure(..)
- | ty::Generator(..)
+ ty::FnDef(..) | ty::Alias(..) | ty::Closure(..) | ty::Generator(..)
if trait_ref.is_none() =>
{
self.print_type(self_ty)
diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs
index 62f44a480..547a59076 100644
--- a/compiler/rustc_symbol_mangling/src/lib.rs
+++ b/compiler/rustc_symbol_mangling/src/lib.rs
@@ -269,8 +269,7 @@ fn compute_symbol_name<'tcx>(
debug_assert!(
rustc_demangle::try_demangle(&symbol).is_ok(),
- "compute_symbol_name: `{}` cannot be demangled",
- symbol
+ "compute_symbol_name: `{symbol}` cannot be demangled"
);
symbol
diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs
index 150459ce0..c6899f8f2 100644
--- a/compiler/rustc_symbol_mangling/src/test.rs
+++ b/compiler/rustc_symbol_mangling/src/test.rs
@@ -74,7 +74,7 @@ impl SymbolNamesTest<'_> {
tcx.sess.emit_err(TestOutput {
span: attr.span,
kind: Kind::DemanglingAlt,
- content: format!("{:#}", demangling),
+ content: format!("{demangling:#}"),
});
}
}
diff --git a/compiler/rustc_symbol_mangling/src/typeid.rs b/compiler/rustc_symbol_mangling/src/typeid.rs
index 9228bea43..53983bed7 100644
--- a/compiler/rustc_symbol_mangling/src/typeid.rs
+++ b/compiler/rustc_symbol_mangling/src/typeid.rs
@@ -3,6 +3,8 @@
use rustc_middle::ty::{FnSig, Ty, TyCtxt};
use rustc_target::abi::call::FnAbi;
+use std::hash::Hasher;
+use twox_hash::XxHash64;
mod typeid_itanium_cxx_abi;
use typeid_itanium_cxx_abi::TypeIdOptions;
@@ -16,3 +18,25 @@ pub fn typeid_for_fnabi<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>)
pub fn typeid_for_fnsig<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: &FnSig<'tcx>) -> String {
typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, TypeIdOptions::NO_OPTIONS)
}
+
+/// Returns an LLVM KCFI type metadata identifier for the specified FnAbi.
+pub fn kcfi_typeid_for_fnabi<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> u32 {
+ // An LLVM KCFI type metadata identifier is a 32-bit constant produced by taking the lower half
+ // of the xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
+ let mut hash: XxHash64 = Default::default();
+ hash.write(
+ typeid_itanium_cxx_abi::typeid_for_fnabi(tcx, fn_abi, TypeIdOptions::NO_OPTIONS).as_bytes(),
+ );
+ hash.finish() as u32
+}
+
+/// Returns an LLVM KCFI type metadata identifier for the specified FnSig.
+pub fn kcfi_typeid_for_fnsig<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: &FnSig<'tcx>) -> u32 {
+ // An LLVM KCFI type metadata identifier is a 32-bit constant produced by taking the lower half
+ // of the xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
+ let mut hash: XxHash64 = Default::default();
+ hash.write(
+ typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, TypeIdOptions::NO_OPTIONS).as_bytes(),
+ );
+ hash.finish() as u32
+}
diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs
index 87128e0f8..0759b95bd 100644
--- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs
+++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs
@@ -99,13 +99,8 @@ fn is_c_void_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
ty::Adt(adt_def, ..) => {
let def_id = adt_def.0.did;
let crate_name = tcx.crate_name(def_id.krate);
- if tcx.item_name(def_id).as_str() == "c_void"
+ tcx.item_name(def_id).as_str() == "c_void"
&& (crate_name == sym::core || crate_name == sym::std || crate_name == sym::libc)
- {
- true
- } else {
- false
- }
}
_ => false,
}
@@ -131,11 +126,11 @@ fn encode_const<'tcx>(
if value < zero {
s.push('n')
};
- let _ = write!(s, "{}", value);
+ let _ = write!(s, "{value}");
}
fn push_unsigned_value<T: Display>(s: &mut String, value: T) {
- let _ = write!(s, "{}", value);
+ let _ = write!(s, "{value}");
}
if let Some(scalar_int) = c.kind().try_to_scalar_int() {
@@ -169,6 +164,7 @@ fn encode_const<'tcx>(
/// Encodes a FnSig using the Itanium C++ ABI with vendor extended type qualifiers and types for
/// Rust types that are not used at the FFI boundary.
+#[instrument(level = "trace", skip(tcx, dict))]
fn encode_fnsig<'tcx>(
tcx: TyCtxt<'tcx>,
fn_sig: &FnSig<'tcx>,
@@ -240,7 +236,7 @@ fn encode_predicate<'tcx>(
s.push_str(&encode_substs(tcx, trait_ref.substs, dict, options));
}
ty::ExistentialPredicate::Projection(projection) => {
- let name = encode_ty_name(tcx, projection.item_def_id);
+ let name = encode_ty_name(tcx, projection.def_id);
let _ = write!(s, "u{}{}", name.len(), &name);
s.push_str(&encode_substs(tcx, projection.substs, dict, options));
match projection.term.unpack() {
@@ -267,8 +263,7 @@ fn encode_predicates<'tcx>(
) -> String {
// <predicate1[..predicateN]>E as part of vendor extended type
let mut s = String::new();
- let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> =
- predicates.iter().map(|predicate| predicate).collect();
+ let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> = predicates.iter().collect();
for predicate in predicates {
s.push_str(&encode_predicate(tcx, predicate, dict, options));
}
@@ -322,7 +317,7 @@ fn encode_substs<'tcx>(
) -> String {
// [I<subst1..substN>E] as part of vendor extended type
let mut s = String::new();
- let substs: Vec<GenericArg<'_>> = substs.iter().map(|subst| subst).collect();
+ let substs: Vec<GenericArg<'_>> = substs.iter().collect();
if !substs.is_empty() {
s.push('I');
for subst in substs {
@@ -344,7 +339,7 @@ fn encode_substs<'tcx>(
}
/// Encodes a ty:Ty name, including its crate and path disambiguators and names.
-fn encode_ty_name<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> String {
+fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
// Encode <name> for use in u<length><name>[I<element-type1..element-typeN>E], where
// <element-type> is <subst>, using v0's <path> without v0's extended form of paths:
//
@@ -646,10 +641,9 @@ fn encode_ty<'tcx>(
| ty::Error(..)
| ty::GeneratorWitness(..)
| ty::Infer(..)
- | ty::Opaque(..)
+ | ty::Alias(..)
| ty::Param(..)
- | ty::Placeholder(..)
- | ty::Projection(..) => {
+ | ty::Placeholder(..) => {
bug!("encode_ty: unexpected `{:?}`", ty.kind());
}
};
@@ -660,6 +654,7 @@ fn encode_ty<'tcx>(
// Transforms a ty:Ty for being encoded and used in the substitution dictionary. It transforms all
// c_void types into unit types unconditionally, and generalizes all pointers if
// TransformTyOptions::GENERALIZE_POINTERS option is set.
+#[instrument(level = "trace", skip(tcx))]
fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptions) -> Ty<'tcx> {
let mut ty = ty;
@@ -704,11 +699,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.is_zst());
!is_zst
});
- if field.is_none() {
- // Transform repr(transparent) types without non-ZST field into ()
- ty = tcx.mk_unit();
- } else {
- let ty0 = tcx.type_of(field.unwrap().did);
+ if let Some(field) = field {
+ let ty0 = tcx.bound_type_of(field.did).subst(tcx, substs);
// Generalize any repr(transparent) user-defined type that is either a pointer
// or reference, and either references itself or any other type that contains or
// references itself, to avoid a reference cycle.
@@ -721,6 +713,9 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
} else {
ty = transform_ty(tcx, ty0, options);
}
+ } else {
+ // Transform repr(transparent) types without non-ZST field into ()
+ ty = tcx.mk_unit();
}
} else {
ty = tcx.mk_adt(*adt_def, transform_substs(tcx, substs, options));
@@ -799,10 +794,9 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
| ty::Error(..)
| ty::GeneratorWitness(..)
| ty::Infer(..)
- | ty::Opaque(..)
+ | ty::Alias(..)
| ty::Param(..)
- | ty::Placeholder(..)
- | ty::Projection(..) => {
+ | ty::Placeholder(..) => {
bug!("transform_ty: unexpected `{:?}`", ty.kind());
}
}
@@ -835,6 +829,7 @@ fn transform_substs<'tcx>(
/// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor
/// extended type qualifiers and types for Rust types that are not used at the FFI boundary.
+#[instrument(level = "trace", skip(tcx))]
pub fn typeid_for_fnabi<'tcx>(
tcx: TyCtxt<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs
index 2cca480f2..0d446d654 100644
--- a/compiler/rustc_symbol_mangling/src/v0.rs
+++ b/compiler/rustc_symbol_mangling/src/v0.rs
@@ -206,6 +206,7 @@ impl<'tcx> SymbolMangler<'tcx> {
where
T: TypeVisitable<'tcx>,
{
+ // FIXME(non-lifetime-binders): What to do here?
let regions = if value.has_late_bound_regions() {
self.tcx.collect_referenced_late_bound_regions(value)
} else {
@@ -439,8 +440,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// Mangle all nominal types as paths.
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
| ty::FnDef(def_id, substs)
- | ty::Opaque(def_id, substs)
- | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs })
+ | ty::Alias(_, ty::AliasTy { def_id, substs, .. })
| ty::Closure(def_id, substs)
| ty::Generator(def_id, substs, _) => {
self = self.print_def_path(def_id, substs)?;
@@ -544,7 +544,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
cx = cx.print_def_path(trait_ref.def_id, trait_ref.substs)?;
}
ty::ExistentialPredicate::Projection(projection) => {
- let name = cx.tcx.associated_item(projection.item_def_id).name;
+ let name = cx.tcx.associated_item(projection.def_id).name;
cx.push("p");
cx.push_ident(name.as_str());
cx = match projection.term.unpack() {
@@ -610,7 +610,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
bits = val.unsigned_abs();
}
- let _ = write!(self.out, "{:x}_", bits);
+ let _ = write!(self.out, "{bits:x}_");
}
// FIXME(valtrees): Remove the special case for `str`
@@ -638,7 +638,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// FIXME(eddyb) use a specialized hex-encoding loop.
for byte in s.bytes() {
- let _ = write!(self.out, "{:02x}", byte);
+ let _ = write!(self.out, "{byte:02x}");
}
self.push("_");