Skip to content

feat(ir): Normalize catch clauses in the IR - #2031

Open
ggiraldez wants to merge 1 commit into
mainfrom
ggiraldez/catch-clause-kind
Open

feat(ir): Normalize catch clauses in the IR#2031
ggiraldez wants to merge 1 commit into
mainfrom
ggiraldez/catch-clause-kind

Conversation

@ggiraldez

Copy link
Copy Markdown
Contributor

This spawned from the discussion in #2023. But the code changed so much that I decided to submit a new PR.

Removes CatchClauseError in favor of CatchClauseKind which is an enum with the valid variants for Error, Panic and low-level.

This ensures the IR only contains valid catch clauses (modulo parameters, to be checked later when type info is available) and the clause kind is encoded in the enum variant.

Also removes the now obsolete ErrorOrPanic built-in.

Removes `CatchClauseError` in favor of `CatchClauseKind` which is an
enum with the valid variants for `Error`, `Panic` and low-level.

This ensures the IR only contains valid catch clauses (modulo
parameters, to be checked later when type info is available) and the
clause kind is encoded in the enum variant.

Also removes the now obsolete `ErrorOrPanic` built-in.
@ggiraldez
ggiraldez requested review from a team as code owners August 6, 2026 16:45
@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 687e683

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +151 to +153
mutator.add_choice_variant("CatchClauseKind", "ClauseErrorKind");
mutator.add_choice_variant("CatchClauseKind", "ClausePanicKind");
mutator.add_choice_variant("CatchClauseKind", "ClauseLowLevelKind");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: for the three variants, the Kind suffix reads to me like they are enums on their own. WDYT of renaming them to ErrorCatchClause, PanicCatchClause, and LowLevelCatchClause? similar to other types in the codebase.

@hedgar2017 hedgar2017 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One API request from the solx side; the normalized shape otherwise works well — I've already adapted solx to this PR and it compiles and passes tests.

use crate::ir;

impl ir::CatchClauseStruct {
pub fn parameters(&self) -> Option<&ir::Parameters> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we mirror this extension on the AST layer as ast::CatchClauseStruct::parameters() -> Option<Parameters>? In solx we consume catch clauses through ast::CatchClauseStruct, and binding the clause parameter currently requires matching all three CatchClauseKind variants just to reach parameters():

let parameters = match node.kind() {
    CatchClauseKind::ClauseErrorKind(kind) => Some(kind.parameters()),
    CatchClauseKind::ClausePanicKind(kind) => Some(kind.parameters()),
    CatchClauseKind::ClauseLowLevelKind(kind) => kind.parameters(),
};

An AST mirror would collapse this to a single call, while the kind-specific cardinality stays available on the variants for callers that need it.

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.

3 participants