Skip to content

[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

Merged
merged 5 commits into from
Nov 16, 2024

Conversation

DougGregor
Copy link
Member

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.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor enabled auto-merge November 14, 2024 21:52
Copy link
Member

@rintaro rintaro left a 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!

@@ -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());
Copy link
Member

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).

Copy link
Member Author

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.

@@ -1131,6 +1163,8 @@ class TypeEraserAttr final : public DeclAttribute {
static bool classof(const DeclAttribute *DA) {
return DA->getKind() == DeclAttrKind::TypeEraser;
}

UNIMPLEMENTED_CLONE(DynamicReplacementAttr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UNIMPLEMENTED_CLONE(DynamicReplacementAttr)
UNIMPLEMENTED_CLONE(TypeEraserAttr)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thank you!

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@DougGregor DougGregor disabled auto-merge November 15, 2024 01:32
…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.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor enabled auto-merge November 15, 2024 18:52
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test windows

@DougGregor DougGregor merged commit c5de02f into swiftlang:main Nov 16, 2024
3 checks passed
@DougGregor DougGregor deleted the clang-importer-parse-request branch November 17, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants