Skip to content

Commit 3398c19

Browse files
committed
Use the resolved type name in generic strings, not the original
This makes some generics less readable, but some more, and reduces generic type pollution. Some cases are a loss, eg `Option_PaymentHashZ` gets converted to `Option_ThirtyTwoBytesZ` (which less less readable but fewer total types as a result), but we ultimately need this because we now have `schnorr::Signature` and `ecdsa::Signature` so we can't rely on just using `Signature` and having it be unique :(.
1 parent b20a8ec commit 3398c19

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

c-bindings-gen/src/types.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
29002900
generics, &subtype, is_ref, is_mut, ptr_for_ref, true);
29012901
}
29022902
} else {
2903-
let id = subtype.rsplitn(2, ':').next().unwrap(); // Get the "Base" name of the resolved type
2903+
let mut resolved = Vec::new();
2904+
let id =
2905+
if self.write_c_path_intern(&mut resolved, &$p_arg.path, generics, false, false, false, false, false) {
2906+
let inner = std::str::from_utf8(&resolved).unwrap();
2907+
inner.rsplitn(2, "::").next().unwrap()
2908+
} else {
2909+
subtype.rsplitn(2, "::").next().unwrap()
2910+
};
29042911
write!(w, "{}", id).unwrap();
29052912
write!(mangled_type, "{}", id).unwrap();
29062913
if let Some(w2) = $extra_write as Option<&mut Vec<u8>> {
@@ -2934,9 +2941,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
29342941
} else { return false; }
29352942
} else if let syn::Type::Array(_) = elem {
29362943
let mut resolved = Vec::new();
2937-
if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, true, false, true) { return false; }
2944+
if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, false, false, false) { return false; }
29382945
let array_inner = String::from_utf8(resolved).unwrap();
2939-
let arr_name = array_inner.split("::").last().unwrap();
2946+
let arr_name = array_inner.rsplitn(2, "::").next().unwrap();
29402947
write!(w, "{}", arr_name).unwrap();
29412948
write!(mangled_type, "{}", arr_name).unwrap();
29422949
} else { return false; }

0 commit comments

Comments
 (0)