@@ -1454,47 +1454,40 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1454
1454
}
1455
1455
};
1456
1456
1457
+ // / Returns the kind of origin, implementation-only import or SPI declaration,
1458
+ // / that restricts exporting \p decl from the given file and context.
1459
+ // /
1460
+ // / Local variant to swift::getDisallowedOriginKind for downgrade to warnings.
1461
+ DisallowedOriginKind
1462
+ getDisallowedOriginKind (const Decl *decl,
1463
+ const SourceFile &userSF,
1464
+ const Decl *userContext,
1465
+ DowngradeToWarning &downgradeToWarning) {
1466
+ downgradeToWarning = DowngradeToWarning::No;
1467
+ ModuleDecl *M = decl->getModuleContext ();
1468
+ if (userSF.isImportedImplementationOnly (M)) {
1469
+ // Temporarily downgrade implementation-only exportability in SPI to
1470
+ // a warning.
1471
+ if (userContext->isSPI ())
1472
+ downgradeToWarning = DowngradeToWarning::Yes;
1473
+
1474
+ // Implementation-only imported, cannot be reexported.
1475
+ return DisallowedOriginKind::ImplementationOnly;
1476
+ } else if (decl->isSPI () && !userContext->isSPI ()) {
1477
+ // SPI can only be exported in SPI.
1478
+ return userContext->getModuleContext () == M ?
1479
+ DisallowedOriginKind::SPILocal :
1480
+ DisallowedOriginKind::SPIImported;
1481
+ }
1482
+
1483
+ return DisallowedOriginKind::None;
1484
+ };
1485
+
1457
1486
// Diagnose public APIs exposing types that are either imported as
1458
1487
// implementation-only or declared as SPI.
1459
1488
class ExportabilityChecker : public DeclVisitor <ExportabilityChecker> {
1460
1489
class Diagnoser ;
1461
1490
1462
- // Problematic origin of an exported type.
1463
- //
1464
- // This enum must be kept in sync with
1465
- // diag::decl_from_hidden_module and
1466
- // diag::conformance_from_implementation_only_module.
1467
- enum class DisallowedOriginKind : uint8_t {
1468
- ImplementationOnly,
1469
- SPIImported,
1470
- SPILocal,
1471
- None
1472
- };
1473
-
1474
- // If there's an exportability problem with \p typeDecl, get its origin kind.
1475
- static DisallowedOriginKind getDisallowedOriginKind (
1476
- const TypeDecl *typeDecl, const SourceFile &SF, const Decl *context,
1477
- DowngradeToWarning &downgradeToWarning) {
1478
- downgradeToWarning = DowngradeToWarning::No;
1479
- ModuleDecl *M = typeDecl->getModuleContext ();
1480
- if (SF.isImportedImplementationOnly (M)) {
1481
- // Temporarily downgrade implementation-only exportability in SPI to
1482
- // a warning.
1483
- if (context->isSPI ())
1484
- downgradeToWarning = DowngradeToWarning::Yes;
1485
-
1486
- // Implementation-only imported, cannot be reexported.
1487
- return DisallowedOriginKind::ImplementationOnly;
1488
- } else if (typeDecl->isSPI () && !context->isSPI ()) {
1489
- // SPI can only be exported in SPI.
1490
- return context->getModuleContext () == M ?
1491
- DisallowedOriginKind::SPILocal :
1492
- DisallowedOriginKind::SPIImported;
1493
- }
1494
-
1495
- return DisallowedOriginKind::None;
1496
- };
1497
-
1498
1491
void checkTypeImpl (
1499
1492
Type type, const TypeRepr *typeRepr, const SourceFile &SF,
1500
1493
const Decl *context,
@@ -2067,6 +2060,13 @@ static void checkExtensionGenericParamAccess(const ExtensionDecl *ED) {
2067
2060
ED, ED, desiredAccessScope, userSpecifiedAccess);
2068
2061
}
2069
2062
2063
+ DisallowedOriginKind swift::getDisallowedOriginKind (const Decl *decl,
2064
+ const SourceFile &userSF,
2065
+ const Decl *declContext) {
2066
+ auto downgradeToWarning = DowngradeToWarning::No;
2067
+ return getDisallowedOriginKind (decl, userSF, declContext, downgradeToWarning);
2068
+ }
2069
+
2070
2070
void swift::checkAccessControl (Decl *D) {
2071
2071
if (isa<ValueDecl>(D) || isa<PatternBindingDecl>(D)) {
2072
2072
AccessControlChecker ().visit (D);
0 commit comments