Skip to content

Conversation

@ironcev
Copy link
Member

@ironcev ironcev commented Jul 9, 2025

Description

This PR adds the #[trace] attribute as described in the ABI Backtracing RFC.

This is the first step in implementing #7276.

Docs for #[trace] attribute will be added in a separate PR that will document the whole backtracking feature.

A check if an annotated function can actually panic will be added in a follow up PR that will implement the backtracing in the IR generation.

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 temporarily deployed to fuel-sway-bot July 9, 2025 12:45 — with GitHub Actions Inactive
@ironcev ironcev self-assigned this Jul 9, 2025
@ironcev ironcev 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 Jul 9, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 9, 2025

CodSpeed Performance Report

Merging #7277 will not alter performance

Comparing ironcev/abi-backtracing-trace-attribute (0706b1c) with master (384f46f)

Summary

✅ 25 untouched benchmarks

@ironcev ironcev marked this pull request as ready for review July 9, 2025 13:15
@ironcev ironcev requested a review from a team as a code owner July 9, 2025 13:15
@ironcev ironcev enabled auto-merge (squash) July 9, 2025 13:15
@ironcev ironcev requested a review from a team July 9, 2025 13:15
@ironcev ironcev temporarily deployed to fuel-sway-bot July 9, 2025 13:41 — with GitHub Actions Inactive
Copy link
Contributor

@zees-dev zees-dev left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ironcev ironcev temporarily deployed to fuel-sway-bot July 11, 2025 06:15 — with GitHub Actions Inactive
@tritao tritao temporarily deployed to fuel-sway-bot July 11, 2025 11:15 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot July 11, 2025 12:18 — with GitHub Actions Inactive
@ironcev ironcev merged commit 8b75246 into master Jul 11, 2025
81 of 117 checks passed
@ironcev ironcev deleted the ironcev/abi-backtracing-trace-attribute branch July 11, 2025 12:35
@zees-dev zees-dev mentioned this pull request Nov 25, 2025
8 tasks
zees-dev added a commit that referenced this pull request Nov 26, 2025
## Description

This PR introduces panic/error traces to the forc call trace output.
This functionality is built on top of the existing abi-backtracing
introduced in the following:
-
https://github.com/FuelLabs/sway-rfcs/blob/master/rfcs/0016-abi-backtracing.md
- #7224
- #7277
- FuelLabs/fuel-abi-types#36
- https://github.com/FuelLabs/fuel-abi-types/pull/40/files

Supplying verbosity level greater than 1 (i.e. `-vv` or `-v=2`) will
display the panic/error traces when using `forc-call`.
If the called function panics, the panic message and the full backtrace
will be displayed in the trace output.

## Example

<details>
<summary>Example contract code</summary>

```sway
contract;

abi AbiErrorDemo {
    #[storage(write)]
    fn write_non_zero(value: u64);
    #[storage(read)]
    fn read_value() -> u64;
}

storage {
    value: u64 = 0,
}

#[error_type]
pub enum PanicError {
    #[error(m = "The provided value must be greater than zero.")]
    ZeroValue: (),
}

impl AbiErrorDemo for Contract {
    #[storage(write)]
    fn write_non_zero(value: u64) {
        set_non_zero_value(value);
    }
    #[storage(read)]
    fn read_value() -> u64 {
        storage.value.read()
    }
}

#[trace(always)]
#[storage(write)]
fn set_non_zero_value(value: u64) {
    ensure_non_zero(value);
    storage.value.write(value);
}

#[trace(always)]
fn ensure_non_zero(value: u64) {
    ensure_non_zero_impl(value);
}

#[trace(always)]
fn ensure_non_zero_impl(value: u64) {
    if value == 0 {
        panic PanicError::ZeroValue;
    }
}
```

</details>

Example Call:

```sh
cargo run -p forc-client --bin forc-call -- \
  --abi out/debug/abi_errors-abi.json \
  babdc125da45eac42309e60d3aea63a53843f5ff2438d1a88bf8c788e8348c58 \
  write_non_zero "0" -vv
```

Example Output:

<img width="857" height="340" alt="Screenshot 2025-11-24 at 8 36 00 PM"
src="https://github.com/user-attachments/assets/9a14053e-9318-4543-a01a-0d794e30dff2"
/>

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds ABI-aware revert decoding to forc-call, displaying panic
messages, values, and backtraces in verbose traces and surfacing revert
errors early.
> 
> - **forc-client (call/trace)**:
> - Add ABI-aware revert decoding (`RevertInfoSummary`) and integrate
into `TraceEvent::Revert`; render panic message, value, location, and
backtrace in `display_transaction_trace`.
> - New helpers: `decode_revert_info` and `first_revert_info` to extract
revert details from receipts and trace.
> - `call_function`: generate receipts once, include in interpreter,
display detailed info on verbosity, and return an error early when a
revert is detected; parse outputs after.
> - Minor: reference `trace::display_transaction_trace` directly; extend
tests to cover revert detail rendering.
> - **forc-util**:
> - Add `revert_info_from_receipts` to build `RevertInfo` (revert code,
panic metadata) from receipts using optional ABI.
> - **forc-test**:
> - Replace `revert_code()` with `revert_info()` using new utility;
filter by actual revert code; simplify API.
> - **Docs**:
> - Add "Seeing revert information and backtraces" section with example
usage/output for `forc call -vv`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
957d411. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: z <[email protected]>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants