mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Add typeid_for_trait_ref function
This function computes a Itanium-like typeid for a trait_ref. This is required for the VFE optimization in LLVM. It is used to map `llvm.type.checked.load` invocations, that is loading the function from a vtable, to the vtables this function could be from. It is important to note that `typeid`s are not unique. So multiple vtables of the same trait can share `typeid`s.
This commit is contained in:
parent
20f597ffcd
commit
d55787a155
@ -155,6 +155,13 @@ pub fn typeid_for_fnabi<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>)
|
||||
v0::mangle_typeid_for_fnabi(tcx, fn_abi)
|
||||
}
|
||||
|
||||
pub fn typeid_for_trait_ref<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_ref: ty::PolyExistentialTraitRef<'tcx>,
|
||||
) -> String {
|
||||
v0::mangle_typeid_for_trait_ref(tcx, trait_ref)
|
||||
}
|
||||
|
||||
/// Computes the symbol name for the given instance. This function will call
|
||||
/// `compute_instantiating_crate` if it needs to factor the instantiating crate
|
||||
/// into the symbol name.
|
||||
|
@ -95,6 +95,24 @@ pub(super) fn mangle_typeid_for_fnabi<'tcx>(
|
||||
format!("typeid{}", arg_count)
|
||||
}
|
||||
|
||||
pub(super) fn mangle_typeid_for_trait_ref<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
trait_ref: ty::PolyExistentialTraitRef<'tcx>,
|
||||
) -> String {
|
||||
// FIXME(flip1995): See comment in `mangle_typeid_for_fnabi`.
|
||||
let mut cx = &mut SymbolMangler {
|
||||
tcx,
|
||||
start_offset: 0,
|
||||
paths: FxHashMap::default(),
|
||||
types: FxHashMap::default(),
|
||||
consts: FxHashMap::default(),
|
||||
binders: vec![],
|
||||
out: String::new(),
|
||||
};
|
||||
cx = cx.print_def_path(trait_ref.def_id(), &[]).unwrap();
|
||||
std::mem::take(&mut cx.out)
|
||||
}
|
||||
|
||||
struct BinderLevel {
|
||||
/// The range of distances from the root of what's
|
||||
/// being printed, to the lifetimes in a binder.
|
||||
|
Loading…
Reference in New Issue
Block a user