From 888c35e49fd1377e960ee13853dbcfa4646300f3 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Mon, 18 Mar 2024 16:27:08 +0100 Subject: [PATCH] remove the fn --- codegen/src/api/mod.rs | 2 +- metadata/src/lib.rs | 39 --------------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/codegen/src/api/mod.rs b/codegen/src/api/mod.rs index df6c43b0a1..a1628d9ed8 100644 --- a/codegen/src/api/mod.rs +++ b/codegen/src/api/mod.rs @@ -44,7 +44,7 @@ impl RuntimeGenerator { /// /// Supported versions: v14 and v15. pub fn new(mut metadata: Metadata) -> Self { - metadata.ensure_unique_type_paths(); + scale_typegen::utils::ensure_unique_type_paths(metadata.types_mut()); RuntimeGenerator { metadata } } diff --git a/metadata/src/lib.rs b/metadata/src/lib.rs index 2f3c6c0000..cec6afd565 100644 --- a/metadata/src/lib.rs +++ b/metadata/src/lib.rs @@ -171,45 +171,6 @@ impl Metadata { &OuterEnumHashes::empty(), )) } - - /// Ensure that every unique type we'll be generating or referring to also has a - /// unique path, so that types with matching paths don't end up overwriting each other - /// in the codegen. We ignore any types with generics; Subxt actually endeavours to - /// de-duplicate those into single types with a generic. - pub fn ensure_unique_type_paths(&mut self) { - let mut visited_path_counts = HashMap::, usize>::new(); - for ty in self.types.types.iter_mut() { - // Ignore types without a path (ie prelude types). - if ty.ty.path.namespace().is_empty() { - continue; - } - - let has_valid_type_params = ty.ty.type_params.iter().any(|tp| tp.ty.is_some()); - - // Ignore types which have generic params that the type generation will use. - // Ordinarily we'd expect that any two types with identical paths must be parameterized - // in order to share the path. However scale-info doesn't understand all forms of generics - // properly I think (eg generics that have associated types that can differ), and so in - // those cases we need to fix the paths for Subxt to generate correct code. - if has_valid_type_params { - continue; - } - - // Count how many times we've seen the same path already. - let visited_count = visited_path_counts - .entry(ty.ty.path.segments.clone()) - .or_default(); - *visited_count += 1; - - // alter the type so that if it's been seen more than once, we append a number to - // its name to ensure that every unique type has a unique path, too. - if *visited_count > 1 { - if let Some(name) = ty.ty.path.segments.last_mut() { - *name = alloc::format!("{name}{visited_count}"); - } - } - } - } } /// Metadata for a specific pallet.