-
Notifications
You must be signed in to change notification settings - Fork 441
[SwiftParser] Parse @abi attribute arguments even without feature flag #3062
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
@swift-ci Please test |
69087d0
to
eedcc5f
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@rintaro I think if the feature is not enabled the whole attribute is not supported, is it possible to move UnexpectedNodesSyntax up to cover not just argument but the attribute node itself? |
I think the new diagnostic should be about |
Any |
Is there a specific reason that made you suggest that? |
I was just looking at the diagnostics you added and they don't seem super useful, it feels like we should either accept the presence of the attribute and validate it fully or skip it all together if the feature is not enabled. That's something we do in TypeCheckAttr by diagnosing the attribute and marking it as invalid when the feature is not there... |
I'll have to tweak a |
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.
I want to note that this is technically source breaking in case somebody has a custom attribute defined as @abi
, eg. the following was correctly parsable using the new parser before this PR and now no longer is. But we broke this kind of code in the C++ parser already, so I don’t think it’s a big deal.
@globalActor
actor abi {
static let shared: abi = abi()
}
@abi struct Foo {}
AttributeSyntax( | ||
attributeName: TypeSyntax("abi"), | ||
leftParen: .leftParenToken(), | ||
[Syntax(try! FunctionDeclSyntax("func fn() -> Int"))], |
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.
Could make the test function throws
and then avoid the try!
here.
[Syntax(try! FunctionDeclSyntax("func fn() -> Int"))], | |
[Syntax(try FunctionDeclSyntax("func fn() -> Int"))], |
When the parser see `@abi` attribute without the language feature enabled, not parsing the interior causes catastrophic breakage in the tree. To avoid that, parse the argument decl is parsed, but instead of generating `ABIAttributeArgumentsSyntax`, store it as a `UnexpectedNodesSyntax` after the left-paren.
eedcc5f
to
7e8f21c
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test Linux |
When the parser see
@abi
attribute without the language feature enabled, not parsing the interior causes catastrophic breakage in the tree. To avoid that, parse the argument decl is parsed, but instead of generatingABIAttributeArgumentsSyntax
, store it as aUnexpectedNodesSyntax
after the left-paren.