-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeCompletion] Stop using temporary Lexer in the second pass #28433
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
[CodeCompletion] Stop using temporary Lexer in the second pass #28433
Conversation
In `TypeCheckFunctionBodyUntilRequest`. So we can type check the body without typechecking the signature.
Since we only call one parsing function (i.e. parseAbstructFunctionBody, parseDecl, or parseStmtOrExpr), the parser stops at the end of the node. It's not necessary to limit the Lexer to set an ArtificialEOF. To minimize the parsing range, modify the Parser to *not* parse the body if the completion happens in the signature.
This is just not necessary. This parser lives only for the single second pass.
func->getResultInterfaceType()->isVoid()) { | ||
// The function returns void. We don't need an explicit return, no matter | ||
// what the type of the expression is. Take the inserted return back out. | ||
body->setFirstElement(func->getSingleExpressionBody()); |
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.
@DougGregor Do you have any concern about this change?
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.
No, this seems like a clear improvement.
@@ -695,9 +695,6 @@ struct InitializerWithNameAndParam { | |||
struct InitializerWithLabels { | |||
init c d: Int {} | |||
// expected-error @-1 {{expected '(' for initializer parameters}} | |||
// expected-error @-2 {{expected declaration}} | |||
// expected-error @-3 {{consecutive declarations on a line must be separated by ';'}} | |||
// expected-note @-5 {{in declaration of 'InitializerWithLabels'}} |
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.
This is because parseDeclInit
now returns an error state. So the parser property skips to the next decl or '}'
@swift-ci Please smoke test |
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.
Nice cleanup!
func->getResultInterfaceType()->isVoid()) { | ||
// The function returns void. We don't need an explicit return, no matter | ||
// what the type of the expression is. Take the inserted return back out. | ||
body->setFirstElement(func->getSingleExpressionBody()); |
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.
No, this seems like a clear improvement.
parseBraceItemList
,parseDecl
, orparseExprOrStmt
), the parser stops at the end of the node anyways. It's not necessary to limit the Lexer to set an ArtificialEOF. As a ground work, modify the Parser to not parse the body if the completion happens in the signaturegetResultInterfaceType()
to get the result type inTypeCheckFunctionBodyUntilRequest
. So we can type check the body without type checking the signature of the func decl. (This change is actually not needed but I think this is an improvement)