Skip to content

Add #[abi_name(name = "foo")] attribute to rename ABI items. #7057

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

Merged
merged 8 commits into from
Jul 18, 2025

Conversation

tritao
Copy link
Contributor

@tritao tritao commented Apr 2, 2025

Description

Add #[abi_name(name = "foo")] attribute to rename enum and struct ABI items.

Here is example of how it can be used:

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 #5955.

Remarks

The checking for ABI names is being done in the ABI generation phase, which made it a requirement to change the interface of ABI checking to return Results everywhere and passing Handler all the way down, so emitted errors can be passed down to the driver for reporting.

Checklist

  • I have linked to any relevant issues.
  • 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).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@tritao tritao added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Apr 2, 2025
@tritao tritao self-assigned this Apr 2, 2025
@tritao tritao temporarily deployed to fuel-sway-bot April 2, 2025 19:08 — with GitHub Actions Inactive
@tritao tritao changed the title Add #[abi_name() attribute to rename ABI items. Add #[abi_name(name = "foo") attribute to rename ABI items. Apr 2, 2025
Copy link

codspeed-hq bot commented Apr 2, 2025

CodSpeed Performance Report

Merging #7057 will degrade performances by 19.1%

Comparing tritao:annotation-abi-name (b753849) with master (b68a386)

Summary

❌ 1 regressions
✅ 24 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
code_lens 4.9 µs 6 µs -19.1%

@tritao tritao force-pushed the annotation-abi-name branch from 04f5114 to 0bddb9d Compare April 2, 2025 19:51
@tritao tritao added the enhancement New feature or request label Apr 2, 2025
@tritao tritao temporarily deployed to fuel-sway-bot April 2, 2025 19:52 — with GitHub Actions Inactive
@tritao tritao marked this pull request as ready for review April 3, 2025 00:05
@tritao tritao requested a review from a team as a code owner April 3, 2025 00:05
IGI-111
IGI-111 previously approved these changes Apr 3, 2025
@tritao tritao enabled auto-merge (squash) April 3, 2025 10:47
@IGI-111 IGI-111 requested a review from a team April 3, 2025 11:26
@ironcev ironcev changed the title Add #[abi_name(name = "foo") attribute to rename ABI items. Add #[abi_name(name = "foo")] attribute to rename ABI items. Apr 3, 2025
Copy link
Member

@ironcev ironcev left a 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 😄

@tritao tritao marked this pull request as draft April 3, 2025 16:16
auto-merge was automatically disabled April 3, 2025 16:16

Pull request was converted to draft

@tritao tritao force-pushed the annotation-abi-name branch from 0bddb9d to e45048c Compare April 4, 2025 18:06
@tritao tritao temporarily deployed to fuel-sway-bot April 4, 2025 18:07 — with GitHub Actions Inactive
@tritao tritao force-pushed the annotation-abi-name branch from e45048c to e364c5c Compare April 7, 2025 11:32
@tritao tritao temporarily deployed to fuel-sway-bot April 7, 2025 11:32 — with GitHub Actions Inactive
@tritao tritao force-pushed the annotation-abi-name branch from e364c5c to b993940 Compare April 7, 2025 11:49
@tritao tritao temporarily deployed to fuel-sway-bot April 7, 2025 11:50 — with GitHub Actions Inactive
@tritao tritao force-pushed the annotation-abi-name branch from b993940 to a9d5c2a Compare April 15, 2025 22:15
@tritao tritao temporarily deployed to fuel-sway-bot April 15, 2025 22:16 — with GitHub Actions Inactive
@tritao tritao force-pushed the annotation-abi-name branch from a9d5c2a to 9046048 Compare April 15, 2025 22:26
Copy link
Member

@ironcev ironcev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small mistake in the docs definitely worth fixing, otherwise only nitpicks 😄

Regarding the comments about diagnostics guidelines, we should add those guidelines to the repo (currently they are only in the RFC) and polish existing diagnostics that violate them, but that's a low prio so far.

tritao added 2 commits July 14, 2025 14:42
Add `#[abi_name(name = "foo")]` attribute to rename enum and struct ABI
items.

Here is example of how it can be used:

```
contract;

struct MyStruct {}

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.
@tritao tritao force-pushed the annotation-abi-name branch from 591114b to 591b97a Compare July 15, 2025 15:52
@tritao tritao temporarily deployed to fuel-sway-bot July 15, 2025 15:52 — with GitHub Actions Inactive
@tritao tritao temporarily deployed to fuel-sway-bot July 16, 2025 15:18 — with GitHub Actions Inactive
@tritao tritao force-pushed the annotation-abi-name branch from febb58e to 271a850 Compare July 16, 2025 15:40
@tritao tritao temporarily deployed to fuel-sway-bot July 16, 2025 15:40 — with GitHub Actions Inactive
@tritao tritao temporarily deployed to fuel-sway-bot July 17, 2025 13:38 — with GitHub Actions Inactive
@tritao tritao requested a review from ironcev July 17, 2025 14:27
@IGI-111 IGI-111 temporarily deployed to fuel-sway-bot July 17, 2025 15:08 — with GitHub Actions Inactive
@tritao tritao enabled auto-merge (squash) July 17, 2025 16:01
@tritao tritao temporarily deployed to fuel-sway-bot July 17, 2025 16:01 — with GitHub Actions Inactive
@tritao tritao temporarily deployed to fuel-sway-bot July 17, 2025 19:09 — with GitHub Actions Inactive
Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@tritao tritao merged commit f117e85 into FuelLabs:master Jul 18, 2025
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create #[abi_name(name)] annotation
5 participants