Skip to content

Commit 7b06a4e

Browse files
committed
Add experimental ABI alias metadata support.
1 parent f060943 commit 7b06a4e

File tree

32 files changed

+2303
-781
lines changed

32 files changed

+2303
-781
lines changed

Cargo.lock

Lines changed: 654 additions & 702 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ sway-ir-macros = { path = "sway-ir/sway-ir-macros", version = "0.70.1" }
8080
#
8181

8282
# Dependencies from the `fuel-abi-types` repository:
83-
fuel-abi-types = "0.15"
83+
fuel-abi-types = "0.16"
8484

8585
# Dependencies from the `fuel-core` repository:
8686
#
@@ -259,3 +259,9 @@ vte = "0.13"
259259
walkdir = "2.3"
260260
whoami = "1.5"
261261
wiremock = "0.6"
262+
263+
[patch.crates-io]
264+
fuels = { git = "https://github.com/FuelLabs/fuels-rs", branch = "feat/alias-type" }
265+
fuels-core = { git = "https://github.com/FuelLabs/fuels-rs", branch = "feat/alias-type" }
266+
fuels-accounts = { git = "https://github.com/FuelLabs/fuels-rs", branch = "feat/alias-type" }
267+
fuels-code-gen = { git = "https://github.com/FuelLabs/fuels-rs", branch = "feat/alias-type" }

forc-pkg/src/pkg.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,9 @@ pub fn compile(
18111811
abi_with_callpaths: true,
18121812
type_ids_to_full_type_str: HashMap::<String, String>::new(),
18131813
unique_names: HashMap::new(),
1814+
metadata_declaration_cache: HashMap::new(),
1815+
concrete_declaration_cache: HashMap::new(),
1816+
experimental,
18141817
},
18151818
engines,
18161819
if experimental.new_encoding {

sway-core/src/abi_generation/abi_str.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct AbiStrContext {
1111
pub abi_with_callpaths: bool,
1212
pub abi_with_fully_specified_types: bool,
1313
pub abi_root_type_without_generic_type_parameters: bool,
14+
pub abi_type_aliases: bool,
1415
}
1516

1617
impl TypeId {
@@ -26,7 +27,7 @@ impl TypeId {
2627
let self_abi_str = type_engine
2728
.get(*self)
2829
.abi_str(handler, ctx, engines, true)?;
29-
if self.is_generic_parameter(engines, resolved_type_id) {
30+
if self.is_generic_parameter(engines, resolved_type_id, ctx.abi_type_aliases) {
3031
Ok(format!("generic {self_abi_str}"))
3132
} else {
3233
match (
@@ -37,9 +38,10 @@ impl TypeId {
3738
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => type_engine
3839
.get(resolved_type_id)
3940
.abi_str(handler, ctx, engines, true),
40-
(_, TypeInfo::Alias { ty, .. }) => ty
41+
(_, TypeInfo::Alias { ty, .. }) if !ctx.abi_type_aliases => ty
4142
.type_id
4243
.get_abi_type_str(handler, ctx, engines, ty.type_id),
44+
(_, TypeInfo::Alias { .. }) => Ok(self_abi_str),
4345
(TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => {
4446
assert_eq!(fields.len(), resolved_fields.len());
4547
let field_strs = resolved_fields
@@ -204,7 +206,13 @@ impl TypeInfo {
204206
"__slice {}",
205207
ty.abi_str(handler, ctx, engines, false)?
206208
)),
207-
Alias { ty, .. } => Ok(ty.abi_str(handler, ctx, engines, false)?),
209+
Alias { name, ty } => {
210+
if ctx.abi_type_aliases {
211+
Ok(name.to_string())
212+
} else {
213+
ty.abi_str(handler, ctx, engines, false)
214+
}
215+
}
208216
TraitType {
209217
name,
210218
implemented_in: _,

sway-core/src/abi_generation/evm_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn generate_abi_program(program: &TyProgram, engines: &Engines) -> EvmAbiRes
2525
/// Gives back a string that represents the type, considering what it resolves to
2626
fn get_type_str(type_id: &TypeId, engines: &Engines, resolved_type_id: TypeId) -> String {
2727
let type_engine = engines.te();
28-
if type_id.is_generic_parameter(engines, resolved_type_id) {
28+
if type_id.is_generic_parameter(engines, resolved_type_id, false) {
2929
format!("generic {}", abi_str(&type_engine.get(*type_id), engines))
3030
} else {
3131
match (

0 commit comments

Comments
 (0)