Skip to content
Open
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
21 changes: 9 additions & 12 deletions rs_bindings_from_cc/generate_bindings/generate_function_thunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,18 @@ fn compute_disambiguator_hash(func: &Func) -> String {
}

pub fn thunk_ident(db: &BindingsGenerator, func: &Func) -> Ident {
let disambiguator = if db.has_conflicting_mangled_name(func) {
compute_disambiguator_hash(func)
} else {
"".to_string()
let disambiguator = {
let need_disambiguation =
db.has_conflicting_mangled_name(func) || func.is_member_or_descendant_of_class_template;
if need_disambiguation {
compute_disambiguator_hash(func)
} else {
"".to_string()
}
};

// TODO(b/528469099): Unify `odr_suffix` and `disambituator` (probably by
// removing `odr_suffix` and using `disambituator` for both conditions).
let odr_suffix = if func.is_member_or_descendant_of_class_template {
func.owning_target.convert_to_cc_identifier()
} else {
String::new()
};
format_ident!(
"__rust_thunk__{disambiguator}{}{odr_suffix}",
"__rust_thunk__{disambiguator}{}",
ident_fragment_from_mangled_name(func.mangled_name.as_ref())
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Default for __CcTemplateInst2TSIiE {
fn default() -> Self {
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
unsafe {
crate::detail::__rust_thunk___ZN2TSIiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplate_5finstantiation_5fcc(&raw mut tmp as*mut _);
crate::detail::__rust_thunk__20ba560a__ZN2TSIiEC1Ev(&raw mut tmp as *mut _);
tmp.assume_init()
}
}
Expand All @@ -52,9 +52,7 @@ mod detail {
use super::*;
unsafe extern "C" {
pub(crate) unsafe fn __rust_thunk___Z3RTSv(__return: *mut ::core::ffi::c_void);
pub(crate) unsafe fn __rust_thunk___ZN2TSIiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplate_5finstantiation_5fcc(
__this: *mut ::core::ffi::c_void,
);
pub(crate) unsafe fn __rust_thunk__20ba560a__ZN2TSIiEC1Ev(__this: *mut ::core::ffi::c_void);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ static_assert((struct TS<int> (*)()) & ::RTS);
static_assert(sizeof(struct TS<int>) == 1);
static_assert(alignof(struct TS<int>) == 1);

extern "C" void
__rust_thunk___ZN2TSIiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplate_5finstantiation_5fcc(
struct TS<int>* __this) {
extern "C" void __rust_thunk__20ba560a__ZN2TSIiEC1Ev(struct TS<int>* __this) {
crubit::construct_at(__this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ static_assert((void (*)(struct Ts<short, double>)) & ::ShortDoubleCaller);
static_assert(sizeof(struct Ts<int, float>) == 1);
static_assert(alignof(struct Ts<int, float>) == 1);

extern "C" void
__rust_thunk___ZN2TsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(
extern "C" void __rust_thunk__ca694370__ZN2TsIifEC1Eif(
struct Ts<int, float>* __this, int t, float s) {
crubit::construct_at(__this, t, s);
}

extern "C" void
__rust_thunk___ZN2TsIifE6MemberEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(
extern "C" void __rust_thunk__f7010ef7__ZN2TsIifE6MemberEv(
struct Ts<int, float>* __this) {
__this->Member();
}
Expand All @@ -52,8 +50,7 @@ static_assert((void (::Ts<int, float>::*)()) & ::Ts<int, float>::Member);
static_assert(sizeof(struct Ts<short, double>) == 1);
static_assert(alignof(struct Ts<short, double>) == 1);

extern "C" void
__rust_thunk___ZN2TsIsdEC1Esd__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(
extern "C" void __rust_thunk__ca694370__ZN2TsIsdEC1Esd(
struct Ts<short, double>* __this, short t, double s) {
crubit::construct_at(__this, t, s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl From<(::ffi_11::c_int, f32)> for __CcTemplateInst2TsIifE {
let (mut t, mut s) = args;
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
unsafe {
crate::detail::__rust_thunk___ZN2TsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(&raw mut tmp as*mut _,t,s);
crate::detail::__rust_thunk__ca694370__ZN2TsIifEC1Eif(&raw mut tmp as *mut _, t, s);
tmp.assume_init()
}
}
Expand All @@ -83,9 +83,7 @@ pub mod cc_template_inst2_ts_iif_e {
/// * `__this`: raw pointer
#[inline(always)]
pub(crate) unsafe fn Member(__this: *mut crate::__CcTemplateInst2TsIifE) {
unsafe {
crate::detail::__rust_thunk___ZN2TsIifE6MemberEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(__this)
}
unsafe { crate::detail::__rust_thunk__f7010ef7__ZN2TsIifE6MemberEv(__this) }
}
}

Expand All @@ -104,7 +102,7 @@ impl From<(::ffi_11::c_short, f64)> for __CcTemplateInst2TsIsdE {
let (mut t, mut s) = args;
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
unsafe {
crate::detail::__rust_thunk___ZN2TsIsdEC1Esd__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(&raw mut tmp as*mut _,t,s);
crate::detail::__rust_thunk__ca694370__ZN2TsIsdEC1Esd(&raw mut tmp as *mut _, t, s);
tmp.assume_init()
}
}
Expand All @@ -128,15 +126,15 @@ mod detail {
pub(crate) unsafe fn __rust_thunk___Z17ShortDoubleCaller2TsIsdE(
i: &mut crate::__CcTemplateInst2TsIsdE,
);
pub(crate) unsafe fn __rust_thunk___ZN2TsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(
pub(crate) unsafe fn __rust_thunk__ca694370__ZN2TsIifEC1Eif(
__this: *mut ::core::ffi::c_void,
t: ::ffi_11::c_int,
s: f32,
);
pub(crate) unsafe fn __rust_thunk___ZN2TsIifE6MemberEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(
pub(crate) unsafe fn __rust_thunk__f7010ef7__ZN2TsIifE6MemberEv(
__this: *mut crate::__CcTemplateInst2TsIifE,
);
pub(crate) unsafe fn __rust_thunk___ZN2TsIsdEC1Esd__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5finstance(
pub(crate) unsafe fn __rust_thunk__ca694370__ZN2TsIsdEC1Esd(
__this: *mut ::core::ffi::c_void,
t: ::ffi_11::c_short,
s: f64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ static_assert((void (*)(struct NotBoundTs<int, float>)) & ::NotBoundCaller);
static_assert(sizeof(struct AlwaysBoundTs<int, float>) == 1);
static_assert(alignof(struct AlwaysBoundTs<int, float>) == 1);

extern "C" void
__rust_thunk___ZN13AlwaysBoundTsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(
extern "C" void __rust_thunk__23bcdcc7__ZN13AlwaysBoundTsIifEC1Eif(
struct AlwaysBoundTs<int, float>* __this, int t, float s) {
crubit::construct_at(__this, t, s);
}

extern "C" void
__rust_thunk___ZN13AlwaysBoundTsIifE6MemberEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(
extern "C" void __rust_thunk__56d34d81__ZN13AlwaysBoundTsIifE6MemberEv(
struct AlwaysBoundTs<int, float>* __this) {
__this->Member();
}
Expand All @@ -53,8 +51,7 @@ static_assert((void (::AlwaysBoundTs<int, float>::*)()) &
static_assert(sizeof(struct NotBoundTs<int, float>) == 1);
static_assert(alignof(struct NotBoundTs<int, float>) == 1);

extern "C" void
__rust_thunk___ZN10NotBoundTsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(
extern "C" void __rust_thunk__9053d357__ZN10NotBoundTsIifEC1Eif(
struct NotBoundTs<int, float>* __this, int t, float s) {
crubit::construct_at(__this, t, s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ impl From<(::ffi_11::c_int, f32)> for __CcTemplateInst13AlwaysBoundTsIifE {
let (mut t, mut s) = args;
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
unsafe {
crate::detail::__rust_thunk___ZN13AlwaysBoundTsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(&raw mut tmp as*mut _,t,s);
crate::detail::__rust_thunk__23bcdcc7__ZN13AlwaysBoundTsIifEC1Eif(
&raw mut tmp as *mut _,
t,
s,
);
tmp.assume_init()
}
}
Expand All @@ -79,9 +83,7 @@ pub mod cc_template_inst13_always_bound_ts_iif_e {
/// * `__this`: raw pointer
#[inline(always)]
pub(crate) unsafe fn Member(__this: *mut crate::__CcTemplateInst13AlwaysBoundTsIifE) {
unsafe {
crate::detail::__rust_thunk___ZN13AlwaysBoundTsIifE6MemberEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(__this)
}
unsafe { crate::detail::__rust_thunk__56d34d81__ZN13AlwaysBoundTsIifE6MemberEv(__this) }
}
}

Expand All @@ -100,7 +102,11 @@ impl From<(::ffi_11::c_int, f32)> for __CcTemplateInst10NotBoundTsIifE {
let (mut t, mut s) = args;
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
unsafe {
crate::detail::__rust_thunk___ZN10NotBoundTsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(&raw mut tmp as*mut _,t,s);
crate::detail::__rust_thunk__9053d357__ZN10NotBoundTsIifEC1Eif(
&raw mut tmp as *mut _,
t,
s,
);
tmp.assume_init()
}
}
Expand All @@ -124,15 +130,15 @@ mod detail {
pub(crate) unsafe fn __rust_thunk___Z14NotBoundCaller10NotBoundTsIifE(
i: &mut crate::__CcTemplateInst10NotBoundTsIifE,
);
pub(crate) unsafe fn __rust_thunk___ZN13AlwaysBoundTsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(
pub(crate) unsafe fn __rust_thunk__23bcdcc7__ZN13AlwaysBoundTsIifEC1Eif(
__this: *mut ::core::ffi::c_void,
t: ::ffi_11::c_int,
s: f32,
);
pub(crate) unsafe fn __rust_thunk___ZN13AlwaysBoundTsIifE6MemberEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(
pub(crate) unsafe fn __rust_thunk__56d34d81__ZN13AlwaysBoundTsIifE6MemberEv(
__this: *mut crate::__CcTemplateInst13AlwaysBoundTsIifE,
);
pub(crate) unsafe fn __rust_thunk___ZN10NotBoundTsIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fallowlist_3aallowlist_5fspecific_5ftemplate(
pub(crate) unsafe fn __rust_thunk__9053d357__ZN10NotBoundTsIifEC1Eif(
__this: *mut ::core::ffi::c_void,
t: ::ffi_11::c_int,
s: f32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ static_assert((void (*)(NiIF const&)) & ::SomeApi);
static_assert(sizeof(struct Ni<int, float>) == 1);
static_assert(alignof(struct Ni<int, float>) == 1);

extern "C" void
__rust_thunk___ZN2NiIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fnamed_5finstantiation_3anamed_5finstantiation(
extern "C" void __rust_thunk__426ccee6__ZN2NiIifEC1Eif(
struct Ni<int, float>* __this, int t, float s) {
crubit::construct_at(__this, t, s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl From<(::ffi_11::c_int, f32)> for __CcTemplateInst2NiIifE {
let (mut t, mut s) = args;
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
unsafe {
crate::detail::__rust_thunk___ZN2NiIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fnamed_5finstantiation_3anamed_5finstantiation(&raw mut tmp as*mut _,t,s);
crate::detail::__rust_thunk__426ccee6__ZN2NiIifEC1Eif(&raw mut tmp as *mut _, t, s);
tmp.assume_init()
}
}
Expand All @@ -66,7 +66,7 @@ mod detail {
unsafe extern "C" {
#[link_name = "_Z7SomeApiRK2NiIifE"]
pub(crate) unsafe fn __rust_thunk___Z7SomeApiRK2NiIifE(i: *const crate::NiIF);
pub(crate) unsafe fn __rust_thunk___ZN2NiIifEC1Eif__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2fnamed_5finstantiation_3anamed_5finstantiation(
pub(crate) unsafe fn __rust_thunk__426ccee6__ZN2NiIifEC1Eif(
__this: *mut ::core::ffi::c_void,
t: ::ffi_11::c_int,
s: f32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@
static_assert(CRUBIT_SIZEOF(class ::MyTemplate<int>) == 4);
static_assert(alignof(class ::MyTemplate<int>) == 4);

extern "C" void
__rust_thunk___ZN10MyTemplateIiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(
extern "C" void __rust_thunk__de4d35d3__ZN10MyTemplateIiEC1Ev(
class ::MyTemplate<int>* __this) {
crubit::construct_at(__this);
}

extern "C" void
__rust_thunk___ZN10MyTemplateIiE6CreateEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(
extern "C" void __rust_thunk__5a9d55c6__ZN10MyTemplateIiE6CreateEi(
class ::MyTemplate<int>* __return, int value) {
new (__return) auto(::MyTemplate<int>::Create(value));
}

static_assert((class ::MyTemplate<int> (*)(int)) & ::MyTemplate<int>::Create);

extern "C" int const*
__rust_thunk___ZNK10MyTemplateIiE5valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(
extern "C" int const* __rust_thunk__758630aa__ZNK10MyTemplateIiE5valueEv(
class ::MyTemplate<int> const* __this) {
return std::addressof(__this->value());
}
Expand Down
19 changes: 9 additions & 10 deletions rs_bindings_from_cc/test/templates/type_alias/type_alias_rs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Default for __CcTemplateInst10MyTemplateIiE {
fn default() -> Self {
let mut tmp = ::core::mem::MaybeUninit::<Self>::zeroed();
unsafe {
crate::detail::__rust_thunk___ZN10MyTemplateIiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(&raw mut tmp as*mut _);
crate::detail::__rust_thunk__de4d35d3__ZN10MyTemplateIiEC1Ev(&raw mut tmp as *mut _);
tmp.assume_init()
}
}
Expand All @@ -64,34 +64,33 @@ pub mod cc_template_inst10_my_template_ii_e {
unsafe {
let mut __crubit_return =
::core::mem::MaybeUninit::<crate::__CcTemplateInst10MyTemplateIiE>::uninit();
crate::detail::__rust_thunk___ZN10MyTemplateIiE6CreateEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(&raw mut __crubit_return as*mut::core::ffi::c_void,value);
crate::detail::__rust_thunk__5a9d55c6__ZN10MyTemplateIiE6CreateEi(
&raw mut __crubit_return as *mut ::core::ffi::c_void,
value,
);
__crubit_return.assume_init()
}
}
#[inline(always)]
pub(crate) fn value<'__this>(
__this: &'__this crate::__CcTemplateInst10MyTemplateIiE,
) -> ::cref::CRef<'__this, ::ffi_11::c_int> {
unsafe {
crate::detail::__rust_thunk___ZNK10MyTemplateIiE5valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(__this)
}
unsafe { crate::detail::__rust_thunk__758630aa__ZNK10MyTemplateIiE5valueEv(__this) }
}
}

mod detail {
#[allow(unused_imports)]
use super::*;
unsafe extern "C" {
pub(crate) unsafe fn __rust_thunk___ZN10MyTemplateIiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(
pub(crate) unsafe fn __rust_thunk__de4d35d3__ZN10MyTemplateIiEC1Ev(
__this: *mut ::core::ffi::c_void,
);
pub(crate) unsafe fn __rust_thunk___ZN10MyTemplateIiE6CreateEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(
pub(crate) unsafe fn __rust_thunk__5a9d55c6__ZN10MyTemplateIiE6CreateEi(
__return: *mut ::core::ffi::c_void,
value: ::ffi_11::c_int,
);
pub(crate) unsafe fn __rust_thunk___ZNK10MyTemplateIiE5valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias<
'__this,
>(
pub(crate) unsafe fn __rust_thunk__758630aa__ZNK10MyTemplateIiE5valueEv<'__this>(
__this: &'__this crate::__CcTemplateInst10MyTemplateIiE,
) -> ::cref::CRef<'__this, ::ffi_11::c_int>;
}
Expand Down