Skip to content

DNM: Fix up effect specifiers in function signatures #889

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

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented Oct 7, 2022

In progress, up for feedback/to comment in another PR.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Looks good to me in general. I’ve got a few stylist ideas inline

@bnbarham bnbarham force-pushed the handle-random-specifiers branch from 14c8cd8 to ee7691a Compare October 11, 2022 02:04
if self.at(.arrow) {
result = self.parseFunctionReturnClause().returnClause
if let handle = self.canRecoverTo(.arrow) {
result = self.parseReturnClause(handle).returnClause
Copy link
Member

Choose a reason for hiding this comment

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

You are dropping the effect specifiers here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weird that I can't see this in the review. But no, they're added to the return clause itself. They're only returned to be able to make async/throws missing when necessary. This is one of the many reasons I'm not a huge fan of this patch (though this particular returning of unexpected nodes was already here).

It really seems like we should just recover + place tokens in unexpected + have ASTGen handle these diagnostics. Though one issue there is that they wouldn't be parsed as contextual keywords if we just did regular recovery vs looked for the effects specifically.

@unknown is sort of an example of this, though it currently allows any attribute as the @unknown attribute and parses the rest as unexpected (ie. just recovers to the case/default).

Copy link
Member

Choose a reason for hiding this comment

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

Ah, never mind. I missed that throws also gets added to the unexpected tokens of the returnClause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but it's super easy to miss. Hence my problem with doing it this way :)

var loopProgress = LoopProgressCondition()
while let (specifier, handle) = self.canRecoverTo(anyIn: EffectsSpecifier.self), loopProgress.evaluate(currentToken) {
let (unexpected, token) = self.eatKeepUnexpected(handle)
specifiers.append(contentsOf: unexpected.map { SpecifierWithToken(specifier: nil, token: $0) })
Copy link
Member

Choose a reason for hiding this comment

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

I don’t really like how we are considering unexpected tokens as SpecifierWithToken here and setting specifier to nil.

What do you think about changing SpecifierWithToken to

struct ParsedEffectsSpecifier {
  let specifier: EffectsSpecifier?
  let unexpected: RawUnexpectedNodesSyntax?
  let token: RawTokenSyntax
 }

That way you also don’t need to modify eat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Much better name, but I'm not sure I understand the unexpected suggestion. The issue here is that they all need to get merged into the single RawUnexpectedNodeSyntax.

Copy link
Member

Choose a reason for hiding this comment

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

We can add RawUnexpectedNodeSyntax as a child of RawUnexpectedNodeSyntax. Or, if you don’t like that, maybe it should be

struct ParsedEffectsSpecifier {
  let specifier: EffectsSpecifier?
  let unexpected: [RawTokenSyntax]
  let token: RawTokenSyntax
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, makes sense.

@bnbarham bnbarham closed this Mar 15, 2024
@bnbarham bnbarham deleted the handle-random-specifiers branch March 15, 2024 17:07
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.

2 participants