Skip to content

Commit 0b2afee

Browse files
Rollup merge of #121818 - rcvalle:rust-cfi-remove-unused-typeid-for-fnsig, r=workingjubilee
CFI: Remove unused `typeid_for_fnsig` Removes unused `typeid_for_fnsig` for simplifying the compiler CFI API.
2 parents d071c06 + 7e64163 commit 0b2afee

File tree

2 files changed

+2
-59
lines changed

2 files changed

+2
-59
lines changed

compiler/rustc_symbol_mangling/src/typeid.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
/// For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
55
/// see design document in the tracking issue #89653.
66
use bitflags::bitflags;
7-
use rustc_middle::ty::{FnSig, Instance, Ty, TyCtxt};
7+
use rustc_middle::ty::{Instance, Ty, TyCtxt};
88
use rustc_target::abi::call::FnAbi;
99
use std::hash::Hasher;
1010
use twox_hash::XxHash64;
1111

1212
bitflags! {
13-
/// Options for typeid_for_fnabi and typeid_for_fnsig.
13+
/// Options for typeid_for_fnabi.
1414
#[derive(Clone, Copy, Debug)]
1515
pub struct TypeIdOptions: u32 {
1616
const GENERALIZE_POINTERS = 1;
@@ -30,15 +30,6 @@ pub fn typeid_for_fnabi<'tcx>(
3030
typeid_itanium_cxx_abi::typeid_for_fnabi(tcx, fn_abi, options)
3131
}
3232

33-
/// Returns a type metadata identifier for the specified FnSig.
34-
pub fn typeid_for_fnsig<'tcx>(
35-
tcx: TyCtxt<'tcx>,
36-
fn_sig: &FnSig<'tcx>,
37-
options: TypeIdOptions,
38-
) -> String {
39-
typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, options)
40-
}
41-
4233
/// Returns a type metadata identifier for the specified Instance.
4334
pub fn typeid_for_instance<'tcx>(
4435
tcx: TyCtxt<'tcx>,
@@ -61,19 +52,6 @@ pub fn kcfi_typeid_for_fnabi<'tcx>(
6152
hash.finish() as u32
6253
}
6354

64-
/// Returns a KCFI type metadata identifier for the specified FnSig.
65-
pub fn kcfi_typeid_for_fnsig<'tcx>(
66-
tcx: TyCtxt<'tcx>,
67-
fn_sig: &FnSig<'tcx>,
68-
options: TypeIdOptions,
69-
) -> u32 {
70-
// A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
71-
// xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
72-
let mut hash: XxHash64 = Default::default();
73-
hash.write(typeid_itanium_cxx_abi::typeid_for_fnsig(tcx, fn_sig, options).as_bytes());
74-
hash.finish() as u32
75-
}
76-
7755
/// Returns a KCFI type metadata identifier for the specified Instance.
7856
pub fn kcfi_typeid_for_instance<'tcx>(
7957
tcx: TyCtxt<'tcx>,

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

-35
Original file line numberDiff line numberDiff line change
@@ -1072,41 +1072,6 @@ pub fn typeid_for_fnabi<'tcx>(
10721072
typeid
10731073
}
10741074

1075-
/// Returns a type metadata identifier for the specified FnSig using the Itanium C++ ABI with vendor
1076-
/// extended type qualifiers and types for Rust types that are not used at the FFI boundary.
1077-
pub fn typeid_for_fnsig<'tcx>(
1078-
tcx: TyCtxt<'tcx>,
1079-
fn_sig: &FnSig<'tcx>,
1080-
options: TypeIdOptions,
1081-
) -> String {
1082-
// A name is mangled by prefixing "_Z" to an encoding of its name, and in the case of functions
1083-
// its type.
1084-
let mut typeid = String::from("_Z");
1085-
1086-
// Clang uses the Itanium C++ ABI's virtual tables and RTTI typeinfo structure name as type
1087-
// metadata identifiers for function pointers. The typeinfo name encoding is a two-character
1088-
// code (i.e., 'TS') prefixed to the type encoding for the function.
1089-
typeid.push_str("TS");
1090-
1091-
// A dictionary of substitution candidates used for compression (see
1092-
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
1093-
let mut dict: FxHashMap<DictKey<'tcx>, usize> = FxHashMap::default();
1094-
1095-
// Encode the function signature
1096-
typeid.push_str(&encode_fnsig(tcx, fn_sig, &mut dict, options));
1097-
1098-
// Add encoding suffixes
1099-
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
1100-
typeid.push_str(".normalized");
1101-
}
1102-
1103-
if options.contains(EncodeTyOptions::GENERALIZE_POINTERS) {
1104-
typeid.push_str(".generalized");
1105-
}
1106-
1107-
typeid
1108-
}
1109-
11101075
/// Returns a type metadata identifier for the specified Instance using the Itanium C++ ABI with
11111076
/// vendor extended type qualifiers and types for Rust types that are not used at the FFI boundary.
11121077
pub fn typeid_for_instance<'tcx>(

0 commit comments

Comments
 (0)