-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Parser: avoid skipping inactive code if we are building syntax trees. #24850
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
Parser: avoid skipping inactive code if we are building syntax trees. #24850
Conversation
@swift-ci please smoke test |
@@ -19,3 +19,7 @@ class { // expected-error {{unknown declaration syntax exists in the source}} | |||
// expected-error@-4 {{top-level statement cannot begin with a closure expression}} | |||
|
|||
} | |||
|
|||
#if swift(<1) | |||
print("Wat") |
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.
Am I mistaken, or does this really not actually verify anything? It would require that the user manually verify that the inactive region is processed.
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 verifies we can get syntax nodes for inactive code like print("wat")
, otherwise an error message will be emitted to complain about unknown syntax nodes.
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.
How about we add an extra step to sanity check that everything is parsed and round-tripped ?
E.g. add a RUN
line to check that printing the syntax-tree will result in the same output as the input source file.
This will ensure that everything is parsed as expected.
// We shouldn't skip code if we are building syntax tree. | ||
// The parser will keep running and we just discard the AST part. | ||
SmallVector<ASTNode, 16> dropedElements; | ||
parseElements(dropedElements, false); |
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.
Can we disable diagnostics using DiagnosticSuppression
?
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.
Good point!
@swift-ci please smoke test |
@akyrtzi @rintaro Two additional commits were added to disable diagnostics in the inactive code though we parse inside the inactive code. Notice the existing design of syntax tree verifier works as a post-processor. To make it compatible with |
I'm a little concerned about this since we just saw issues with |
8ad1006
to
ad4a4dc
Compare
I think that it shouldn't be the responsibility of What do you think about an alternative solution; we could just disable the syntax-tree verifier in the case where
we'd do:
This has these benefits:
|
If syntax trees are requested, we shouldn't skip inactive code. Notice the inactive code won't be skipped in SwiftSyntax because we always set PerformConditionEvaluation false for the in-process parser. This is mostly needed for testing purposes where we add -verify-syntax-tree to regular compiler invocations. rdar://50837165
ad4a4dc
to
f25925f
Compare
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci Please clean test Linux platform |
Build failed |
@swift-ci Please smoke test OS X platform |
If syntax trees are requested, we shouldn't skip inactive code. Notice the
inactive code won't be skipped in SwiftSyntax because we always set
PerformConditionEvaluation false for the in-process parser.
This is mostly needed for testing purposes where we add -verify-syntax-tree
to regular compiler invocations.
rdar://50837165