Skip to content

Revert "[Sema] Fix leak of implementation-only imported types in SPI signatures" #32552

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

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,14 +1483,11 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
}
};

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

void checkTypeImpl(
Type type, const TypeRepr *typeRepr, const SourceFile &SF,
const Decl *context,
const Diagnoser &diagnoser) {
// Don't bother checking errors.
if (type && type->hasError())
Expand All @@ -1503,15 +1500,14 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
if (typeRepr) {
const_cast<TypeRepr *>(typeRepr)->walk(TypeReprIdentFinder(
[&](const ComponentIdentTypeRepr *component) {
TypeDecl *typeDecl = component->getBoundDecl();
ModuleDecl *M = typeDecl->getModuleContext();
bool isImplementationOnly = SF.isImportedImplementationOnly(M);
if (isImplementationOnly ||
(SF.isImportedAsSPI(typeDecl) && !context->isSPI())) {
diagnoser.diagnoseType(typeDecl, component, isImplementationOnly);
foundAnyIssues = true;
}

ModuleDecl *M = component->getBoundDecl()->getModuleContext();
if (!SF.isImportedImplementationOnly(M) &&
!SF.isImportedAsSPI(component->getBoundDecl()))
return true;

diagnoser.diagnoseType(component->getBoundDecl(), component,
SF.isImportedImplementationOnly(M));
foundAnyIssues = true;
// We still continue even in the diagnostic case to report multiple
// violations.
return true;
Expand All @@ -1529,19 +1525,19 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {

class ProblematicTypeFinder : public TypeDeclFinder {
const SourceFile &SF;
const Decl *context;
const Diagnoser &diagnoser;
public:
ProblematicTypeFinder(const SourceFile &SF, const Decl *context, const Diagnoser &diagnoser)
: SF(SF), context(context), diagnoser(diagnoser) {}
ProblematicTypeFinder(const SourceFile &SF, const Diagnoser &diagnoser)
: SF(SF), diagnoser(diagnoser) {}

void visitTypeDecl(const TypeDecl *typeDecl) {
ModuleDecl *M = typeDecl->getModuleContext();
bool isImplementationOnly = SF.isImportedImplementationOnly(M);
if (isImplementationOnly ||
(SF.isImportedAsSPI(typeDecl) && !context->isSPI()))
diagnoser.diagnoseType(typeDecl, /*typeRepr*/nullptr,
isImplementationOnly);
if (!SF.isImportedImplementationOnly(M) &&
!SF.isImportedAsSPI(typeDecl))
return;

diagnoser.diagnoseType(typeDecl, /*typeRepr*/nullptr,
SF.isImportedImplementationOnly(M));
}

void visitSubstitutionMap(SubstitutionMap subs) {
Expand Down Expand Up @@ -1601,15 +1597,15 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
}
};

type.walk(ProblematicTypeFinder(SF, context, diagnoser));
type.walk(ProblematicTypeFinder(SF, diagnoser));
}

void checkType(
Type type, const TypeRepr *typeRepr, const Decl *context,
const Diagnoser &diagnoser) {
auto *SF = context->getDeclContext()->getParentSourceFile();
assert(SF && "checking a non-source declaration?");
return checkTypeImpl(type, typeRepr, *SF, context, diagnoser);
return checkTypeImpl(type, typeRepr, *SF, diagnoser);
}

void checkType(
Expand Down Expand Up @@ -1706,7 +1702,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
AccessScope accessScope =
VD->getFormalAccessScope(nullptr,
/*treatUsableFromInlineAsPublic*/true);
if (accessScope.isPublic())
if (accessScope.isPublic() && !accessScope.isSPI())
return false;

// Is this a stored property in a non-resilient struct or class?
Expand Down
46 changes: 0 additions & 46 deletions test/SPI/implementation_only_spi_import_exposability.swift

This file was deleted.