From 3ebe4fde0297d09eb82ecbf5065c29993e07b91f Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Mon, 15 Jul 2024 11:49:20 +0100 Subject: [PATCH] Fixes generic enums and structs type ids. --- sway-core/src/abi_generation/abi_str.rs | 22 +++++++++++++++---- sway-core/src/abi_generation/fuel_abi.rs | 10 ++++----- .../ty/expression/intrinsic_function.rs | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/sway-core/src/abi_generation/abi_str.rs b/sway-core/src/abi_generation/abi_str.rs index f7d0e9934ea..a4519ca3855 100644 --- a/sway-core/src/abi_generation/abi_str.rs +++ b/sway-core/src/abi_generation/abi_str.rs @@ -2,10 +2,12 @@ use sway_types::integer_bits::IntegerBits; use crate::{language::CallPath, Engines, TypeArgument, TypeId, TypeInfo}; +#[derive(Clone)] pub struct AbiStrContext { pub program_name: Option, pub abi_with_callpaths: bool, pub abi_with_fully_specified_types: bool, + pub abi_with_generic_type_parameters: bool, } impl TypeId { @@ -39,7 +41,13 @@ impl TypeId { .iter() .map(|f| { if ctx.abi_with_fully_specified_types { - type_engine.get(f.type_id).abi_str(ctx, engines) + type_engine.get(f.type_id).abi_str( + &AbiStrContext { + abi_with_generic_type_parameters: true, + ..ctx.clone() + }, + engines, + ) } else { "_".to_string() } @@ -50,7 +58,13 @@ impl TypeId { (TypeInfo::Array(_, count), TypeInfo::Array(type_arg, resolved_count)) => { assert_eq!(count.val(), resolved_count.val()); let inner_type = if ctx.abi_with_fully_specified_types { - type_engine.get(type_arg.type_id).abi_str(ctx, engines) + type_engine.get(type_arg.type_id).abi_str( + &AbiStrContext { + abi_with_generic_type_parameters: true, + ..ctx.clone() + }, + engines, + ) } else { "_".to_string() }; @@ -105,7 +119,7 @@ impl TypeInfo { Enum(decl_ref) => { let decl = decl_engine.get_enum(decl_ref); let type_params = - if !ctx.abi_with_fully_specified_types || decl.type_parameters.is_empty() { + if !ctx.abi_with_generic_type_parameters || decl.type_parameters.is_empty() { "".into() } else { format!( @@ -126,7 +140,7 @@ impl TypeInfo { Struct(decl_ref) => { let decl = decl_engine.get_struct(decl_ref); let type_params = - if !ctx.abi_with_fully_specified_types || decl.type_parameters.is_empty() { + if !ctx.abi_with_generic_type_parameters || decl.type_parameters.is_empty() { "".into() } else { format!( diff --git a/sway-core/src/abi_generation/fuel_abi.rs b/sway-core/src/abi_generation/fuel_abi.rs index d9e5970aaf9..31b5d4c0301 100644 --- a/sway-core/src/abi_generation/fuel_abi.rs +++ b/sway-core/src/abi_generation/fuel_abi.rs @@ -19,11 +19,7 @@ pub struct AbiContext<'a> { } impl<'a> AbiContext<'a> { - fn to_str_context( - &self, - engines: &Engines, - abi_with_fully_specified_types: bool, - ) -> AbiStrContext { + fn to_str_context(&self, engines: &Engines, abi_full: bool) -> AbiStrContext { AbiStrContext { program_name: self .program @@ -32,7 +28,8 @@ impl<'a> AbiContext<'a> { .program_id(engines) .read(engines, |m| m.name.clone().map(|v| v.as_str().to_string())), abi_with_callpaths: self.abi_with_callpaths, - abi_with_fully_specified_types, + abi_with_fully_specified_types: abi_full, + abi_with_generic_type_parameters: abi_full, } } } @@ -55,6 +52,7 @@ impl TypeId { .read(engines, |m| m.name.clone().map(|v| v.as_str().to_string())), abi_with_callpaths: true, abi_with_fully_specified_types: true, + abi_with_generic_type_parameters: false, }, engines, resolved_type_id, diff --git a/sway-core/src/language/ty/expression/intrinsic_function.rs b/sway-core/src/language/ty/expression/intrinsic_function.rs index a82ec310f9f..eadc7dcde1a 100644 --- a/sway-core/src/language/ty/expression/intrinsic_function.rs +++ b/sway-core/src/language/ty/expression/intrinsic_function.rs @@ -121,6 +121,7 @@ impl CollectTypesMetadata for TyIntrinsicFunctionKind { program_name: Some(ctx.program_name.clone()), abi_with_callpaths: true, abi_with_fully_specified_types: true, + abi_with_generic_type_parameters: true, }, ctx.engines, logged_type,