Skip to content

[ASTGen] Utilize base specific SyntaxEnum and start Pattern generation #69829

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

Merged
merged 2 commits into from
Nov 15, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 14, 2023

  • Utilize {Decl|Stmt|Expr|Type|Pattern}SyntaxEnum introduced in Add SyntaxEnum per base syntax kind swift-syntax#2351
  • Separate generate(_: Syntax) into generate(decl: DeclSyntax), generate(expr: ExprSyntax) etc.
  • Start Patterns.swift to generate Patterns as the same scheme as other kinds. (C++ parser ping-pong is not implmented)
  • Enable ASTGen tests in non-ASAN

@rintaro
Copy link
Member Author

rintaro commented Nov 14, 2023

@swift-ci Please smoke test

@rintaro rintaro changed the title [ASTGne] Utilize base specific SyntaxEnum and start Pattern generation [ASTGen] Utilize base specific SyntaxEnum and start Pattern generation Nov 14, 2023
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -373,7 +261,7 @@ extension ASTGenVisitor {
return nil
}

return self.generate(node)
return self.generate(type: node)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to give these argument labels, should the optional variants also get them? Or is the intention to avoid the risk of recursion?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I will add argument labels to all the existing generate(_:) functions in follow-ups.


default:
fatalError("case does not correspond to an ASTNode")
// CodeBlockItem -> BraceStmt or IfStmt.
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean

Suggested change
// CodeBlockItem -> BraceStmt or IfStmt.
// CodeBlockSyntax -> BraceStmt or IfStmt.

Also, if this can become an IfStmt, can it also become a SwitchStmt?

Copy link
Member Author

Choose a reason for hiding this comment

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

IfStmt was wrong. just CodeBlockSyntax -> BraceStmt

return .expr(self.generate(expr: expr))
}
if let type = node.as(TypeSyntax.self) {
return .type(self.generate(type: type))
}
Copy link
Member

Choose a reason for hiding this comment

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

Don’t we need to also check for PatternSyntax here?

Copy link
Member Author

Choose a reason for hiding this comment

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

BridgedPattern is not an ASTNode at this point

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. 👍🏽

@@ -2,7 +2,8 @@

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// REQUIRES: rdar116686158
// rdar//116686158
Copy link
Member

Choose a reason for hiding this comment

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

Nit

Suggested change
// rdar//116686158
// rdar://116686158

@@ -10,7 +10,8 @@

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// REQUIRES: rdar116686158
// rdar//116686158
Copy link
Member

Choose a reason for hiding this comment

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

Nit

Suggested change
// rdar//116686158
// rdar://116686158

@rintaro rintaro force-pushed the astgen-node-syntaxenum branch from 2eb5116 to 215abe6 Compare November 14, 2023 18:48
@rintaro
Copy link
Member Author

rintaro commented Nov 14, 2023

@swift-ci Please smoke test

@rintaro rintaro enabled auto-merge November 14, 2023 19:38
@rintaro rintaro merged commit 8ca707b into swiftlang:main Nov 15, 2023
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