-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[usr-generation][print-as-objc] Namespace @objc (clang-style) USRs with the swift module name #8117
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
…th the swift module name This is to avoid USR collisions between symbols from different Swift frameworks with the same name. Also update PrintAsObjC to add the new clang external_source_symbol attribute with the module name on the printed decls so the objective C USR generation can do the same.
@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.
Small comments only, otherwise this looks good.
OS << "@E@" << ObjCName; // FIXME: expose clang API to handle enum names | ||
// FIXME: expose clang API to handle enum names | ||
OS << "@M@" << ModuleName; | ||
OS << "@E@" << ObjCName; | ||
} else if (isa<EnumElementDecl>(D)) { | ||
OS << "@" << ObjCName; |
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.
Don't these need to be namespaced with the module name too? And methods, and properties?
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.
They all get namespaced with their type context's USR fragment, so they'll pick up their context's module namespacing (test/IDE/print_usrs.swift has examples). Are there any cases where that won't be enough?
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.
Ah, I didn't realize that circled back through this code; I thought the "@M
" would just be omitted.
It may not be sufficient for extension methods, though, which can be added in a different module than the type being extended.
lib/PrintAsObjC/PrintAsObjC.cpp
Outdated
@@ -204,7 +205,9 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>, | |||
maybePrintObjCGenericParameters(baseClass); | |||
os << " (SWIFT_EXTENSION(" << origDC->getParentModule()->getName() | |||
<< "))\n"; | |||
insideCategory = true; |
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.
Nitpick: mind using llvm::SaveAndRestore here? It may seem like overkill for straight-line code, but it's more future-proof.
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.
Wasn't aware of it, actually – thanks!
@swift-ci please smoke test |
@swift-ci please smoke test |
This is overridden by #8972 |
This patch prefixes the clang-style USRs of
@objc
symbols with the swift module name to avoid USR collisions between symbols from different Swift frameworks with the same name. It also updates PrintAsObjC to add the new clangexternal_source_symbol
attribute (with the swift module name) on the generated ObjC decls so that clang's USR generation can add the prefix too.At the moment this is done by:
SWIFT_CLASS
,SWIFT_PROTOCOL
, andSWIFT_ENUM
macros already on top-level declsSWIFT_MODULE(_module)
macro that expands to the attribute on top-level function declsSWIFT_GENERATED
object-like macro to the members of categories, which don't support attributes themselves. The module name isn't needed in this case as the USRs of these members are based on the original interface, which should have the attribute.The plan is to move to using the new pragma under review at https://reviews.llvm.org/D30009 when it lands, so there isn't as much noise in the header (especially for categories), but this lets us progress for now.
Resolves rdar://problem/30645863.