-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Implement panic
expression
#7073
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
Conversation
CodSpeed Performance ReportMerging #7073 will not alter performanceComparing Summary
|
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 tooling changes look good to me 👍
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.
We seem to have a tiny conflict happy to re-approve once it is fixed as well :)
cd86555
Description
This PR introduces the
panic
expression to the language, as defined in the ABI Errors RFC.The
panic
expression can be used without arguments, or accept an argument that implements thestd::marker::Error
trait. TheError
trait is implemented by the compiler for the unit()
, string slices, and#[error_type]
enums.Using the
panic
expression without arguments gives the symetry with thereturn
expression and acts in the same way as having unit as an argument.Panicking without an argument or with unit as argument is discouraged to use. In the upcoming PR that finalizes the ABI errors feature, we will emit a warning if the
panic
is used without arguments or with unit as argument.panic
expression is available in all program kinds. In predicates it currently compiles only to revert. Once__dbg
intrinsic is implemented, we can consider compiling to it in predicates. In the upcoming PR, theerror_codes
entry in the ABI JSON will be available for all program kinds.The dead code analysis for the
panic
expression is implemented in the straightforward way, following the current approach of connecting reverts to the exit node. This will be revisted in a separate PR, together with the open TODOs in the DCA implementation ofReturn
. Essentially, we want reverting/panicking to connect to program exit and implicit returns to the exit node.Additionally, the PR:
forc test
CLI attributes with--revert-codes
that prints revert codes even if tests are successful but revert.forc test
in snapshot tests.__log
with invalid number of arguments #7072.Partially addresses #6765.
Breaking Change
panic
is a new reserved keyword. Once theerror_type
feature becomes integrated, compiling any existing code containing a "panic" as an identifier will result in an "Identifiers cannot be a reserved keyword." error.In this PR,
panic
keyword is hidden behind theerror_type
feature flag. This prevents existing code from breaking, unless opted-in.Note that, although being behind a feature flag,
panic
cannot be used in conditional compilation, means in combination with the#[cfg(experimental_error_type = true/false)]
. The reason is thatcfg
evaluation happens after parsing, and we can either parsepanic
as a keyword or identifier during the parsing, because we cannot distinguish ambiguous cases likepanic;
or justpanic
.This limitation means, that introducing
panic
tostd
can be done only once theerror_type
feature is fully integrated. In practice, this is not a serious limitation, because introducingpanic
instd
would anyhow, due to effort and design decisions, happen after the feature is integrated.We will provide a migration for this breaking change that will migrate the existing "panic" identifiers to "r#panic".
Checklist
Breaking*
orNew Feature
labels where relevant.