From 3398c19e2889fbe22590d8991b4ce1bc176ec1bc Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 28 Sep 2023 01:14:41 +0000 Subject: [PATCH] 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 :(. --- c-bindings-gen/src/types.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index b08c6bc..9df1bd1 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -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> { @@ -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; } -- 2.39.5