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 {
25
25
26
26
class PersistentParserState ;
27
27
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
+
28
37
// / A file containing Swift source code.
29
38
// /
30
39
// / 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 {
336
345
// / If not, we can fast-path module checks.
337
346
bool hasImplementationOnlyImports () const ;
338
347
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 ;
340
350
341
351
// / Find all SPI names imported from \p importedModule by this file,
342
352
// / collecting the identifiers in \p spiGroups.
Original file line number Diff line number Diff line change @@ -2438,12 +2438,7 @@ bool SourceFile::hasTestableOrPrivateImport(
2438
2438
});
2439
2439
}
2440
2440
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 {
2447
2442
auto &imports = getASTContext ().getImportCache ();
2448
2443
2449
2444
// Look at the imports of this source file.
@@ -2455,11 +2450,14 @@ bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
2455
2450
// If the module is imported this way, it's not imported
2456
2451
// implementation-only.
2457
2452
if (imports.isImportedBy (module , desc.module .importedModule ))
2458
- return false ;
2453
+ return RestrictedImportKind::None ;
2459
2454
}
2460
2455
2461
2456
// 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;
2463
2461
}
2464
2462
2465
2463
bool 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,
1503
1503
downgradeToWarning = DowngradeToWarning::No;
1504
1504
ModuleDecl *M = decl->getModuleContext ();
1505
1505
auto *SF = where.getDeclContext ()->getParentSourceFile ();
1506
- if (SF->isImportedImplementationOnly (M)) {
1506
+
1507
+ RestrictedImportKind howImported = SF->getRestrictedImportKind (M);
1508
+ if (howImported != RestrictedImportKind::None) {
1507
1509
// Temporarily downgrade implementation-only exportability in SPI to
1508
1510
// a warning.
1509
1511
if (where.isSPI ())
@@ -1883,7 +1885,8 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
1883
1885
1884
1886
const SourceFile *SF = refDecl->getDeclContext ()->getParentSourceFile ();
1885
1887
ModuleDecl *M = PGD->getModuleContext ();
1886
- if (!SF->isImportedImplementationOnly (M))
1888
+ RestrictedImportKind howImported = SF->getRestrictedImportKind (M);
1889
+ if (howImported == RestrictedImportKind::None)
1887
1890
return ;
1888
1891
1889
1892
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) {
2332
2332
assert (SF && " checking a non-source declaration?" );
2333
2333
2334
2334
ModuleDecl *M = overridden->getModuleContext ();
2335
- if (SF->isImportedImplementationOnly (M)) {
2335
+ if (SF->getRestrictedImportKind (M) == RestrictedImportKind::ImplementationOnly ) {
2336
2336
VD->diagnose (diag::implementation_only_override_import_without_attr,
2337
2337
overridden->getDescriptiveKind ())
2338
2338
.fixItInsert (VD->getAttributeInsertionLoc (false ),
You can’t perform that action at this time.
0 commit comments