Skip to content

Commit

Permalink
Fix type enumeration for stripped metadata in subxt. (#23)
Browse files Browse the repository at this point in the history
* hotfix type enumetation

* clippy

* make iter simpler

* clippy

* Tweak changelog comment

---------

Co-authored-by: James Wilson <[email protected]>
  • Loading branch information
tadeohepperle and jsdw authored Mar 25, 2024
1 parent 59d5747 commit 64ec335
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [0.4.1] - 2024-03-22

- Bump `scale-info` to 2.11.1 to fix an issue in `scale_typegen::utils::ensure_unique_type_paths` for cases where a type's index and id do not line up, and simplify code a touch.

# [0.4.0] - 2024-03-21

- Fix logic bug in `scale_typegen::utils::ensure_unique_type_paths`.
Expand All @@ -6,8 +10,8 @@

# [0.3.0] - 2024-03-19

- When generating rust code with `TypeGenerator::gerate_types_mod` we now validate that no type
is overwritten by another type that has an identical type path but a different structure. In case this happens,
- When generating rust code with `TypeGenerator::gerate_types_mod` we now validate that no type
is overwritten by another type that has an identical type path but a different structure. In case this happens,
we return an error and encourage users to use `scale_typegen::utils::ensure_unique_type_paths` on
the type registry before. Doing so, should let the type generation succeed.

Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ resolver = "2"
[workspace.package]
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
version = "0.4.0"
version = "0.4.1"
rust-version = "1.70.0"
license = "Apache-2.0 OR GPL-3.0"
repository = "https://github.com/paritytech/scale-typegen"
homepage = "https://www.parity.io/"


[workspace.dependencies]

scale-typegen-description = { version = "0.4.0", path = "description" }
scale-typegen = { version = "0.4.0", path = "typegen" }
scale-typegen-description = { version = "0.4.1", path = "description" }
scale-typegen = { version = "0.4.1", path = "typegen" }

# external dependencies
parity-scale-codec = { version = "3.6.5", features = ["derive"] }
proc-macro2 = "1.0.69"
quote = "1.0.33"
scale-bits = "0.5.0"
scale-info = { version = "2.10.0", features = ["derive", "bit-vec", "decode", "docs", "serde"] }
scale-info = { version = "2.11.1", features = ["derive", "bit-vec", "decode", "docs", "serde"] }
smallvec = "1.10.0"
syn = { version = "2.0.38", features = ["full", "extra-traits"] }
thiserror = "1.0.50"
Expand Down
13 changes: 7 additions & 6 deletions typegen/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub fn ensure_unique_type_paths(types: &mut PortableRegistry) {
let mut types_with_same_type_path_grouped_by_shape = HashMap::<&[String], Vec<Vec<u32>>>::new();

// First, group types if they are similar (same path, same shape).

for (ty_id, ty) in types.types.iter().enumerate() {
for ty in types.types.iter() {
// Ignore types without a path (i.e prelude types).
if ty.ty.path.namespace().is_empty() {
continue;
Expand All @@ -31,9 +30,11 @@ pub fn ensure_unique_type_paths(types: &mut PortableRegistry) {
// Compare existing groups to check which to add our type ID to.
let mut added_to_existing_group = false;
for group in groups_with_same_path.iter_mut() {
let ty_id_b = group[0]; // all types in group are same shape; just check any one of them.
let ty_b = types.resolve(ty_id_b).expect("ty exists");
if types_equal_extended_to_params(&ty.ty, ty_b) {
let other_ty_in_group_idx = group[0]; // all types in group are same shape; just check any one of them.
let other_ty_in_group = types
.resolve(other_ty_in_group_idx)
.expect("type is present; qed;");
if types_equal_extended_to_params(&ty.ty, other_ty_in_group) {
group.push(ty.id);
added_to_existing_group = true;
break;
Expand All @@ -42,7 +43,7 @@ pub fn ensure_unique_type_paths(types: &mut PortableRegistry) {

// We didn't find a matching group, so add it to a new one.
if !added_to_existing_group {
groups_with_same_path.push(vec![ty_id as u32])
groups_with_same_path.push(vec![ty.id])
}
}

Expand Down

0 comments on commit 64ec335

Please sign in to comment.