Skip to content

[Clang importer] Don't cache swift_attr source files that have CustomAttrs with arguments #77962

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

Conversation

DougGregor
Copy link
Member

Since we can't do a proper "deep" clone of expression nodes, cloning such a CustomAttr is necessarily shallow. In such cases, don't cache the swift_attr source files at all, so we get fresh attribute nodes for each such usage.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

break;

for (auto attr : decl->getAttrs()) {
if (auto customAttr = dyn_cast<CustomAttr>(attr)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want to also capture all subclasses with UNIMPLEMENTED_CLONE as well. Do we want the implementation of CustomAttr::clone() to assert if the argument list isn't empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we can do that. Actually, I can avoid the clone here altogether with a different approach that's more similar to how member-attribute macros work.

…Attrs with arguments

Since we can't do a proper "deep" clone of expression nodes, cloning
such a CustomAttr is necessarily shallow. In such cases, don't cache
the swift_attr source files at all, so we get fresh attribute nodes
for each such usage.
@DougGregor DougGregor force-pushed the importer-no-cache-custom-swift-attr branch from f96c910 to 0c91a34 Compare December 4, 2024 23:25
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor enabled auto-merge December 4, 2024 23:25
Copy link
Contributor

@hnrklssn hnrklssn left a comment

Choose a reason for hiding this comment

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

LGTM, just a nonblocking inquiry

case DeclAttrKind::CLASS: \
if (&CLASS##Attr::canClone == &DeclAttribute::canClone) \
return true; \
return static_cast<const CLASS##Attr *>(this)->canClone();
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why this manual dynamic dispatch rather than a virtual function? Does DeclAttribute not have a vtable or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right: there's no vtable, so I don't want to add one.

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor DougGregor merged commit 41efe32 into swiftlang:main Dec 5, 2024
3 checks passed
@DougGregor DougGregor deleted the importer-no-cache-custom-swift-attr branch December 5, 2024 16:24
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.

2 participants