diff --git a/Cargo.lock b/Cargo.lock index 84b7375f8a9..1ab32c1970d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4554,7 +4554,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ - "proc-macro-crate 3.1.0", + "proc-macro-crate 1.1.3", "proc-macro2", "quote", "syn 2.0.63", @@ -7539,7 +7539,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "static_assertions", ] diff --git a/sway-core/src/abi_generation/abi_str.rs b/sway-core/src/abi_generation/abi_str.rs new file mode 100644 index 00000000000..3c94fc3a731 --- /dev/null +++ b/sway-core/src/abi_generation/abi_str.rs @@ -0,0 +1,211 @@ +use sway_types::integer_bits::IntegerBits; + +use crate::{language::CallPath, Engines, TypeArgument, TypeId, TypeInfo}; + +pub struct AbiStrContext { + pub program_name: Option, + pub abi_with_callpaths: bool, + pub abi_with_fully_specified_types: bool, +} + +impl TypeId { + /// Gives back a string that represents the type, considering what it resolves to + pub fn get_abi_type_str( + &self, + ctx: &AbiStrContext, + engines: &Engines, + resolved_type_id: TypeId, + ) -> String { + let type_engine = engines.te(); + if self.is_generic_parameter(engines, resolved_type_id) { + format!("generic {}", type_engine.get(*self).abi_str(ctx, engines)) + } else { + match ( + &*type_engine.get(*self), + &*type_engine.get(resolved_type_id), + ) { + (TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => { + type_engine.get(resolved_type_id).abi_str(ctx, engines) + } + (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => { + type_engine.get(resolved_type_id).abi_str(ctx, engines) + } + (TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => { + type_engine.get(resolved_type_id).abi_str(ctx, engines) + } + (TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => { + assert_eq!(fields.len(), resolved_fields.len()); + let field_strs = fields + .iter() + .map(|f| { + if ctx.abi_with_fully_specified_types { + type_engine.get(f.type_id).abi_str(ctx, engines) + } else { + "_".to_string() + } + }) + .collect::>(); + format!("({})", field_strs.join(", ")) + } + (TypeInfo::Array(type_arg, count), TypeInfo::Array(_, 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) + } else { + "_".to_string() + }; + format!("[{}; {}]", inner_type, count.val()) + } + (TypeInfo::Custom { .. }, _) => { + format!("generic {}", type_engine.get(*self).abi_str(ctx, engines)) + } + _ => type_engine.get(resolved_type_id).abi_str(ctx, engines), + } + } + } +} + +impl TypeInfo { + pub fn abi_str(&self, ctx: &AbiStrContext, engines: &Engines) -> String { + use TypeInfo::*; + let decl_engine = engines.de(); + let type_engine = engines.te(); + match self { + Unknown => "unknown".into(), + Never => "never".into(), + UnknownGeneric { name, .. } => name.to_string(), + Placeholder(_) => "_".to_string(), + TypeParam(n) => format!("typeparam({n})"), + StringSlice => "str".into(), + StringArray(x) => format!("str[{}]", x.val()), + UnsignedInteger(x) => match x { + IntegerBits::Eight => "u8", + IntegerBits::Sixteen => "u16", + IntegerBits::ThirtyTwo => "u32", + IntegerBits::SixtyFour => "u64", + IntegerBits::V256 => "u256", + } + .into(), + Boolean => "bool".into(), + Custom { + qualified_call_path: call_path, + .. + } => call_path.call_path.suffix.to_string(), + Tuple(fields) => { + let field_strs = fields + .iter() + .map(|field| field.abi_str(ctx, engines)) + .collect::>(); + format!("({})", field_strs.join(", ")) + } + B256 => "b256".into(), + Numeric => "u64".into(), // u64 is the default + Contract => "contract".into(), + ErrorRecovery(_) => "unknown due to error".into(), + 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() { + "".into() + } else { + format!( + "<{}>", + decl.type_parameters + .iter() + .map(|p| type_engine.get(p.type_id).abi_str(ctx, engines)) + .collect::>() + .join(",") + ) + }; + format!( + "enum {}{}", + call_path_display(ctx, &decl.call_path), + type_params + ) + } + 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() { + "".into() + } else { + format!( + "<{}>", + decl.type_parameters + .iter() + .map(|p| type_engine.get(p.type_id).abi_str(ctx, engines)) + .collect::>() + .join(",") + ) + }; + format!( + "struct {}{}", + call_path_display(ctx, &decl.call_path), + type_params + ) + } + ContractCaller { abi_name, .. } => { + format!("contract caller {abi_name}") + } + Array(elem_ty, length) => { + format!("[{}; {}]", elem_ty.abi_str(ctx, engines), length.val()) + } + Storage { .. } => "contract storage".into(), + RawUntypedPtr => "raw untyped ptr".into(), + RawUntypedSlice => "raw untyped slice".into(), + Ptr(ty) => { + format!("__ptr {}", ty.abi_str(ctx, engines)) + } + Slice(ty) => { + format!("__slice {}", ty.abi_str(ctx, engines)) + } + Alias { ty, .. } => ty.abi_str(ctx, engines), + TraitType { + name, + trait_type_id: _, + } => format!("trait type {}", name), + Ref { + to_mutable_value, + referenced_type, + } => { + format!( + "__ref {}{}", // TODO-IG: No references in ABIs according to the RFC. Or we want to have them? + if *to_mutable_value { "mut " } else { "" }, + referenced_type.abi_str(ctx, engines) + ) + } + } + } +} + +/// `call_path_display` returns the provided `call_path` without the first prefix in case it is equal to the program name. +/// If the program name is `my_program` and the `call_path` is `my_program::MyStruct` then this function returns only `MyStruct`. +fn call_path_display(ctx: &AbiStrContext, call_path: &CallPath) -> String { + if !ctx.abi_with_callpaths { + return call_path.suffix.as_str().to_string(); + } + let mut buf = String::new(); + for (index, prefix) in call_path.prefixes.iter().enumerate() { + let mut skip_prefix = false; + if index == 0 { + if let Some(root_name) = &ctx.program_name { + if prefix.as_str() == root_name.as_str() { + skip_prefix = true; + } + } + } + if !skip_prefix { + buf.push_str(prefix.as_str()); + buf.push_str("::"); + } + } + buf.push_str(&call_path.suffix.to_string()); + + buf +} + +impl TypeArgument { + pub(self) fn abi_str(&self, ctx: &AbiStrContext, engines: &Engines) -> String { + engines.te().get(self.type_id).abi_str(ctx, engines) + } +} diff --git a/sway-core/src/abi_generation/fuel_abi.rs b/sway-core/src/abi_generation/fuel_abi.rs index dacce5d05d8..6a306b43228 100644 --- a/sway-core/src/abi_generation/fuel_abi.rs +++ b/sway-core/src/abi_generation/fuel_abi.rs @@ -1,20 +1,38 @@ use fuel_abi_types::abi::program as program_abi; -use sway_types::integer_bits::IntegerBits; +use std::collections::HashSet; use crate::{ - language::{ - ty::{TyConstantDecl, TyFunctionDecl, TyProgram, TyProgramKind}, - CallPath, - }, + language::ty::{TyConstantDecl, TyFunctionDecl, TyProgram, TyProgramKind}, transform::AttributesMap, - Engines, TypeArgument, TypeId, TypeInfo, TypeParameter, + Engines, TypeId, TypeInfo, TypeParameter, }; +use super::abi_str::AbiStrContext; + pub struct AbiContext<'a> { pub program: &'a TyProgram, pub abi_with_callpaths: bool, } +impl<'a> AbiContext<'a> { + fn to_str_context( + &self, + engines: &Engines, + abi_with_fully_specified_types: bool, + ) -> AbiStrContext { + AbiStrContext { + program_name: self + .program + .root + .namespace + .module_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, + } + } +} + pub fn generate_program_abi( ctx: &mut AbiContext, engines: &Engines, @@ -82,7 +100,11 @@ fn generate_logged_types( .iter() .map(|(_, type_id)| program_abi::TypeDeclaration { type_id: type_id.index(), - type_field: type_id.get_abi_type_str(ctx, engines, *type_id), + type_field: type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + *type_id, + ), components: type_id.get_abi_type_components(ctx, engines, types, *type_id), type_parameters: type_id.get_abi_type_parameters(ctx, engines, types, *type_id), }) @@ -92,16 +114,26 @@ fn generate_logged_types( types.extend(logged_types); // Generate the JSON data for the logged types + let mut log_ids: HashSet = HashSet::default(); ctx.program .logged_types .iter() - .map(|(log_id, type_id)| program_abi::LoggedType { - log_id: log_id.to_string(), - application: program_abi::TypeApplication { - name: "".to_string(), - type_id: type_id.index(), - type_arguments: type_id.get_abi_type_arguments(ctx, engines, types, *type_id), - }, + .filter_map(|(log_id, type_id)| { + let log_id = log_id.hash_id; + if log_ids.contains(&log_id) { + None + } else { + log_ids.insert(log_id); + Some(program_abi::LoggedType { + log_id: log_id.to_string(), + application: program_abi::TypeApplication { + name: "".to_string(), + type_id: type_id.index(), + type_arguments: type_id + .get_abi_type_arguments(ctx, engines, types, *type_id), + }, + }) + } }) .collect() } @@ -118,7 +150,11 @@ fn generate_messages_types( .iter() .map(|(_, type_id)| program_abi::TypeDeclaration { type_id: type_id.index(), - type_field: type_id.get_abi_type_str(ctx, engines, *type_id), + type_field: type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + *type_id, + ), components: type_id.get_abi_type_components(ctx, engines, types, *type_id), type_parameters: type_id.get_abi_type_parameters(ctx, engines, types, *type_id), }) @@ -158,7 +194,7 @@ fn generate_configurables( }| program_abi::TypeDeclaration { type_id: type_ascription.type_id.index(), type_field: type_ascription.type_id.get_abi_type_str( - ctx, + &ctx.to_str_context(engines, false), engines, type_ascription.type_id, ), @@ -209,50 +245,6 @@ fn generate_configurables( } impl TypeId { - /// Gives back a string that represents the type, considering what it resolves to - pub(self) fn get_abi_type_str( - &self, - ctx: &mut AbiContext, - engines: &Engines, - resolved_type_id: TypeId, - ) -> String { - let type_engine = engines.te(); - if self.is_generic_parameter(engines, resolved_type_id) { - format!("generic {}", type_engine.get(*self).abi_str(ctx, engines)) - } else { - match ( - &*type_engine.get(*self), - &*type_engine.get(resolved_type_id), - ) { - (TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => { - type_engine.get(resolved_type_id).abi_str(ctx, engines) - } - (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => { - type_engine.get(resolved_type_id).abi_str(ctx, engines) - } - (TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => { - type_engine.get(resolved_type_id).abi_str(ctx, engines) - } - (TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => { - assert_eq!(fields.len(), resolved_fields.len()); - let field_strs = fields - .iter() - .map(|_| "_".to_string()) - .collect::>(); - format!("({})", field_strs.join(", ")) - } - (TypeInfo::Array(_, count), TypeInfo::Array(_, resolved_count)) => { - assert_eq!(count.val(), resolved_count.val()); - format!("[_; {}]", count.val()) - } - (TypeInfo::Custom { .. }, _) => { - format!("generic {}", type_engine.get(*self).abi_str(ctx, engines)) - } - _ => type_engine.get(resolved_type_id).abi_str(ctx, engines), - } - } - } - /// Return the type parameters of a given (potentially generic) type while considering what it /// actually resolves to. These parameters are essentially of type of `usize` which are /// basically the IDs of some set of `program_abi::TypeDeclaration`s. The method below also @@ -297,7 +289,7 @@ impl TypeId { .map(|x| program_abi::TypeDeclaration { type_id: x.type_argument.initial_type_id.index(), type_field: x.type_argument.initial_type_id.get_abi_type_str( - ctx, + &ctx.to_str_context(engines, false), engines, x.type_argument.type_id, ), @@ -345,7 +337,7 @@ impl TypeId { .map(|x| program_abi::TypeDeclaration { type_id: x.type_argument.initial_type_id.index(), type_field: x.type_argument.initial_type_id.get_abi_type_str( - ctx, + &ctx.to_str_context(engines, false), engines, x.type_argument.type_id, ), @@ -389,7 +381,7 @@ impl TypeId { let elem_abi_ty = program_abi::TypeDeclaration { type_id: elem_ty.initial_type_id.index(), type_field: elem_ty.initial_type_id.get_abi_type_str( - ctx, + &ctx.to_str_context(engines, false), engines, elem_ty.type_id, ), @@ -431,7 +423,11 @@ impl TypeId { .iter() .map(|x| program_abi::TypeDeclaration { type_id: x.initial_type_id.index(), - type_field: x.initial_type_id.get_abi_type_str(ctx, engines, x.type_id), + type_field: x.initial_type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + x.type_id, + ), components: x .initial_type_id .get_abi_type_components(ctx, engines, types, x.type_id), @@ -476,7 +472,11 @@ impl TypeId { ) .map(|(v, p)| program_abi::TypeDeclaration { type_id: v.initial_type_id.index(), - type_field: v.initial_type_id.get_abi_type_str(ctx, engines, p.type_id), + type_field: v.initial_type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + p.type_id, + ), components: v .initial_type_id .get_abi_type_components(ctx, engines, types, p.type_id), @@ -537,7 +537,11 @@ impl TypeId { .zip(resolved_params.iter()) .map(|(v, p)| program_abi::TypeDeclaration { type_id: v.initial_type_id.index(), - type_field: v.initial_type_id.get_abi_type_str(ctx, engines, p.type_id), + type_field: v.initial_type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + p.type_id, + ), components: v .initial_type_id .get_abi_type_components(ctx, engines, types, p.type_id), @@ -570,7 +574,11 @@ impl TypeId { .iter() .map(|v| program_abi::TypeDeclaration { type_id: v.type_id.index(), - type_field: v.type_id.get_abi_type_str(ctx, engines, v.type_id), + type_field: v.type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + v.type_id, + ), components: v .type_id .get_abi_type_components(ctx, engines, types, v.type_id), @@ -606,7 +614,11 @@ impl TypeId { .iter() .map(|v| program_abi::TypeDeclaration { type_id: v.type_id.index(), - type_field: v.type_id.get_abi_type_str(ctx, engines, v.type_id), + type_field: v.type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + v.type_id, + ), components: v .type_id .get_abi_type_components(ctx, engines, types, v.type_id), @@ -638,119 +650,6 @@ impl TypeId { } } -impl TypeInfo { - pub fn abi_str(&self, ctx: &mut AbiContext, engines: &Engines) -> String { - use TypeInfo::*; - let decl_engine = engines.de(); - match self { - Unknown => "unknown".into(), - Never => "never".into(), - UnknownGeneric { name, .. } => name.to_string(), - Placeholder(_) => "_".to_string(), - TypeParam(n) => format!("typeparam({n})"), - StringSlice => "str".into(), - StringArray(x) => format!("str[{}]", x.val()), - UnsignedInteger(x) => match x { - IntegerBits::Eight => "u8", - IntegerBits::Sixteen => "u16", - IntegerBits::ThirtyTwo => "u32", - IntegerBits::SixtyFour => "u64", - IntegerBits::V256 => "u256", - } - .into(), - Boolean => "bool".into(), - Custom { - qualified_call_path: call_path, - .. - } => call_path.call_path.suffix.to_string(), - Tuple(fields) => { - let field_strs = fields - .iter() - .map(|field| field.abi_str(ctx, engines)) - .collect::>(); - format!("({})", field_strs.join(", ")) - } - B256 => "b256".into(), - Numeric => "u64".into(), // u64 is the default - Contract => "contract".into(), - ErrorRecovery(_) => "unknown due to error".into(), - Enum(decl_ref) => { - let decl = decl_engine.get_enum(decl_ref); - format!("enum {}", call_path_display(ctx, engines, &decl.call_path)) - } - Struct(decl_ref) => { - let decl = decl_engine.get_struct(decl_ref); - format!( - "struct {}", - call_path_display(ctx, engines, &decl.call_path) - ) - } - ContractCaller { abi_name, .. } => { - format!("contract caller {abi_name}") - } - Array(elem_ty, length) => { - format!("[{}; {}]", elem_ty.abi_str(ctx, engines), length.val()) - } - Storage { .. } => "contract storage".into(), - RawUntypedPtr => "raw untyped ptr".into(), - RawUntypedSlice => "raw untyped slice".into(), - Ptr(ty) => { - format!("__ptr {}", ty.abi_str(ctx, engines)) - } - Slice(ty) => { - format!("__slice {}", ty.abi_str(ctx, engines)) - } - Alias { ty, .. } => ty.abi_str(ctx, engines), - TraitType { - name, - trait_type_id: _, - } => format!("trait type {}", name), - Ref { - to_mutable_value, - referenced_type, - } => { - format!( - "__ref {}{}", // TODO-IG: No references in ABIs according to the RFC. Or we want to have them? - if *to_mutable_value { "mut " } else { "" }, - referenced_type.abi_str(ctx, engines) - ) - } - } - } -} - -/// `call_path_display` returns the provided `call_path` without the first prefix in case it is equal to the program name. -/// If the program name is `my_program` and the `call_path` is `my_program::MyStruct` then this function returns only `MyStruct`. -fn call_path_display(ctx: &mut AbiContext, engines: &Engines, call_path: &CallPath) -> String { - if !ctx.abi_with_callpaths { - return call_path.suffix.as_str().to_string(); - } - let mut buf = String::new(); - for (index, prefix) in call_path.prefixes.iter().enumerate() { - let mut skip_prefix = false; - if index == 0 { - if let Some(root_name) = &ctx - .program - .root - .namespace - .module_id(engines) - .read(engines, |m| m.name.clone()) - { - if prefix.as_str() == root_name.as_str() { - skip_prefix = true; - } - } - } - if !skip_prefix { - buf.push_str(prefix.as_str()); - buf.push_str("::"); - } - } - buf.push_str(&call_path.suffix.to_string()); - - buf -} - impl TyFunctionDecl { pub(self) fn generate_abi_function( &self, @@ -765,7 +664,7 @@ impl TyFunctionDecl { .map(|x| program_abi::TypeDeclaration { type_id: x.type_argument.initial_type_id.index(), type_field: x.type_argument.initial_type_id.get_abi_type_str( - ctx, + &ctx.to_str_context(engines, false), engines, x.type_argument.type_id, ), @@ -788,7 +687,7 @@ impl TyFunctionDecl { let output_type = program_abi::TypeDeclaration { type_id: self.return_type.initial_type_id.index(), type_field: self.return_type.initial_type_id.get_abi_type_str( - ctx, + &ctx.to_str_context(engines, false), engines, self.return_type.type_id, ), @@ -871,9 +770,11 @@ impl TypeParameter { ) -> usize { let type_parameter = program_abi::TypeDeclaration { type_id: self.initial_type_id.index(), - type_field: self - .initial_type_id - .get_abi_type_str(ctx, engines, self.type_id), + type_field: self.initial_type_id.get_abi_type_str( + &ctx.to_str_context(engines, false), + engines, + self.type_id, + ), components: self.initial_type_id.get_abi_type_components( ctx, engines, @@ -886,9 +787,3 @@ impl TypeParameter { self.initial_type_id.index() } } - -impl TypeArgument { - pub(self) fn abi_str(&self, ctx: &mut AbiContext, engines: &Engines) -> String { - engines.te().get(self.type_id).abi_str(ctx, engines) - } -} diff --git a/sway-core/src/abi_generation/mod.rs b/sway-core/src/abi_generation/mod.rs index 33b6c8c3885..6a639f25ffc 100644 --- a/sway-core/src/abi_generation/mod.rs +++ b/sway-core/src/abi_generation/mod.rs @@ -1,2 +1,3 @@ +pub mod abi_str; pub mod evm_abi; pub mod fuel_abi; diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index 485c8284f35..e433f9ee6e5 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -1172,7 +1172,7 @@ impl<'eng> FnCompiler<'eng> { )); } Some(log_id) => { - convert_literal_to_value(context, &Literal::U64(**log_id as u64)) + convert_literal_to_value(context, &Literal::U64(log_id.hash_id)) } }; diff --git a/sway-core/src/language/ty/expression/intrinsic_function.rs b/sway-core/src/language/ty/expression/intrinsic_function.rs index 008090960e6..a82ec310f9f 100644 --- a/sway-core/src/language/ty/expression/intrinsic_function.rs +++ b/sway-core/src/language/ty/expression/intrinsic_function.rs @@ -3,7 +3,10 @@ use std::{ hash::{Hash, Hasher}, }; -use crate::{engine_threading::*, has_changes, language::ty::*, type_system::*, types::*}; +use crate::{ + abi_generation::abi_str::AbiStrContext, engine_threading::*, has_changes, language::ty::*, + type_system::*, types::*, +}; use itertools::Itertools; use sway_ast::Intrinsic; use sway_error::handler::{ErrorEmitted, Handler}; @@ -113,10 +116,17 @@ impl CollectTypesMetadata for TyIntrinsicFunctionKind { Intrinsic::Log => { let logged_type = self.get_logged_type(ctx.experimental.new_encoding).unwrap(); types_metadata.push(TypeMetadata::LoggedType( - LogId::new(ctx.log_id_counter()), + LogId::new(logged_type.get_abi_type_str( + &AbiStrContext { + program_name: Some(ctx.program_name.clone()), + abi_with_callpaths: true, + abi_with_fully_specified_types: true, + }, + ctx.engines, + logged_type, + )), logged_type, )); - *ctx.log_id_counter_mut() += 1; } Intrinsic::Smo => { types_metadata.push(TypeMetadata::MessageType( diff --git a/sway-core/src/lib.rs b/sway-core/src/lib.rs index 8acfb492ae4..48ba813803a 100644 --- a/sway-core/src/lib.rs +++ b/sway-core/src/lib.rs @@ -577,7 +577,7 @@ pub fn parsed_to_ast( // Collect information about the types used in this program let types_metadata_result = typed_program.collect_types_metadata( handler, - &mut CollectTypesMetadataContext::new(engines, experimental), + &mut CollectTypesMetadataContext::new(engines, experimental, package_name.to_string()), ); let types_metadata = match types_metadata_result { Ok(types_metadata) => types_metadata, diff --git a/sway-core/src/types/collect_types_metadata.rs b/sway-core/src/types/collect_types_metadata.rs index 98f36a8ade9..7f535787f9a 100644 --- a/sway-core/src/types/collect_types_metadata.rs +++ b/sway-core/src/types/collect_types_metadata.rs @@ -9,6 +9,7 @@ use std::{ }; use crate::{type_system::TypeId, Engines, ExperimentalFlags}; +use sha2::{Digest, Sha256}; use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{Ident, Span}; @@ -16,18 +17,17 @@ use sway_types::{Ident, Span}; /// error to signal to the user that more type information is needed. #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] -pub struct LogId(usize); - -impl std::ops::Deref for LogId { - type Target = usize; - fn deref(&self) -> &Self::Target { - &self.0 - } +pub struct LogId { + pub hash_id: u64, } impl LogId { - pub fn new(index: usize) -> LogId { - LogId(index) + pub fn new(string: String) -> LogId { + let mut hasher = Sha256::new(); + hasher.update(string); + let result = hasher.finalize(); + let hash_id = u64::from_be_bytes(result[0..8].try_into().unwrap()); + LogId { hash_id } } } @@ -60,10 +60,6 @@ pub enum TypeMetadata { // A simple context that only contains a single counter for now but may expand in the future. pub struct CollectTypesMetadataContext<'cx> { - // Consume this and update it via the methods implemented for CollectTypesMetadataContext to - // obtain a unique ID for a given log instance. - log_id_counter: usize, - // Consume this and update it via the methods implemented for CollectTypesMetadataContext to // obtain a unique ID for a given smo instance. message_id_counter: usize, @@ -71,18 +67,12 @@ pub struct CollectTypesMetadataContext<'cx> { call_site_spans: Vec>>>, pub(crate) engines: &'cx Engines, + pub(crate) program_name: String, + pub experimental: ExperimentalFlags, } impl<'cx> CollectTypesMetadataContext<'cx> { - pub fn log_id_counter(&self) -> usize { - self.log_id_counter - } - - pub fn log_id_counter_mut(&mut self) -> &mut usize { - &mut self.log_id_counter - } - pub fn message_id_counter(&self) -> usize { self.message_id_counter } @@ -119,13 +109,17 @@ impl<'cx> CollectTypesMetadataContext<'cx> { None } - pub fn new(engines: &'cx Engines, experimental: ExperimentalFlags) -> Self { + pub fn new( + engines: &'cx Engines, + experimental: ExperimentalFlags, + program_name: String, + ) -> Self { let mut ctx = Self { engines, - log_id_counter: 0, message_id_counter: 0, call_site_spans: vec![], experimental, + program_name, }; ctx.call_site_push(); ctx diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json index 0b18428deec..cd1346b7e0d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json @@ -88,7 +88,7 @@ "typeArguments": null }, "name": "BOOL", - "offset": 13544 + "offset": 13552 }, { "configurableType": { @@ -97,7 +97,7 @@ "typeArguments": null }, "name": "U8", - "offset": 13552 + "offset": 13560 }, { "configurableType": { @@ -106,7 +106,7 @@ "typeArguments": null }, "name": "ANOTHERU8", - "offset": 13568 + "offset": 13576 }, { "configurableType": { @@ -115,7 +115,7 @@ "typeArguments": null }, "name": "U16", - "offset": 13576 + "offset": 13584 }, { "configurableType": { @@ -124,7 +124,7 @@ "typeArguments": null }, "name": "U32", - "offset": 13584 + "offset": 13592 }, { "configurableType": { @@ -133,7 +133,7 @@ "typeArguments": null }, "name": "U64", - "offset": 13600 + "offset": 13608 }, { "configurableType": { @@ -142,7 +142,7 @@ "typeArguments": null }, "name": "U256", - "offset": 13616 + "offset": 13624 }, { "configurableType": { @@ -178,7 +178,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "3330666440490685604", "loggedType": { "name": "", "type": 0, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle.json index 018c52f800b..31808c4fd24 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": null, @@ -7,44 +8,36 @@ "name": "main", "output": { "name": "", - "type": 14, + "type": 13, "typeArguments": null } } ], "loggedTypes": [ { - "logId": 0, + "logId": "4579537983717831593", "loggedType": { "name": "", - "type": 7, + "type": 6, "typeArguments": [] } }, { - "logId": 1, + "logId": "16566583104751091389", "loggedType": { "name": "", - "type": 8, + "type": 7, "typeArguments": [ { "name": "", - "type": 14, + "type": 13, "typeArguments": null } ] } }, { - "logId": 2, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": [] - } - }, - { - "logId": 3, + "logId": "5087777005172090899", "loggedType": { "name": "", "type": 1, @@ -52,28 +45,12 @@ } }, { - "logId": 4, + "logId": "5555909392781521367", "loggedType": { "name": "", "type": 5, "typeArguments": [] } - }, - { - "logId": 5, - "loggedType": { - "name": "", - "type": 6, - "typeArguments": [] - } - }, - { - "logId": 6, - "loggedType": { - "name": "", - "type": 6, - "typeArguments": [] - } } ], "messagesTypes": [], @@ -88,11 +65,11 @@ "components": [ { "name": "A", - "type": 8, + "type": 7, "typeArguments": [ { "name": "", - "type": 14, + "type": 13, "typeArguments": null } ] @@ -131,47 +108,35 @@ "typeId": 5, "typeParameters": null }, - { - "components": [ - { - "name": "p", - "type": 3, - "typeArguments": null - } - ], - "type": "struct NotAutoEncodable", - "typeId": 6, - "typeParameters": null - }, { "components": [ { "name": "a", - "type": 14, + "type": 13, "typeArguments": null }, { "name": "b", - "type": 13, + "type": 12, "typeArguments": null }, { "name": "c", - "type": 11, + "type": 10, "typeArguments": null }, { "name": "d", - "type": 15, + "type": 14, "typeArguments": null }, { "name": "e", - "type": 10, + "type": 9, "typeArguments": [ { "name": "", - "type": 14, + "type": 13, "typeArguments": null } ] @@ -183,12 +148,12 @@ }, { "name": "g", - "type": 12, + "type": 11, "typeArguments": null } ], "type": "struct S", - "typeId": 7, + "typeId": 6, "typeParameters": null }, { @@ -200,7 +165,7 @@ } ], "type": "struct SS", - "typeId": 8, + "typeId": 7, "typeParameters": [ 2 ] @@ -214,12 +179,12 @@ }, { "name": "cap", - "type": 14, + "type": 13, "typeArguments": null } ], "type": "struct std::vec::RawVec", - "typeId": 9, + "typeId": 8, "typeParameters": [ 2 ] @@ -228,7 +193,7 @@ "components": [ { "name": "buf", - "type": 9, + "type": 8, "typeArguments": [ { "name": "", @@ -239,12 +204,12 @@ }, { "name": "len", - "type": 14, + "type": 13, "typeArguments": null } ], "type": "struct std::vec::Vec", - "typeId": 10, + "typeId": 9, "typeParameters": [ 2 ] @@ -252,32 +217,32 @@ { "components": null, "type": "u16", - "typeId": 11, + "typeId": 10, "typeParameters": null }, { "components": null, "type": "u256", - "typeId": 12, + "typeId": 11, "typeParameters": null }, { "components": null, "type": "u32", - "typeId": 13, + "typeId": 12, "typeParameters": null }, { "components": null, "type": "u64", - "typeId": 14, + "typeId": 13, "typeParameters": null }, { "components": null, "type": "u8", - "typeId": 15, + "typeId": 14, "typeParameters": null } ] -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle_new_encoding.json index a78c79ca85b..8af65bf6ec9 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/logging/json_abi_oracle_new_encoding.json @@ -15,7 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "4579537983717831593", "loggedType": { "name": "", "type": 6, @@ -23,7 +23,7 @@ } }, { - "logId": "1", + "logId": "16566583104751091389", "loggedType": { "name": "", "type": 7, @@ -37,7 +37,7 @@ } }, { - "logId": "2", + "logId": "5087777005172090899", "loggedType": { "name": "", "type": 1, @@ -45,15 +45,7 @@ } }, { - "logId": "3", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": [] - } - }, - { - "logId": "4", + "logId": "5555909392781521367", "loggedType": { "name": "", "type": 5, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle.json index 3840c0a2167..5e63ac8b192 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": null, @@ -20,7 +21,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "3647243719605075626", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle_new_encoding.json index 8af5dcf2fd7..09b704fef9b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_various_types/json_abi_oracle_new_encoding.json @@ -21,7 +21,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "3647243719605075626", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle.json index 61bbbdb56ad..84af75c5966 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": null, @@ -14,7 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "10098701174489624218", "loggedType": { "name": "", "type": 7, @@ -22,7 +23,7 @@ } }, { - "logId": "1", + "logId": "3297216108266379291", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle_new_encoding.json index 6dae8fdfb85..27b39b8702e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/smo/json_abi_oracle_new_encoding.json @@ -15,7 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "10098701174489624218", "loggedType": { "name": "", "type": 7, @@ -23,7 +23,7 @@ } }, { - "logId": "1", + "logId": "3297216108266379291", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json index 35c57836f81..22c561c616d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json @@ -7,7 +7,7 @@ "typeArguments": null }, "name": "SOME_U256", - "offset": 752 + "offset": 768 } ], "encoding": "1", @@ -25,7 +25,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "1970142151624111756", "loggedType": { "name": "", "type": 0, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw index 0b556e8d4b3..0dc56193dd0 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw @@ -4,7 +4,7 @@ use basic_storage_abi::{BasicStorage, Quad}; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x5c0aef0c1af7601aa6b9fa0fc9efff0e956dcb93f855788222e172e67e717072; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xfa9b40cf5517d1f023ad92bfc9c9ffc0b1c54ab32624958f3a2f63a3c1d5d88e; +const CONTRACT_ID = 0x37cdef21aab78b40f27486172cd39a320539de08b625e22d877e2bed6b826250; fn main() -> u64 { let addr = abi(BasicStorage, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw index 9e16ee2fd46..2a031d2ca34 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw @@ -6,7 +6,7 @@ use std::hash::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x0a58692bee60559887f0ac181c8a3b14ffb7a3a66256eec3f08e3135bfbecac9; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0x0ad5888677d51f65200c75f463b0740bcb64e3d33a92b6e7326694de7b5a2151; +const CONTRACT_ID = 0x8ae216e6df492a4a983c34c5871bbe84c6aafa70fa25f1d76b771d8c8a72a1d7; fn main() -> bool { let caller = abi(StorageAccess, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq/json_abi_oracle_new_encoding.json index 38c7a317d91..b50fc6cfd6b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq/json_abi_oracle_new_encoding.json @@ -15,7 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 12, @@ -23,15 +23,7 @@ } }, { - "logId": "1", - "loggedType": { - "name": "", - "type": 12, - "typeArguments": null - } - }, - { - "logId": "2", + "logId": "15520703124961489725", "loggedType": { "name": "", "type": 11, @@ -39,23 +31,7 @@ } }, { - "logId": "3", - "loggedType": { - "name": "", - "type": 11, - "typeArguments": null - } - }, - { - "logId": "4", - "loggedType": { - "name": "", - "type": 10, - "typeArguments": null - } - }, - { - "logId": "5", + "logId": "2992671284987479467", "loggedType": { "name": "", "type": 10, @@ -63,7 +39,7 @@ } }, { - "logId": "6", + "logId": "14454674236531057292", "loggedType": { "name": "", "type": 13, @@ -71,15 +47,7 @@ } }, { - "logId": "7", - "loggedType": { - "name": "", - "type": 13, - "typeArguments": null - } - }, - { - "logId": "8", + "logId": "8961848586872524460", "loggedType": { "name": "", "type": 1, @@ -87,23 +55,7 @@ } }, { - "logId": "9", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "10", - "loggedType": { - "name": "", - "type": 5, - "typeArguments": [] - } - }, - { - "logId": "11", + "logId": "17696813611398264200", "loggedType": { "name": "", "type": 5, @@ -111,7 +63,7 @@ } }, { - "logId": "12", + "logId": "3008693953818743129", "loggedType": { "name": "", "type": 9, @@ -119,15 +71,7 @@ } }, { - "logId": "13", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": [] - } - }, - { - "logId": "14", + "logId": "14832741149864513620", "loggedType": { "name": "", "type": 7, @@ -135,23 +79,7 @@ } }, { - "logId": "15", - "loggedType": { - "name": "", - "type": 7, - "typeArguments": [] - } - }, - { - "logId": "16", - "loggedType": { - "name": "", - "type": 6, - "typeArguments": [] - } - }, - { - "logId": "17", + "logId": "8385180437869151632", "loggedType": { "name": "", "type": 6, @@ -159,31 +87,7 @@ } }, { - "logId": "18", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": "19", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": "20", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": "21", + "logId": "12356980511120185571", "loggedType": { "name": "", "type": 3, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle.json index bf820505563..9ca357a7795 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": null, @@ -14,15 +15,7 @@ ], "loggedTypes": [ { - "logId": 0, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 1, + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 1, @@ -45,4 +38,4 @@ "typeParameters": null } ] -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle_new_encoding.json index 2bef9193fd0..17f3d600e0d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_eq_revert/json_abi_oracle_new_encoding.json @@ -15,15 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "1", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle.json index 57d2aa0915a..3ac7b87f28a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": null, @@ -14,7 +15,7 @@ ], "loggedTypes": [ { - "logId": 0, + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 12, @@ -22,15 +23,7 @@ } }, { - "logId": 1, - "loggedType": { - "name": "", - "type": 12, - "typeArguments": null - } - }, - { - "logId": 2, + "logId": "15520703124961489725", "loggedType": { "name": "", "type": 11, @@ -38,23 +31,7 @@ } }, { - "logId": 3, - "loggedType": { - "name": "", - "type": 11, - "typeArguments": null - } - }, - { - "logId": 4, - "loggedType": { - "name": "", - "type": 10, - "typeArguments": null - } - }, - { - "logId": 5, + "logId": "2992671284987479467", "loggedType": { "name": "", "type": 10, @@ -62,7 +39,7 @@ } }, { - "logId": 6, + "logId": "14454674236531057292", "loggedType": { "name": "", "type": 13, @@ -70,15 +47,7 @@ } }, { - "logId": 7, - "loggedType": { - "name": "", - "type": 13, - "typeArguments": null - } - }, - { - "logId": 8, + "logId": "8961848586872524460", "loggedType": { "name": "", "type": 1, @@ -86,23 +55,7 @@ } }, { - "logId": 9, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 10, - "loggedType": { - "name": "", - "type": 5, - "typeArguments": [] - } - }, - { - "logId": 11, + "logId": "17696813611398264200", "loggedType": { "name": "", "type": 5, @@ -110,7 +63,7 @@ } }, { - "logId": 12, + "logId": "3008693953818743129", "loggedType": { "name": "", "type": 9, @@ -118,15 +71,7 @@ } }, { - "logId": 13, - "loggedType": { - "name": "", - "type": 9, - "typeArguments": [] - } - }, - { - "logId": 14, + "logId": "14832741149864513620", "loggedType": { "name": "", "type": 7, @@ -134,23 +79,7 @@ } }, { - "logId": 15, - "loggedType": { - "name": "", - "type": 7, - "typeArguments": [] - } - }, - { - "logId": 16, - "loggedType": { - "name": "", - "type": 6, - "typeArguments": [] - } - }, - { - "logId": 17, + "logId": "8385180437869151632", "loggedType": { "name": "", "type": 6, @@ -158,31 +87,7 @@ } }, { - "logId": 18, - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": 19, - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": 20, - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": 21, + "logId": "12356980511120185571", "loggedType": { "name": "", "type": 3, @@ -334,4 +239,4 @@ "typeParameters": null } ] -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle_new_encoding.json index 38c7a317d91..b50fc6cfd6b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne/json_abi_oracle_new_encoding.json @@ -15,7 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 12, @@ -23,15 +23,7 @@ } }, { - "logId": "1", - "loggedType": { - "name": "", - "type": 12, - "typeArguments": null - } - }, - { - "logId": "2", + "logId": "15520703124961489725", "loggedType": { "name": "", "type": 11, @@ -39,23 +31,7 @@ } }, { - "logId": "3", - "loggedType": { - "name": "", - "type": 11, - "typeArguments": null - } - }, - { - "logId": "4", - "loggedType": { - "name": "", - "type": 10, - "typeArguments": null - } - }, - { - "logId": "5", + "logId": "2992671284987479467", "loggedType": { "name": "", "type": 10, @@ -63,7 +39,7 @@ } }, { - "logId": "6", + "logId": "14454674236531057292", "loggedType": { "name": "", "type": 13, @@ -71,15 +47,7 @@ } }, { - "logId": "7", - "loggedType": { - "name": "", - "type": 13, - "typeArguments": null - } - }, - { - "logId": "8", + "logId": "8961848586872524460", "loggedType": { "name": "", "type": 1, @@ -87,23 +55,7 @@ } }, { - "logId": "9", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "10", - "loggedType": { - "name": "", - "type": 5, - "typeArguments": [] - } - }, - { - "logId": "11", + "logId": "17696813611398264200", "loggedType": { "name": "", "type": 5, @@ -111,7 +63,7 @@ } }, { - "logId": "12", + "logId": "3008693953818743129", "loggedType": { "name": "", "type": 9, @@ -119,15 +71,7 @@ } }, { - "logId": "13", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": [] - } - }, - { - "logId": "14", + "logId": "14832741149864513620", "loggedType": { "name": "", "type": 7, @@ -135,23 +79,7 @@ } }, { - "logId": "15", - "loggedType": { - "name": "", - "type": 7, - "typeArguments": [] - } - }, - { - "logId": "16", - "loggedType": { - "name": "", - "type": 6, - "typeArguments": [] - } - }, - { - "logId": "17", + "logId": "8385180437869151632", "loggedType": { "name": "", "type": 6, @@ -159,31 +87,7 @@ } }, { - "logId": "18", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": "19", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": "20", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": [] - } - }, - { - "logId": "21", + "logId": "12356980511120185571", "loggedType": { "name": "", "type": 3, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle.json index bf820505563..9ca357a7795 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": null, @@ -14,15 +15,7 @@ ], "loggedTypes": [ { - "logId": 0, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 1, + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 1, @@ -45,4 +38,4 @@ "typeParameters": null } ] -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle_new_encoding.json index 2bef9193fd0..17f3d600e0d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/assert_ne_revert/json_abi_oracle_new_encoding.json @@ -15,15 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "1", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/require/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/require/json_abi_oracle_new_encoding.json index a5f01797ee6..3c87c103235 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/require/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/require/json_abi_oracle_new_encoding.json @@ -15,7 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 3, @@ -23,39 +23,7 @@ } }, { - "logId": "1", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": null - } - }, - { - "logId": "2", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": null - } - }, - { - "logId": "3", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": null - } - }, - { - "logId": "4", - "loggedType": { - "name": "", - "type": 3, - "typeArguments": null - } - }, - { - "logId": "5", + "logId": "12587658342658067091", "loggedType": { "name": "", "type": 2, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.json index 290d04e8b24..ec0a0a7addf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": [ @@ -198,7 +199,7 @@ ], "loggedTypes": [ { - "logId": 0, + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 9, @@ -206,39 +207,7 @@ } }, { - "logId": 1, - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": 2, - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": 3, - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": 4, - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": 5, + "logId": "1970142151624111756", "loggedType": { "name": "", "type": 8, @@ -246,47 +215,7 @@ } }, { - "logId": 6, - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": 7, - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": 8, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 9, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 10, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 11, + "logId": "8961848586872524460", "loggedType": { "name": "", "type": 1, @@ -423,4 +352,4 @@ "typeParameters": null } ] -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle_new_encoding.json index 61dba718076..8e817c80160 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle_new_encoding.json @@ -199,7 +199,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 9, @@ -207,55 +207,7 @@ } }, { - "logId": "1", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "2", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "3", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "4", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "5", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "6", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "7", + "logId": "1970142151624111756", "loggedType": { "name": "", "type": 8, @@ -263,127 +215,7 @@ } }, { - "logId": "8", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "9", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "10", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "11", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "12", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "13", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "14", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "15", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "16", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "17", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "18", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "19", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "20", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "21", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "22", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "23", + "logId": "8961848586872524460", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle.json index 3c8224f070c..ea4a39bd74e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": null, @@ -14,7 +15,7 @@ ], "loggedTypes": [ { - "logId": 0, + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 1, @@ -37,4 +38,4 @@ "typeParameters": null } ] -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle_new_encoding.json index 9ab7be41b30..e8d2e4e28d4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/multiple_impl/json_abi_oracle_new_encoding.json @@ -15,15 +15,7 @@ ], "loggedTypes": [ { - "logId": "0", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "1", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 1, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle_new_encoding.json index a5831f96116..90c5fa2590e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle_new_encoding.json @@ -822,15 +822,7 @@ ], "loggedTypes": [ { - "logId": "0", - "loggedType": { - "name": "", - "type": 2, - "typeArguments": null - } - }, - { - "logId": "1", + "logId": "13213829929622723620", "loggedType": { "name": "", "type": 2, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.json index 290d04e8b24..ec0a0a7addf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.json @@ -1,5 +1,6 @@ { "configurables": [], + "encoding": "1", "functions": [ { "attributes": [ @@ -198,7 +199,7 @@ ], "loggedTypes": [ { - "logId": 0, + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 9, @@ -206,39 +207,7 @@ } }, { - "logId": 1, - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": 2, - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": 3, - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": 4, - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": 5, + "logId": "1970142151624111756", "loggedType": { "name": "", "type": 8, @@ -246,47 +215,7 @@ } }, { - "logId": 6, - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": 7, - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": 8, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 9, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 10, - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": 11, + "logId": "8961848586872524460", "loggedType": { "name": "", "type": 1, @@ -423,4 +352,4 @@ "typeParameters": null } ] -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle_new_encoding.json index 61dba718076..8e817c80160 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle_new_encoding.json @@ -199,7 +199,7 @@ ], "loggedTypes": [ { - "logId": "0", + "logId": "1515152261580153489", "loggedType": { "name": "", "type": 9, @@ -207,55 +207,7 @@ } }, { - "logId": "1", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "2", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "3", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "4", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "5", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "6", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "7", + "logId": "1970142151624111756", "loggedType": { "name": "", "type": 8, @@ -263,127 +215,7 @@ } }, { - "logId": "8", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "9", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "10", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "11", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "12", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "13", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "14", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "15", - "loggedType": { - "name": "", - "type": 9, - "typeArguments": null - } - }, - { - "logId": "16", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "17", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "18", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "19", - "loggedType": { - "name": "", - "type": 8, - "typeArguments": null - } - }, - { - "logId": "20", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "21", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "22", - "loggedType": { - "name": "", - "type": 1, - "typeArguments": null - } - }, - { - "logId": "23", + "logId": "8961848586872524460", "loggedType": { "name": "", "type": 1, diff --git a/test/src/ir_generation/mod.rs b/test/src/ir_generation/mod.rs index 011e88b0eae..b371b710bc3 100644 --- a/test/src/ir_generation/mod.rs +++ b/test/src/ir_generation/mod.rs @@ -230,7 +230,7 @@ pub(super) async fn run( PathBuf::from("/"), build_target, ).with_experimental(sway_core::ExperimentalFlags { - new_encoding: experimental.new_encoding + new_encoding: experimental.new_encoding, }); // Include unit tests in the build. @@ -470,7 +470,7 @@ pub(super) async fn run( // Parse the IR again, and print it yet again to make sure that IR de/serialisation works. let parsed_ir = sway_ir::parser::parse(&ir_output, engines.se(), sway_ir::ExperimentalFlags { - new_encoding: experimental.new_encoding + new_encoding: experimental.new_encoding, }) .unwrap_or_else(|e| panic!("{}: {e}\n{ir_output}", path.display())); let parsed_ir_output = sway_ir::printer::to_string(&parsed_ir);