8000 Add `EffectfulExprSyntax` syntax trait by Matejkob · Pull Request #2572 · swiftlang/swift-syntax · GitHub
[go: up one dir, main page]

Skip to content

Add EffectfulExprSyntax syntax trait #2572

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

Closed
wants to merge 1 commit into from

Conversation

Matejkob
Copy link
Contributor
@Matejkob Matejkob commented Mar 27, 2024

Introduces the EffectfulExprSyntax protocol, designed to provide a common interface for effectful expressions such as try and await.

Resolves #2549

Comment on lines 69 to 80
Trait(
traitName: "EffectfulExpr",
documentation: "Syntax trait for effectful expressions, such as `try` and `await`.",
children: [
Child(name: "expression", kind: .node(kind: .expr))
]
),
Copy link
Member

Choose a reason for hiding this comment

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

We should probably also expose the try or await keyword, similar to #2539

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've incorporated a keyword property into the trait.

However, I have some reservations regarding this API, particularly because using the try keyword without accompanying it with either a question mark or an exclamation mark might lead to confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps you could expose an effectKeyword property (mirroring tryKeyword and awaitKeyword) as well as a questionOrExclamationMark property that's just always nil for AwaitExprSyntax?

(In the future, we could conceivably add some sort of await? or await! syntax and then the property would be automagically available. And no, I don't know what such syntax would do since it's purely hypothetical.)

Introduces the `EffectfulExprSyntax` protocol, designed to provide a common interface for effectful expressions such as `try` and `await`.

Solves swiftlang#2549
@Matejkob Matejkob force-pushed the effectful-syntax-trait branch from b7fbd13 to f19e5dd Compare March 29, 2024 09:43
@grynspan
Copy link
Contributor

If you do land this change, I'd like to get it cherry-picked to 600 so we can adopt it in swift-testing sooner.

@Matejkob
Copy link
Contributor Author

If you do land this change, I'd like to get it cherry-picked to 600 so we can adopt it in swift-testing sooner.

I don't see any problems with that on my end.

Do you have an issue in swift-testing regarding adaptation?

@grynspan
Copy link
Contributor

swift-testing should generally be able to adopt swift-syntax-600 features once the release is tagged; swift-syntax-610, speculatively, would be quite a ways off.

@Matejkob
Copy link
Contributor Author
Matejkob commented Apr 1, 2024

Oh, I meant an issue about adopting EffectfulExprSyntax syntax trait, so I could look at it. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahoppen, please let me know if you want to land this PR in version 600. I will then move this release note to the 600.md file.

@ahoppen
Copy link
Member
ahoppen commented Apr 4, 2024

I did find the time to actually think about it now and wasn’t able to come up with a concise definition that differentiates TryExprSyntax and AwaitExprSyntax from any other syntax nodes, which is usually a very good indicator that we’re not on the right track.
At first I thought that try and await are keywords/modifiers/whatever you want to call them that don’t actually change semantic meaning but just indicate something to anyone reading the code. But TryExprSyntax also represents try! and try?, which do change how the expression behaves. With those in mind, I don’t think there’s anything fundamental that’s separating eg. try? from eg. optional chaining or force-unwrapping and thus it doesn’t make sense to add a syntax trait for them.

@ahoppen ahoppen closed this Apr 4, 2024
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.

"EffectfulExprSyntax" protocol covering TryExprSyntax and AwaitExprSyntax
3 participants
0