-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Plumb through support for 'usable from inline' imports #16211
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -345,9 +345,17 @@ class ModuleDecl : public DeclContext, public TypeDecl { | |
|
||
/// \sa getImportedModules | ||
enum class ImportFilter { | ||
// Everything. | ||
All, | ||
|
||
// @_exported only. | ||
Public, | ||
Private | ||
|
||
// Not @_exported only. Also includes @_usableFromInline. | ||
Private, | ||
|
||
// @_usableFromInline and @_exported only. | ||
ForLinking | ||
}; | ||
|
||
/// Looks up which modules are imported by this module. | ||
|
@@ -360,11 +368,16 @@ class ModuleDecl : public DeclContext, public TypeDecl { | |
/// Looks up which modules are imported by this module, ignoring any that | ||
/// won't contain top-level decls. | ||
/// | ||
/// This is a performance hack. Do not use for anything but name lookup. | ||
/// May go away in the future. | ||
/// This is a performance hack for the ClangImporter. Do not use for | ||
/// anything but name lookup. May go away in the future. | ||
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 commentThe 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 commentThe 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. |
||
void | ||
getImportedModulesForLinking(SmallVectorImpl<ImportedModule> &imports) const; | ||
|
||
/// Finds all top-level decls of this module. | ||
/// | ||
/// This does a simple local lookup, not recursively looking through imports. | ||
|
@@ -402,11 +415,16 @@ class ModuleDecl : public DeclContext, public TypeDecl { | |
/// results, with the given access path. | ||
/// \param fn A callback of type bool(ImportedModule) or void(ImportedModule). | ||
/// Return \c false to abort iteration. | ||
/// \param includeLinkOnlyModules Include modules that are not visible to | ||
/// name lookup but must be linked in because inlinable code can | ||
/// reference their symbols. | ||
/// | ||
/// \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 commentThe 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 commentThe 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. |
||
|
||
|
||
/// @} | ||
|
||
|
@@ -638,6 +656,12 @@ class FileUnit : public DeclContext { | |
return getImportedModules(imports, ModuleDecl::ImportFilter::Public); | ||
} | ||
|
||
/// \see ModuleDecl::getImportedModulesForLinking | ||
virtual void getImportedModulesForLinking( | ||
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const { | ||
return getImportedModules(imports, ModuleDecl::ImportFilter::ForLinking); | ||
} | ||
|
||
/// Generates the list of libraries needed to link this file, based on its | ||
/// imports. | ||
virtual void | ||
|
@@ -649,11 +673,15 @@ class FileUnit : public DeclContext { | |
/// | ||
/// \param fn A callback of type bool(ImportedModule) or void(ImportedModule). | ||
/// Return \c false to abort iteration. | ||
/// \param includeLinkOnlyModules Include modules that are not visible to | ||
/// name lookup but must be linked in because inlinable code can | ||
/// reference their symbols. | ||
/// | ||
/// \return True if the traversal ran to completion, false if it ended early | ||
/// due to the callback. | ||
bool | ||
forAllVisibleModules(llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn); | ||
forAllVisibleModules(llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn, | ||
bool includeLinkOnlyModules = false); | ||
|
||
/// @} | ||
|
||
|
@@ -732,13 +760,17 @@ class SourceFile final : public FileUnit { | |
}; | ||
|
||
/// Possible attributes for imports in source files. | ||
enum class ImportFlags { | ||
enum class ImportFlags : uint8_t { | ||
/// The imported module is exposed to anyone who imports the parent module. | ||
Exported = 0x1, | ||
|
||
/// This source file has access to testable declarations in the imported | ||
/// module. | ||
Testable = 0x2 | ||
Testable = 0x2, | ||
|
||
/// Modules that depend on the module containing this source file will | ||
/// autolink this dependency. | ||
UsableFromInline = 0x4, | ||
}; | ||
|
||
/// \see ImportFlags | ||
|
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