-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalize the handling of generics in JSON ABI #2386
Comments
Another option is to completely redesign the JSON ABI as suggested by @emilyaherbert: Quoting Emily: This is what I would ideally like to see for the ABI, MyStruct<T,U> {
bim: T,
bam: U,
never_used: u64,
} this ABI method: fn add(foo: MyStruct<u64, bool>, bar: MyStruct<u64, u8>); it would be cool if we could achieve something similar to this: {
"types": [
{ // 0
"type": "u64",
"typeParameters": null,
"components": null
},
{ // 1
"type": "bool",
"typeParameters": null,
"components": null
},
{ // 2
"type": "u8",
"typeParameters": null,
"components": null
},
{ // 3
"type": "generic T0",
"typeParameters": null,
"components": null
},
{ // 4
"type": "generic U0",
"typeParameters": null,
"components": null
},
{ // 5
"type": "struct MyStruct",
"typeParameters": [3, 4],
"components": [
{
"name": "bim",
"type": 3,
"typeArguments": null
},
{
"name": "bam",
"type": 4,
"typeArguments": null
},
{
"name": "never_used",
"type": 0,
"typeArguments": null
}
]
},
{ // 6
"type": "()",
"typeParameters": null,
"components": null
}
],
"functions": [
{
"type": "function",
"inputs": [
{
"name": "foo",
"type": 5,
"typeArguments": [0, 1]
},
{
"name": "bar",
"type": 5,
"typeArguments": [0, 2]
}
],
"output": [
{
"name": "",
"type": 6,
"typeArguments": null
}
]
}
]
} |
A third short term option is to work with what we have today (i.e. |
We agreed to go with the flat JSON ABI design for it's simplicity and clarity. The types now go first then the functions. There are basically two types of properties (unlike before):
|
#2218 introduces the
typeArgument
field to the JSON ABI which got us one step closer to supporting (resolved) generics in the ABI. However, as @iqdecay pointed out, this doesn't solve the full problem because even though we know what type parameters a given struct/enum has and what they resolve to, we do not know what generic parameter each component actually uses. For example:Both structs above would be represented in the same way in the JSON ABI (except for the name of course) and that's ambiguous.
The
typeArguments
field gave us half the solution. The other half is that we should modify thetype
field to contain the type parameter applied. For example, the first input would be represented as follows:The above has all the information we need to recreate the generic struct declaration and also recreate its specialization (i.e.
MyStruct1<u64, u64>
).This gets a bit more complicated when the field of a struct is a complex type that uses one of the generics. For example:
but the same concepts still applies:
This introduces no changes to non-generic types so the current working flows continue to work as expected.
The text was updated successfully, but these errors were encountered: