-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes #77628
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
[Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes #77628
Conversation
@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.
Thank you for doing this!
include/swift/AST/Attr.h
Outdated
@@ -1802,6 +1902,11 @@ class CustomAttr final : public DeclAttribute { | |||
return DA->getKind() == DeclAttrKind::Custom; | |||
} | |||
|
|||
/// Create a copy of this attribute. | |||
CustomAttr *clone(ASTContext &ctx) const { | |||
return create(ctx, AtLoc, getTypeExpr(), isImplicit()); |
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.
ArgumentList *argList;
and PatternBindingInitializer *initContext;
are not cloned. Do we need to support CustomAttr
in swift_attrs? If not, we should make this UNIMPLEMENTED_CLONE
, then skip CustomAttr
before cloning in ImportDecl (and diagnose).
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.
We do need CustomAttr
, yes.
include/swift/AST/Attr.h
Outdated
@@ -1131,6 +1163,8 @@ class TypeEraserAttr final : public DeclAttribute { | |||
static bool classof(const DeclAttribute *DA) { | |||
return DA->getKind() == DeclAttrKind::TypeEraser; | |||
} | |||
|
|||
UNIMPLEMENTED_CLONE(DynamicReplacementAttr) |
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.
UNIMPLEMENTED_CLONE(DynamicReplacementAttr) | |
UNIMPLEMENTED_CLONE(TypeEraserAttr) |
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 catch, thank you!
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!
…tributes The Clang importer was directly calling into the parser to parse the attribute (or modifier) within swift_attr. Aside from being gross, this isn't possible with ASTGen. Instead, teach ParseSourceFileRequest to deal with modifiers in the same way that the Clang importer was hardcoding, and have the Clang importer pull the attributes/modifiers off of the "missing" declaration introduced by the request. One benefit of this approach is that we're only parsing each swift_attr source buffer once, then cloning the attributes each time it's used, so we should be doing less work overall. Fixes rdar://139119159.
…erly-typed clone() Code review identified some incorrect UNIMPLEMENTED_CLONEs in DeclAttribute (thank you Hamish and Rintaro). Fix those, and make sure this can't happen again by checking the type signatures of clone() in every DeclAttribute subclass.
62960e1
to
24a12eb
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test windows |
The Clang importer was directly calling into the parser to parse the
attribute (or modifier) within swift_attr. Aside from being gross, this
isn't possible with ASTGen.
Instead, teach ParseSourceFileRequest to deal with modifiers in the
same way that the Clang importer was hardcoding, and have the Clang
importer pull the attributes/modifiers off of the "missing"
declaration introduced by the request.
One benefit of this approach is that we're only parsing each
swift_attr source buffer once, then cloning the attributes each time
it's used, so we should be doing less work overall.
Fixes rdar://139119159.