-
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
Add #[abi_name(name = "foo")]
attribute to rename ABI items.
#7057
base: master
Are you sure you want to change the base?
Conversation
#[abi_name()
attribute to rename ABI items.#[abi_name(name = "foo")
attribute to rename ABI items.
CodSpeed Performance ReportMerging #7057 will not alter performanceComparing Summary
|
04f5114
to
0bddb9d
Compare
#[abi_name(name = "foo")
attribute to rename ABI items.#[abi_name(name = "foo")]
attribute to rename ABI items.
test/src/e2e_vm_tests/test_programs/should_pass/language/abi_name_attribute/.gitignore
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_pass/language/abi_name_attribute/src/lib.sw
Outdated
Show resolved
Hide resolved
test/src/e2e_vm_tests/test_programs/should_pass/language/abi_name_attribute/src/lib.sw
Outdated
Show resolved
Hide resolved
Literal::String(lit_string) => lit_string, | ||
_ => unreachable!(), | ||
}; | ||
abi_call_path.suffix = BaseIdent::new(literal.span.clone().trim_quotes()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general question to renaming ABI elements. What if we rename it to something that already exist and is also serialized into ABI? Shouldn't we provide any checks here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this a bit of a thought. Giving names is a serious business. Aside from renaming that can clash with an existing item what about invalid names? E.g.
name = ""
name = "this !s n0t an identif1er"
name = "__this_also_not"
name = "this::looks::like::a::path"
name = "will this \" break ABI generation or be encoded?"
What will SDKs do in these cases? How do they handle invalid names, if at all? I wouldn't be surprised if expecting a valid name is a part of an unwritten contract for ABI consistency.
I expect strong checks here for consistency. Honestly, I would go that far and give warnings for non-idiomatic names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for thinking about these in more detail, indeed I agree with you, it's worth it to spend a bit more time on this and add some better checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attribute should be added to the Attributes chapter in the documentation.
I've changed that documentation page fully in #7058 because it was seriously outdated. So, whoever gets the PR merged later will have some slight merge conflicts to solve on that page 😄
Pull request was converted to draft
0bddb9d
to
e45048c
Compare
e45048c
to
e364c5c
Compare
Add `#[abi_name(name = "foo")` attribute to rename enum and struct ABI items. Here is example of how it can be used: ```sway contract; #[abi_name(name = "RenamedMyStruct")] struct MyStruct {} #[abi_name(name = "RenamedMyEnum")] enum MyEnum { A: () } abi MyAbi { fn my_struct() -> MyStruct; fn my_enum() -> MyEnum; } impl MyAbi for Contract { fn my_struct() -> MyStruct { MyStruct{} } fn my_enum() -> MyEnum { MyEnum::A } } ``` Closes FuelLabs#5955.
e364c5c
to
b993940
Compare
Description
Add
#[abi_name(name = "foo")]
attribute to rename enum and struct ABI items.Here is example of how it can be used:
Closes #5955.
Checklist
Breaking*
orNew Feature
labels where relevant.