Use the resolved type name in generic strings, not the original
authorMatt Corallo <git@bluematt.me>
Thu, 28 Sep 2023 01:14:41 +0000 (01:14 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 4 Oct 2023 20:02:23 +0000 (20:02 +0000)
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 :(.

c-bindings-gen/src/types.rs

index b08c6bc9d30bbc3a938033d5135d03084bab7076..9df1bd1c1ef309e13aef79f99072c3c265adf128 100644 (file)
@@ -2900,7 +2900,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                                                                        generics, &subtype, is_ref, is_mut, ptr_for_ref, true);
                                                        }
                                                } else {
-                                                       let id = subtype.rsplitn(2, ':').next().unwrap(); // Get the "Base" name of the resolved type
+                                                       let mut resolved = Vec::new();
+                                                       let id =
+                                                               if self.write_c_path_intern(&mut resolved, &$p_arg.path, generics, false, false, false, false, false) {
+                                                                       let inner = std::str::from_utf8(&resolved).unwrap();
+                                                                       inner.rsplitn(2, "::").next().unwrap()
+                                                               } else {
+                                                                       subtype.rsplitn(2, "::").next().unwrap()
+                                                               };
                                                        write!(w, "{}", id).unwrap();
                                                        write!(mangled_type, "{}", id).unwrap();
                                                        if let Some(w2) = $extra_write as Option<&mut Vec<u8>> {
@@ -2934,9 +2941,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                                                                } else { return false; }
                                                        } else if let syn::Type::Array(_) = elem {
                                                                let mut resolved = Vec::new();
-                                                               if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, true, false, true) { return false; }
+                                                               if !self.write_c_type_intern(&mut resolved, &elem, generics, false, false, false, false, false) { return false; }
                                                                let array_inner = String::from_utf8(resolved).unwrap();
-                                                               let arr_name = array_inner.split("::").last().unwrap();
+                                                               let arr_name = array_inner.rsplitn(2, "::").next().unwrap();
                                                                write!(w, "{}", arr_name).unwrap();
                                                                write!(mangled_type, "{}", arr_name).unwrap();
                                                        } else { return false; }