8000 Compile panic expression to ABI error codes by ironcev · Pull Request #7118 · FuelLabs/sway · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Compile panic expression to ABI error codes #7118

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ironcev
Copy link
Member
@ironcev ironcev commented Apr 24, 2025

Description

This PR is the final step in implementing the panic expression and the ABI errors, as defined in the ABI Errors RFC.

The PR generates the errorCodes section in the ABI, like, e.g.:

"errorCodes": {
  "18446744069414584320": {
    "pos": {
      "pkg": "my_lib@1.2.3",
      "file": "src/lib.rs",
      "line": 42,
      "column": 13
    },
    "logId": null,
    "msg": "Error message."
  },
  "18446744069414584321": {
    "pos": {
      "pkg": "my_contract",
      "file": "src/main.rs",
      "line": 21,
      "column": 34
    },
    "logId": "4933727799282657266",
    "msg": null
  }
}

If the panic argument is a string slice that can 8000 be const-evaluated, the msg field of the corresponding error code is generated, and a log is not emitted. The string itself is stored only within the ABI JSON, and is not included into the generated bytecode.

Additionally, the PR:

  • provides a common infrastructure for obtaining a SourceLocation from a Span. This is currently used in the implementation of the __dbg intrinsics and the panic expression.
  • improves filtering of forc outputs in snapshot tests by supporting regular expressions. The grep command is renamed to regex to avoid confusion with piping the actual grep CLI command.

Partially addresses #6765.

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.

@ironcev ironcev self-assigned this Apr 24, 2025
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged language feature Core language features visible to end users ABI Everything to do the ABI, especially the JSON representation blocked labels Apr 24, 2025
@ironcev ironcev force-pushed the ironcev/error-codes-in-abi-json branch from 43f1861 to f411839 Compare April 24, 2025 14:49
@ironcev
Copy link
Member Author
ironcev commented Apr 24, 2025

This PR is blocked by #7073. It integrates the newest fuel-abi-types and ensures forc and swayfmt builds against fuels defined in:

fuels = { git = "https://github.com/FuelLabs/fuels-rs", branch = "feat/abi-errors" }

The next step in the integration of fuel-abi-types is to get a fuels patch that compiles against this branch.

CC: @hal3e.

@ironcev ironcev force-pushed the ironcev/error-codes-in-abi-json branch from be13470 to 65a9c8c Compare May 7, 2025 12:57
@ironcev ironcev temporarily deployed to fuel-sway-bot May 7, 2025 12:57 — with GitHub Actions Inactive
@hal3e hal3e temporarily deployed to fuel-sway-bot May 7, 2025 19:13 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot May 8, 2025 11:00 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI Everything to do the ABI, especially the JSON representation compiler General compiler. Should eventually become more specific as the issue is triaged language feature Core language features visible to end users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0