File tree Expand file tree Collapse file tree 4 files changed +23
-12
lines changed Expand file tree Collapse file tree 4 files changed +23
-12
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,15 @@ namespace swift {
2525
2626class PersistentParserState ;
2727
28+ // / Kind of import affecting how a decl can be reexported.
29+ // / This is a subset of \c DisallowedOriginKind.
30+ // /
31+ // / \sa getRestrictedImportKind
32+ enum class RestrictedImportKind {
33+ ImplementationOnly,
34+ None // No restriction, i.e. the module is imported publicly.
35+ };
36+
2837// / A file containing Swift source code.
2938// /
3039// / This is a .swift or .sil file (or a virtual file, such as the contents of
@@ -336,7 +345,8 @@ class SourceFile final : public FileUnit {
336345 // / If not, we can fast-path module checks.
337346 bool hasImplementationOnlyImports () const ;
338347
339- bool isImportedImplementationOnly (const ModuleDecl *module ) const ;
348+ // / Get the most permissive restriction applied to the imports of \p module.
349+ RestrictedImportKind getRestrictedImportKind (const ModuleDecl *module ) const ;
340350
341351 // / Find all SPI names imported from \p importedModule by this file,
342352 // / collecting the identifiers in \p spiGroups.
Original file line number Diff line number Diff line change @@ -2438,12 +2438,7 @@ bool SourceFile::hasTestableOrPrivateImport(
24382438 });
24392439}
24402440
2441- bool SourceFile::isImportedImplementationOnly (const ModuleDecl *module ) const {
2442- // Implementation-only imports are (currently) always source-file-specific,
2443- // so if we don't have any, we know the search is complete.
2444- if (!hasImplementationOnlyImports ())
2445- return false ;
2446-
2441+ RestrictedImportKind SourceFile::getRestrictedImportKind (const ModuleDecl *module ) const {
24472442 auto &imports = getASTContext ().getImportCache ();
24482443
24492444 // Look at the imports of this source file.
@@ -2455,11 +2450,14 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
24552450 // If the module is imported this way, it's not imported
24562451 // implementation-only.
24572452 if (imports.isImportedBy (module , desc.module .importedModule ))
2458- return false ;
2453+ return RestrictedImportKind::None ;
24592454 }
24602455
24612456 // Now check this file's enclosing module in case there are re-exports.
2462- return !imports.isImportedBy (module , getParentModule ());
2457+ if (imports.isImportedBy (module , getParentModule ()))
2458+ return RestrictedImportKind::None;
2459+
2460+ return RestrictedImportKind::ImplementationOnly;
24632461}
24642462
24652463bool ModuleDecl::isImportedImplementationOnly (const ModuleDecl *module ) const {
Original file line number Diff line number Diff line change @@ -1503,7 +1503,9 @@ swift::getDisallowedOriginKind(const Decl *decl,
15031503 downgradeToWarning = DowngradeToWarning::No;
15041504 ModuleDecl *M = decl->getModuleContext ();
15051505 auto *SF = where.getDeclContext ()->getParentSourceFile ();
1506- if (SF->isImportedImplementationOnly (M)) {
1506+
1507+ RestrictedImportKind howImported = SF->getRestrictedImportKind (M);
1508+ if (howImported != RestrictedImportKind::None) {
15071509 // Temporarily downgrade implementation-only exportability in SPI to
15081510 // a warning.
15091511 if (where.isSPI ())
@@ -1883,7 +1885,8 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
18831885
18841886 const SourceFile *SF = refDecl->getDeclContext ()->getParentSourceFile ();
18851887 ModuleDecl *M = PGD->getModuleContext ();
1886- if (!SF->isImportedImplementationOnly (M))
1888+ RestrictedImportKind howImported = SF->getRestrictedImportKind (M);
1889+ if (howImported == RestrictedImportKind::None)
18871890 return ;
18881891
18891892 auto &DE = PGD->getASTContext ().Diags ;
Original file line number Diff line number Diff line change @@ -2332,7 +2332,7 @@ void swift::checkImplementationOnlyOverride(const ValueDecl *VD) {
23322332 assert (SF && " checking a non-source declaration?" );
23332333
23342334 ModuleDecl *M = overridden->getModuleContext ();
2335- if (SF->isImportedImplementationOnly (M)) {
2335+ if (SF->getRestrictedImportKind (M) == RestrictedImportKind::ImplementationOnly ) {
23362336 VD->diagnose (diag::implementation_only_override_import_without_attr,
23372337 overridden->getDescriptiveKind ())
23382338 .fixItInsert (VD->getAttributeInsertionLoc (false ),
You can’t perform that action at this time.
0 commit comments