Skip to content

Commit cd95cdc

Browse files
esdrubalIGI-111
andauthored
Fixes ABI alias metadata types. (#6494)
## Description Before this push, using an alias in a contract would produce an ABI with two distinct metadata types for tuples: one for `(_,_)` and another for `(u64,u64)`. With this change, aliases are bypassed and we only produce metadata for the string type of the inner alias type. If alias is `(u64, u64)` we will produce a metadatatype for `(_,_)`. Fixes #6488 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: IGI-111 <igi-111@protonmail.com>
1 parent e220eca commit cd95cdc

File tree

8 files changed

+166
-3
lines changed

8 files changed

+166
-3
lines changed

sway-core/src/abi_generation/abi_str.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ impl TypeId {
2828
&*type_engine.get(resolved_type_id),
2929
) {
3030
(TypeInfo::Custom { .. }, TypeInfo::Struct { .. })
31-
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. })
32-
| (TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => type_engine
31+
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => type_engine
3332
.get(resolved_type_id)
3433
.abi_str(ctx, engines, true),
34+
(_, TypeInfo::Alias { ty, .. }) => {
35+
ty.type_id.get_abi_type_str(ctx, engines, ty.type_id)
36+
}
3537
(TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => {
3638
assert_eq!(fields.len(), resolved_fields.len());
3739
let field_strs = resolved_fields

test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_generics/json_abi_oracle_new_encoding.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
}
5353
],
5454
"metadataTypeId": 0,
55-
"type": "(struct TwoGenerics<u64,u32>, struct OneGeneric<u8>)"
55+
"type": "(_, _)"
5656
},
5757
{
5858
"metadataTypeId": 1,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[[package]]
2+
name = "abi_with_alias"
3+
source = "member"
4+
dependencies = ["core"]
5+
6+
[[package]]
7+
name = "core"
8+
source = "path+from-root-DE4DCECD674C309C"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
authors = ["Fuel Labs <contact@fuel.sh>"]
3+
entry = "main.sw"
4+
implicit-std = false
5+
license = "Apache-2.0"
6+
name = "abi_with_alias"
7+
8+
[dependencies]
9+
core = { path = "../../../../../../../sway-lib-core" }
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"concreteTypes": [
3+
{
4+
"concreteTypeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d",
5+
"type": "()"
6+
},
7+
{
8+
"concreteTypeId": "41bd1a98f0a59642d8f824c805b798a5f268d1f7d05808eb05c4189c493f1be0",
9+
"metadataTypeId": 0,
10+
"type": "(u64, u64)"
11+
}
12+
],
13+
"configurables": [],
14+
"encodingVersion": "1",
15+
"functions": [
16+
{
17+
"attributes": null,
18+
"inputs": [
19+
{
20+
"concreteTypeId": "41bd1a98f0a59642d8f824c805b798a5f268d1f7d05808eb05c4189c493f1be0",
21+
"name": "arg1"
22+
}
23+
],
24+
"name": "aliased_tuple",
25+
"output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
26+
},
27+
{
28+
"attributes": null,
29+
"inputs": [
30+
{
31+
"concreteTypeId": "41bd1a98f0a59642d8f824c805b798a5f268d1f7d05808eb05c4189c493f1be0",
32+
"name": "_arg1"
33+
}
34+
],
35+
"name": "tuple",
36+
"output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
37+
}
38+
],
39+
"loggedTypes": [],
40+
"messagesTypes": [],
41+
"metadataTypes": [
42+
{
43+
"components": [
44+
{
45+
"name": "__tuple_element",
46+
"typeId": 1
47+
},
48+
{
49+
"name": "__tuple_element",
50+
"typeId": 1
51+
}
52+
],
53+
"metadataTypeId": 0,
54+
"type": "(_, _)"
55+
},
56+
{
57+
"metadataTypeId": 1,
58+
"type": "u64"
59+
}
60+
],
61+
"programType": "contract",
62+
"specVersion": "1"
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"concreteTypes": [
3+
{
4+
"concreteTypeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d",
5+
"type": "()"
6+
},
7+
{
8+
"concreteTypeId": "41bd1a98f0a59642d8f824c805b798a5f268d1f7d05808eb05c4189c493f1be0",
9+
"metadataTypeId": 0,
10+
"type": "(u64, u64)"
11+
}
12+
],
13+
"configurables": [],
14+
"encodingVersion": "1",
15+
"functions": [
16+
{
17+
"attributes": null,
18+
"inputs": [
19+
{
20+
"concreteTypeId": "41bd1a98f0a59642d8f824c805b798a5f268d1f7d05808eb05c4189c493f1be0",
21+
"name": "arg1"
22+
}
23+
],
24+
"name": "aliased_tuple",
25+
"output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
26+
},
27+
{
28+
"attributes": null,
29+
"inputs": [
30+
{
31+
"concreteTypeId": "41bd1a98f0a59642d8f824c805b798a5f268d1f7d05808eb05c4189c493f1be0",
32+
"name": "_arg1"
33+
}
34+
],
35+
"name": "tuple",
36+
"output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d"
37+
}
38+
],
39+
"loggedTypes": [],
40+
"messagesTypes": [],
41+
"metadataTypes": [
42+
{
43+
"components": [
44+
{
45+
"name": "__tuple_element",
46+
"typeId": 1
47+
},
48+
{
49+
"name": "__tuple_element",
50+
"typeId": 1
51+
}
52+
],
53+
"metadataTypeId": 0,
54+
"type": "(_, _)"
55+
},
56+
{
57+
"metadataTypeId": 1,
58+
"type": "u64"
59+
}
60+
],
61+
"programType": "contract",
62+
"specVersion": "1"
63+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract;
2+
3+
type AliasedTuple = (u64, u64);
4+
5+
abi MyContract {
6+
fn tuple(arg1: (u64, u64)); // Inline
7+
fn aliased_tuple(arg1: AliasedTuple); // Alias
8+
}
9+
10+
impl MyContract for Contract {
11+
fn tuple(_arg1: (u64, u64)) {
12+
}
13+
fn aliased_tuple(arg1: AliasedTuple) {
14+
}
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
category = "compile"
2+
validate_abi = true
3+
expected_warnings = 1

0 commit comments

Comments
 (0)