Skip to content
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

Merged

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Apr 27, 2018

Progress on rdar://problem/39338239; we still need to infer this attribute though.

@slavapestov slavapestov force-pushed the fix-inlinable-vs-autolinking branch 2 times, most recently from aad64a6 to e8ca0db Compare May 1, 2018 00:49
@slavapestov slavapestov changed the title [WIP] Fix @inlinable -vs- autolinking Plumb through support for 'usable from inline' imports May 1, 2018
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@shahmishal
Copy link
Member

@swift-ci Please test source compatibility

@slavapestov slavapestov requested a review from jrose-apple May 1, 2018 04:10
@jrose-apple
Copy link
Contributor

Sorry, I have no idea what this is for. Maybe I'll talk to you about it in person.

@slavapestov slavapestov force-pushed the fix-inlinable-vs-autolinking branch from e8ca0db to 5d21079 Compare May 1, 2018 22:49
@slavapestov
Copy link
Contributor Author

@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 :-)

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

Public,
Private

// Not @_exported only. Also includes @_usableFromInline.
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

virtual void getImportedModulesForLinking(
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const {
return getImportedModules(imports, ModuleDecl::ImportFilter::Public);
return getImportedModules(imports, ModuleDecl::ImportFilter::UsableFromInline);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -842,6 +843,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
IGNORED_ATTR(Transparent)
IGNORED_ATTR(WarnUnqualifiedAccess)
IGNORED_ATTR(WeakLinked)
IGNORED_ATTR(UsableFromInlineImport)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.
@slavapestov slavapestov force-pushed the fix-inlinable-vs-autolinking branch from 5d21079 to 36e045e Compare May 2, 2018 00:54
Progress on <rdar://problem/39338239>; we still need to infer this
attribute though.
@slavapestov slavapestov force-pushed the fix-inlinable-vs-autolinking branch from 36e045e to db44012 Compare May 2, 2018 00:56
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

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.

Looks good enough for me. Inference part next, right?

@jrose-apple
Copy link
Contributor

(This doc comment comment didn't get addressed though: https://github.com/apple/swift/pull/16211/files#r185358916)

@swift-ci
Copy link
Contributor

swift-ci commented May 2, 2018

Build failed
Swift Test OS X Platform
Git Sha - e8ca0db52333aab69919edec4de0545f2afda5b8

@swift-ci
Copy link
Contributor

swift-ci commented May 2, 2018

Build failed
Swift Test Linux Platform
Git Sha - e8ca0db52333aab69919edec4de0545f2afda5b8

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

jrose-apple pushed a commit to jrose-apple/swift that referenced this pull request May 3, 2018
…autolinking

Plumb through support for 'usable from inline' imports

(cherry picked from commit bb16ee0)
jrose-apple pushed a commit to jrose-apple/swift that referenced this pull request May 3, 2018
…autolinking

Plumb through support for 'usable from inline' imports

(cherry picked from commit bb16ee0)
jrose-apple added a commit to jrose-apple/swift that referenced this pull request May 4, 2018
…able-vs-autolinking"

This reverts commit bb16ee0,
reversing changes made to a8d831f.
It's not sufficient to solve the problem, and the choices were to do
something more complicated, or just take a simple brute force
approach. We're going with the latter.
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