Skip to content

Conversation

mikebenfield
Copy link

@mikebenfield mikebenfield commented Mar 12, 2024

Parent PR: OffchainLabs/stylus#208
Associated PR: OffchainLabs/stylus-sdk-c#18
Stylus update PR: OffchainLabs/stylus#210

Closes STY-39

Comment on lines 60 to 83
/// Exits program execution early with the given status code.
/// If `0`, the program returns successfully with any data supplied by `write_result`.
/// Otherwise, the program reverts and treats any `write_result` data as revert data.
#[inline]
pub fn exit_early(status: u32) {
unsafe { hostio::exit_early(status) }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of exposing this as-is to users, let's add a revert! macro that expands to a console!, write_result and early_exit(). Also let's go through the SDK and find places where we can replace panics with it.

We'll also want an affordance for the success case, which should ideally take an arguement for the return data.

Copy link
Author

@mikebenfield mikebenfield Mar 12, 2024

Choose a reason for hiding this comment

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

I added this macro. Note that exit_early does need to still be public so that it can be called by the expanded macro. I also added a similar succeed macro.

Currently the macro does not call write_result - it seemed awkward to me that the macro would receive both a result slice for revert data and a message to print. The user can first call output. However, if you do prefer the macro handle both (presumably just called as revert!(slice_data, "Some console message"), let me know and I'll make that change.

@rauljordan
Copy link
Contributor

Closing as PR is stale

@rauljordan rauljordan closed this Mar 18, 2025
@gligneul gligneul deleted the early-exit2 branch May 30, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants