Skip to content

[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

Closed
wants to merge 2 commits into from

Conversation

nathawes
Copy link
Contributor

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 clang external_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:

  • adding the swift module name as an extra argument to the various SWIFT_CLASS, SWIFT_PROTOCOL, and SWIFT_ENUM macros already on top-level decls
  • adding a new SWIFT_MODULE(_module) macro that expands to the attribute on top-level function decls
  • adding a SWIFT_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.

…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.
@nathawes
Copy link
Contributor Author

@swift-ci please smoke test

@nathawes nathawes requested a review from jrose-apple March 15, 2017 20:18
Copy link
Contributor

@jrose-apple jrose-apple left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

@jrose-apple jrose-apple Mar 15, 2017

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.

@@ -204,7 +205,9 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
maybePrintObjCGenericParameters(baseClass);
os << " (SWIFT_EXTENSION(" << origDC->getParentModule()->getName()
<< "))\n";
insideCategory = true;
Copy link
Contributor

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.

Copy link
Contributor Author

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!

@shahmishal
Copy link
Member

@swift-ci please smoke test

@nathawes
Copy link
Contributor Author

@swift-ci please smoke test

@akyrtzi
Copy link
Contributor

akyrtzi commented Apr 24, 2017

This is overridden by #8972

@akyrtzi akyrtzi closed this Apr 24, 2017
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.

4 participants