From e6a97ad47131bb9a4894d4200c36fdac906765fc Mon Sep 17 00:00:00 2001 From: tritao Date: Sat, 28 Jun 2025 19:38:40 +0100 Subject: [PATCH 1/5] Do not consider aliased types as generic parameters. --- sway-core/src/type_system/id.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sway-core/src/type_system/id.rs b/sway-core/src/type_system/id.rs index b74b2742949..f361f73c717 100644 --- a/sway-core/src/type_system/id.rs +++ b/sway-core/src/type_system/id.rs @@ -228,13 +228,7 @@ impl TypeId { }, TypeInfo::Struct(decl_ref), ) => call_path.call_path.suffix != decl_engine.get_struct(decl_ref).call_path.suffix, - ( - TypeInfo::Custom { - qualified_call_path: call_path, - .. - }, - TypeInfo::Alias { name, .. }, - ) => call_path.call_path.suffix != name.clone(), + (TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => false, (TypeInfo::Custom { .. }, _) => true, _ => false, } From c27c8c72b11362a00c52e9027ee5ecf97bfdc793 Mon Sep 17 00:00:00 2001 From: tritao Date: Fri, 18 Jul 2025 11:18:53 +0100 Subject: [PATCH 2/5] Do not process inner aliased types when generating ABI type string. --- sway-core/src/abi_generation/abi_str.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sway-core/src/abi_generation/abi_str.rs b/sway-core/src/abi_generation/abi_str.rs index decaaf27b38..80feb40c64a 100644 --- a/sway-core/src/abi_generation/abi_str.rs +++ b/sway-core/src/abi_generation/abi_str.rs @@ -35,10 +35,7 @@ impl TypeId { | (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => type_engine .get(resolved_type_id) .abi_str(handler, ctx, engines, true), - (_, TypeInfo::Alias { ty, .. }) => { - ty.type_id() - .get_abi_type_str(handler, ctx, engines, ty.type_id()) - } + (_, TypeInfo::Alias { .. }) => Ok(self_abi_str), (TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => { assert_eq!(fields.len(), resolved_fields.len()); let field_strs = resolved_fields @@ -200,7 +197,10 @@ impl TypeInfo { "__slice {}", ty.abi_str(handler, ctx, engines, false)? )), - Alias { ty, .. } => Ok(ty.abi_str(handler, ctx, engines, false)?), + Alias { .. } => { + // Aliases are handled specially when processing the ABI, so we should never get here. + unreachable!() + } TraitType { name, trait_type_id: _, From 82659858608eeb8c2d64a0f1e062ee1a9b9e6183 Mon Sep 17 00:00:00 2001 From: tritao Date: Sat, 28 Jun 2025 19:42:37 +0100 Subject: [PATCH 3/5] Generate `aliasOf` field when processing aliased types for ABI generation. --- sway-core/src/abi_generation/fuel_abi.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sway-core/src/abi_generation/fuel_abi.rs b/sway-core/src/abi_generation/fuel_abi.rs index 5d9bc085ae2..f8ecfc9498f 100644 --- a/sway-core/src/abi_generation/fuel_abi.rs +++ b/sway-core/src/abi_generation/fuel_abi.rs @@ -649,11 +649,31 @@ fn generate_concrete_type_declaration( let (type_field, concrete_type_id) = type_id.get_abi_type_field_and_concrete_id(handler, ctx, engines, resolved_type_id)?; + + let type_engine = engines.te(); + let alias_of = match &*type_engine.get(resolved_type_id) { + TypeInfo::Alias { ty, .. } => { + // Ensure the underlying representation has a declaration first + let target_ctid = generate_concrete_type_declaration( + handler, + ctx, + engines, + metadata_types, + concrete_types, + ty.initial_type_id(), + ty.type_id(), + )?; + Some(target_ctid) + } + _ => None, + }; + let concrete_type_decl = TypeConcreteDeclaration { type_field, concrete_type_id: concrete_type_id.clone(), metadata_type_id, type_arguments, + alias_of, }; concrete_types.push(concrete_type_decl); From f43554dd8a68d5b1b6184cfe5f2a4b3c20436f4c Mon Sep 17 00:00:00 2001 From: tritao Date: Sat, 28 Jun 2025 20:08:45 +0100 Subject: [PATCH 4/5] Do not consider type aliases when retrieving ABI type components. --- sway-core/src/abi_generation/fuel_abi.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sway-core/src/abi_generation/fuel_abi.rs b/sway-core/src/abi_generation/fuel_abi.rs index f8ecfc9498f..44b3626a085 100644 --- a/sway-core/src/abi_generation/fuel_abi.rs +++ b/sway-core/src/abi_generation/fuel_abi.rs @@ -1170,21 +1170,6 @@ impl TypeId { None } } - TypeInfo::Alias { .. } => { - if let TypeInfo::Alias { ty, .. } = &*type_engine.get(resolved_type_id) { - ty.initial_type_id().get_abi_type_components( - handler, - ctx, - engines, - metadata_types, - concrete_types, - ty.type_id(), - metadata_types_to_add, - )? - } else { - None - } - } TypeInfo::UnknownGeneric { .. } => { // avoid infinite recursion if *self == resolved_type_id { From f0d347863002dfb2f6b61d6f900b52a539ac3330 Mon Sep 17 00:00:00 2001 From: tritao Date: Wed, 30 Jul 2025 16:06:18 +0100 Subject: [PATCH 5/5] Update `fuel-abi-types` to 0.15.0. --- Cargo.lock | 80 +++++++++++++++++++++--- Cargo.toml | 2 +- sway-core/src/abi_generation/fuel_abi.rs | 5 ++ 3 files changed, 76 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab8287214aa..5b9094a6a7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2969,7 +2969,7 @@ dependencies = [ "forc-tracing 0.69.1", "forc-util", "fs_extra", - "fuel-abi-types", + "fuel-abi-types 0.15.0", "fuel-asm", "hex", "rexpect", @@ -3011,7 +3011,7 @@ dependencies = [ "forc-tx", "forc-util", "forc-wallet", - "fuel-abi-types", + "fuel-abi-types 0.15.0", "fuel-core-client", "fuel-core-storage", "fuel-core-types", @@ -3089,7 +3089,7 @@ dependencies = [ "forc-test", "forc-tracing 0.69.1", "forc-util", - "fuel-abi-types", + "fuel-abi-types 0.15.0", "fuel-core-client", "fuel-tx", "fuel-types", @@ -3243,7 +3243,7 @@ dependencies = [ "flate2", "forc-tracing 0.69.1", "forc-util", - "fuel-abi-types", + "fuel-abi-types 0.15.0", "futures", "git2", "gix-url", @@ -3311,7 +3311,7 @@ dependencies = [ "anyhow", "forc-pkg", "forc-util", - "fuel-abi-types", + "fuel-abi-types 0.15.0", "fuel-tx", "fuel-vm", "rand 0.8.5", @@ -3371,7 +3371,7 @@ dependencies = [ "dirs 5.0.1", "fd-lock", "forc-tracing 0.69.1", - "fuel-abi-types", + "fuel-abi-types 0.15.0", "fuel-asm", "fuel-tx", "fuels-core", @@ -3460,6 +3460,24 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "fuel-abi-types" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e2647c0e022c4911954b4c50d7e618885db1bdf402e7c2c398902269e819a5d" +dependencies = [ + "itertools 0.10.5", + "lazy_static", + "proc-macro2", + "quote", + "regex", + "rstest", + "serde", + "serde_json", + "syn 2.0.101", + "thiserror 1.0.69", +] + [[package]] name = "fuel-asm" version = "0.62.0" @@ -3831,7 +3849,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2bf80dac7255cd5b3ed2a69745622946151fc85b92fe7b1c3e0bbeecba6322e" dependencies = [ "Inflector", - "fuel-abi-types", + "fuel-abi-types 0.12.0", "itertools 0.12.1", "proc-macro2", "quote", @@ -3849,7 +3867,7 @@ dependencies = [ "async-trait", "auto_impl", "chrono", - "fuel-abi-types", + "fuel-abi-types 0.12.0", "fuel-asm", "fuel-core-chain-config", "fuel-core-client", @@ -3889,7 +3907,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "595f83f274003d1a75b1e065433e933286375aa8cde91d14787ec803bbc91b26" dependencies = [ "async-trait", - "fuel-abi-types", + "fuel-abi-types 0.12.0", "fuel-asm", "fuel-tx", "fuel-types", @@ -4002,6 +4020,12 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + [[package]] name = "futures-util" version = "0.3.31" @@ -6952,6 +6976,12 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "relative-path" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" + [[package]] name = "rend" version = "0.4.2" @@ -7280,6 +7310,36 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "rstest" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fc39292f8613e913f7df8fa892b8944ceb47c247b78e1b1ae2f09e019be789d" +dependencies = [ + "futures-timer", + "futures-util", + "rstest_macros", + "rustc_version 0.4.1", +] + +[[package]] +name = "rstest_macros" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f168d99749d307be9de54d23fd226628d99768225ef08f6ffb52e0182a27746" +dependencies = [ + "cfg-if", + "glob", + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "regex", + "relative-path", + "rustc_version 0.4.1", + "syn 2.0.101", + "unicode-ident", +] + [[package]] name = "rtoolbox" version = "0.0.3" @@ -8336,7 +8396,7 @@ dependencies = [ "clap", "dirs 5.0.1", "either", - "fuel-abi-types", + "fuel-abi-types 0.15.0", "fuel-ethabi", "fuel-etk-asm", "fuel-etk-ops", diff --git a/Cargo.toml b/Cargo.toml index 664355a146d..3fea315e82c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ sway-ir-macros = { path = "sway-ir/sway-ir-macros", version = "0.69.1" } # # Dependencies from the `fuel-abi-types` repository: -fuel-abi-types = "0.12" +fuel-abi-types = "0.15" # Dependencies from the `fuel-core` repository: # diff --git a/sway-core/src/abi_generation/fuel_abi.rs b/sway-core/src/abi_generation/fuel_abi.rs index 44b3626a085..4029cb34961 100644 --- a/sway-core/src/abi_generation/fuel_abi.rs +++ b/sway-core/src/abi_generation/fuel_abi.rs @@ -334,6 +334,7 @@ pub fn generate_program_abi( messages_types: Some(messages_types), configurables: Some(configurables), error_codes: Some(error_codes), + panicking_calls: None, }) } TyProgramKind::Script { main_function, .. } => { @@ -363,6 +364,7 @@ pub fn generate_program_abi( messages_types: Some(messages_types), configurables: Some(configurables), error_codes: Some(error_codes), + panicking_calls: None, }) } TyProgramKind::Predicate { main_function, .. } => { @@ -392,6 +394,7 @@ pub fn generate_program_abi( messages_types: Some(messages_types), configurables: Some(configurables), error_codes: Some(error_codes), + panicking_calls: None, }) } TyProgramKind::Library { .. } => { @@ -411,6 +414,7 @@ pub fn generate_program_abi( messages_types: Some(messages_types), configurables: None, error_codes: Some(error_codes), + panicking_calls: None, }) } })?; @@ -834,6 +838,7 @@ fn generate_error_codes(panic_occurrences: &PanicOccurrences) -> BTreeMap