-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ASTGen] Infrastructure for implementing ASTGen incrementally #69761
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
c15feed
to
b423363
Compare
//===--------------------------------------------------------------------===// | ||
// ASTGen support. | ||
|
||
ParserResult<TypeRepr> parseTypeReprFromSyntaxTree(); |
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.
Just reading the function declaration, I’m thinking: Which syntax tree is this parsing from? I think a doc comment could help explain this (or a need a better name).
break | ||
case // Known unimplemented kinds. | ||
.arrayExpr, .arrowExpr, .asExpr, .assignmentExpr, .awaitExpr, | ||
.binaryOperatorExpr, .booleanLiteralExpr, .borrowExpr, .canImportExpr, |
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.
Literals are already implemented. I didn't notice that they were in Literals.swift
.
When 'wantOutermost' is true, traverse the parent as long as the position is the same as the target position.
0323409
to
f333245
Compare
@swift-ci Please smoke test |
f333245
to
5f7c020
Compare
@swift-ci Please smoke test |
preset=asan |
5f7c020
to
253fbb9
Compare
@swift-ci Please smoke test |
preset=asan |
include/swift/Parse/Parser.h
Outdated
|
||
/// Parse a TypeRepr from the syntax tree. i.e. SF->getExpxortedSourceFile() | ||
ParserResult<TypeRepr> parseTypeReprFromSyntaxTree(); | ||
/// Parse a Stmt from the syntax tree. i.e. SF->getExpxortedSourceFile() |
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.
Typo "Expxorted" in all of these.
} | ||
else { | ||
// FIXME: Produce an error | ||
return nil |
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.
It might be worth putting in some stub error sooner rather than later, so this doesn't cause unwanted surprises.
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.
Currently findSyntaxNodeInSourceFile()
prints an error message to stdout, which is not great, but at least it prevents "unwanted surprises". But yeah, I think we should add a diagnostic on the diagnostic engine.
Though since this PR is getting big, and to unblock some follow-up patches I have, I'd like to do it in the followups.
Also, I'm thinking to change findSyntaxNodeInSourceFile()
itself. #69724 (comment)
I like this approach of bouncing between the two parsers as needed, so we can opt in to ASTGen production-by-production. |
* 'ASTGenVisitor' has a reference to a legacy C++ Parser configured for ASTGen. * If 'ASTGenVisitor' encounters a AST node that hasn't been migrated, call parse(Decl|Stmt|Expr|Type) to parse the position using the legacy parser. * The legacy parser calls ASTGen's 'swift_ASTGen_build(Decl|Stmt|Expr|Type)' for each ASTNode "parsing" (unless the call is not directly from the ASTGen.) rdar://117151886
There's no reason to generate only TypeRepr using ASTGen anymore. Use ParserASTGen feature to test test/ASTGen/types.swift because ASTGen now can generate the whole test file for type checking.
Apparently C++ method bridging doesn't work in Linux?
fe4ba34
to
d51058c
Compare
@swift-ci Please smoke test |
preset=asan |
|
||
// -enable-experimental-feature requires an asserts build | ||
// REQUIRES: asserts | ||
// REQUIRES: rdar116686158 |
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.
It is really unfortunate that this test hits ASAN failure too. We're actively looking into this issue.
Anyway I confirmed these tests passes locally.
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.
Should we mark it UNSUPPORTED: asan
for now so we at least don't lose the test coverage?
@@ -113,6 +134,67 @@ struct SwiftParserExecutor { | |||
} | |||
}; | |||
|
|||
static void appendToVector(void *declPtr, void *vecPtr) { |
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.
Is this used? Only reference I see is in ParseDecl.cpp
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.
Ah, it's a leftover. I'm removing it in a followup
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.
Cool!
) -> UnsafeMutableRawPointer? { | ||
let sourceFile = sourceFilePtr.assumingMemoryBound(to: ExportedSourceFile.self) | ||
|
||
// Find the type syntax node. |
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.
Nit: Not necessarily a type syntax any more, right?
The field `IsForASTGen` only exists when `SWIFT_BUILD_SWIFT_SYNTAX` is defined, but the usage was unprotected. The whole function can be inside the protected block because it only seems to be invoked from inside blocks already protected by `SWIFT_BUILD_SWIFT_SYNTAX`. Fix for swiftlang#69761
ASTGenVisitor
has a reference to a legacy C++ Parser configured for ASTGen.ASTGenVisitor
encounters a AST node that hasn't been migrated, call the C++Parser::parse(Decl|Stmt|Expr|Type)
to parse the position using the legacy parser.swift_ASTGen_build(Decl|Stmt|Expr|Type)
for each ASTNode parsing (unless the call is not directly from the ASTGen.)rdar://117151886