Skip to content

Commit e3d93ef

Browse files
committed
Revert "[Sema] Fix leak of implementation-only imported types in SPI signatures"
This reverts commit 08abc0d.
1 parent a890d8b commit e3d93ef

File tree

2 files changed

+19
-69
lines changed

2 files changed

+19
-69
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,14 +1483,11 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
14831483
}
14841484
};
14851485

1486-
// Diagnose public APIs exposing types that are either imported as
1487-
// implementation-only or declared as SPI.
14881486
class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
14891487
class Diagnoser;
14901488

14911489
void checkTypeImpl(
14921490
Type type, const TypeRepr *typeRepr, const SourceFile &SF,
1493-
const Decl *context,
14941491
const Diagnoser &diagnoser) {
14951492
// Don't bother checking errors.
14961493
if (type && type->hasError())
@@ -1503,15 +1500,14 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
15031500
if (typeRepr) {
15041501
const_cast<TypeRepr *>(typeRepr)->walk(TypeReprIdentFinder(
15051502
[&](const ComponentIdentTypeRepr *component) {
1506-
TypeDecl *typeDecl = component->getBoundDecl();
1507-
ModuleDecl *M = typeDecl->getModuleContext();
1508-
bool isImplementationOnly = SF.isImportedImplementationOnly(M);
1509-
if (isImplementationOnly ||
1510-
(SF.isImportedAsSPI(typeDecl) && !context->isSPI())) {
1511-
diagnoser.diagnoseType(typeDecl, component, isImplementationOnly);
1512-
foundAnyIssues = true;
1513-
}
1514-
1503+
ModuleDecl *M = component->getBoundDecl()->getModuleContext();
1504+
if (!SF.isImportedImplementationOnly(M) &&
1505+
!SF.isImportedAsSPI(component->getBoundDecl()))
1506+
return true;
1507+
1508+
diagnoser.diagnoseType(component->getBoundDecl(), component,
1509+
SF.isImportedImplementationOnly(M));
1510+
foundAnyIssues = true;
15151511
// We still continue even in the diagnostic case to report multiple
15161512
// violations.
15171513
return true;
@@ -1529,19 +1525,19 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
15291525

15301526
class ProblematicTypeFinder : public TypeDeclFinder {
15311527
const SourceFile &SF;
1532-
const Decl *context;
15331528
const Diagnoser &diagnoser;
15341529
public:
1535-
ProblematicTypeFinder(const SourceFile &SF, const Decl *context, const Diagnoser &diagnoser)
1536-
: SF(SF), context(context), diagnoser(diagnoser) {}
1530+
ProblematicTypeFinder(const SourceFile &SF, const Diagnoser &diagnoser)
1531+
: SF(SF), diagnoser(diagnoser) {}
15371532

15381533
void visitTypeDecl(const TypeDecl *typeDecl) {
15391534
ModuleDecl *M = typeDecl->getModuleContext();
1540-
bool isImplementationOnly = SF.isImportedImplementationOnly(M);
1541-
if (isImplementationOnly ||
1542-
(SF.isImportedAsSPI(typeDecl) && !context->isSPI()))
1543-
diagnoser.diagnoseType(typeDecl, /*typeRepr*/nullptr,
1544-
isImplementationOnly);
1535+
if (!SF.isImportedImplementationOnly(M) &&
1536+
!SF.isImportedAsSPI(typeDecl))
1537+
return;
1538+
1539+
diagnoser.diagnoseType(typeDecl, /*typeRepr*/nullptr,
1540+
SF.isImportedImplementationOnly(M));
15451541
}
15461542

15471543
void visitSubstitutionMap(SubstitutionMap subs) {
@@ -1601,15 +1597,15 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
16011597
}
16021598
};
16031599

1604-
type.walk(ProblematicTypeFinder(SF, context, diagnoser));
1600+
type.walk(ProblematicTypeFinder(SF, diagnoser));
16051601
}
16061602

16071603
void checkType(
16081604
Type type, const TypeRepr *typeRepr, const Decl *context,
16091605
const Diagnoser &diagnoser) {
16101606
auto *SF = context->getDeclContext()->getParentSourceFile();
16111607
assert(SF && "checking a non-source declaration?");
1612-
return checkTypeImpl(type, typeRepr, *SF, context, diagnoser);
1608+
return checkTypeImpl(type, typeRepr, *SF, diagnoser);
16131609
}
16141610

16151611
void checkType(
@@ -1706,7 +1702,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
17061702
AccessScope accessScope =
17071703
VD->getFormalAccessScope(nullptr,
17081704
/*treatUsableFromInlineAsPublic*/true);
1709-
if (accessScope.isPublic())
1705+
if (accessScope.isPublic() && !accessScope.isSPI())
17101706
return false;
17111707

17121708
// Is this a stored property in a non-resilient struct or class?

test/SPI/implementation_only_spi_import_exposability.swift

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)