-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Plumb through support for 'usable from inline' imports #16211
Plumb through support for 'usable from inline' imports #16211
Conversation
aad64a6
to
e8ca0db
Compare
@swift-ci Please test |
@swift-ci Please test source compatibility |
1 similar comment
@swift-ci Please test source compatibility |
Sorry, I have no idea what this is for. Maybe I'll talk to you about it in person. |
e8ca0db
to
5d21079
Compare
@jrose-apple I renamed the attribute as you requested. Hopefully you have an idea of what this is for now that we've talked in person :-) |
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
Public, | ||
Private | ||
|
||
// Not @_exported only. Also includes @_usableFromInline. |
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.
Hm, if these categories already aren't mutually exclusive, I think I'd suggest having UsableFromInline also include Public, as we discussed (which might suggest calling it "ForLinking" or something instead).
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.
Done
void | ||
getImportedModulesForLookup(SmallVectorImpl<ImportedModule> &imports) const; | ||
|
||
/// Extension of the above hack. Identical to getImportedModulesForLookup() | ||
/// for imported modules, otherwise also includes @usableFromInline imports. |
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.
Swift modules are also "imported modules" as far as AST goes, but either way it seems like an implementation detail that's not worth mentioning here. Those functions are virtual for a reason.
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.
I meant "Clang imported modules" I guess. I'll change the doc comment in the next PR.
/// | ||
/// \return True if the traversal ran to completion, false if it ended early | ||
/// due to the callback. | ||
bool forAllVisibleModules(AccessPathTy topLevelAccessPath, | ||
llvm::function_ref<bool(ImportedModule)> fn); | ||
llvm::function_ref<bool(ImportedModule)> fn, | ||
bool includeLinkOnlyModules = false); |
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.
*sigh* Should this just take an ImportFilter at this point?
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.
It's not quite an ImportFilter, because it's used to decide if we want to call getImportedModulesForLookup() vs getImportedModulesForLinking(). Since those two are only overridden by ClangModuleUnit and the comments allude to some caching they do, I suspect it could be refactored further, but maybe we can tackle this later.
include/swift/AST/Module.h
Outdated
virtual void getImportedModulesForLinking( | ||
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const { | ||
return getImportedModules(imports, ModuleDecl::ImportFilter::Public); | ||
return getImportedModules(imports, ModuleDecl::ImportFilter::UsableFromInline); |
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.
Copy/paste error here. Should there have been a test that catches this, or is it just that this is overridden everywhere in practice?
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.
I'm not sure what the error is -- the set of modules for linking includes public (@_exported) imports, and @_usableFromInline imports.
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.
There's a return
, so the second line never happens.
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.
Oops, thanks. Yeah, I'll add a test. You need to have both an @_exported and @_usableFromInline import.
lib/Sema/TypeCheckAttr.cpp
Outdated
@@ -842,6 +843,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> { | |||
IGNORED_ATTR(Transparent) | |||
IGNORED_ATTR(WarnUnqualifiedAccess) | |||
IGNORED_ATTR(WeakLinked) | |||
IGNORED_ATTR(UsableFromInlineImport) |
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: This particular list is alphabetized; please keep it that way.
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.
Done
lib/Serialization/ModuleFile.cpp
Outdated
@@ -1666,6 +1675,9 @@ void ModuleFile::getImportDecls(SmallVectorImpl<Decl *> &Results) { | |||
if (Dep.isExported()) | |||
ID->getAttrs().add( | |||
new (Ctx) ExportedAttr(/*IsImplicit=*/false)); | |||
if (Dep.isUsableFromInline()) | |||
ID->getAttrs().add( | |||
new (Ctx) UsableFromInlineAttr(/*IsImplicit=*/false)); |
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.
This should be UsableFromInlineImportAttr…and should probably be marked implicit because we don't want to show them to users at this time.
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.
Sure. How can I test this?
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.
test/IDE/print_clang_framework_with_overlay.swift
uses swift-ide-test to print a Clang framework's imports; you should be able to do the same sort of thing for a Swift module.
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.
Done.
ModuleDecl::forAllVisibleModules() now has a includeLinkOnlyModules parameter. This is intended to be used when computing the set of libraries to autolink.
5d21079
to
36e045e
Compare
Progress on <rdar://problem/39338239>; we still need to infer this attribute though.
36e045e
to
db44012
Compare
@swift-ci Please smoke test |
@swift-ci Please 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.
Looks good enough for me. Inference part next, right?
(This doc comment comment didn't get addressed though: https://github.com/apple/swift/pull/16211/files#r185358916) |
Build failed |
Build failed |
@swift-ci Please test source compatibility |
1 similar comment
@swift-ci Please test source compatibility |
…autolinking Plumb through support for 'usable from inline' imports (cherry picked from commit bb16ee0)
…autolinking Plumb through support for 'usable from inline' imports (cherry picked from commit bb16ee0)
Progress on rdar://problem/39338239; we still need to infer this attribute though.