Skip to content

Commit be73343

Browse files
authored
Merge pull request swiftlang#34372 from slavapestov/more-export-context-refactoring
Generalize ExportContext and use it for deprecation and unavailability
2 parents a790439 + 85d2495 commit be73343

12 files changed

+339
-196
lines changed

include/swift/AST/DeclContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace swift {
5757
class GenericTypeParamType;
5858
class InfixOperatorDecl;
5959
class InfixOperatorLookupResult;
60+
enum class PlatformKind: uint8_t;
6061
class PrecedenceGroupDecl;
6162
class ProtocolDecl;
6263
class Requirement;

lib/Sema/TypeCheckAccess.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
15131513
loc = varDecl->getNameLoc();
15141514

15151515
diagnoseTypeAvailability(typeRepr, type, loc,
1516-
Where.forReason(reason), flags);
1516+
Where.withReason(reason), flags);
15171517
}
15181518

15191519
void checkGenericParams(const GenericContext *ownerCtx,
@@ -1541,8 +1541,8 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
15411541
}
15421542

15431543
public:
1544-
explicit DeclAvailabilityChecker(Decl *D)
1545-
: Where(ExportContext::forDeclSignature(D)) {}
1544+
explicit DeclAvailabilityChecker(ExportContext where)
1545+
: Where(where) {}
15461546

15471547
// Force all kinds to be handled at a lower level.
15481548
void visitDecl(Decl *D) = delete;
@@ -1751,14 +1751,14 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
17511751
return isExported(valueMember);
17521752
});
17531753

1754-
Where = wasWhere.forExported(hasExportedMembers);
1755-
checkType(ED->getExtendedType(), ED->getExtendedTypeRepr(), ED,
1754+
Where = wasWhere.withExported(hasExportedMembers);
1755+
checkType(ED->getExtendedType(), ED->getExtendedTypeRepr(), ED,
17561756
ExportabilityReason::ExtensionWithPublicMembers);
17571757

17581758
// 3) If the extension contains exported members or defines conformances,
17591759
// the 'where' clause must only name exported types.
1760-
Where = wasWhere.forExported(hasExportedMembers ||
1761-
!ED->getInherited().empty());
1760+
Where = wasWhere.withExported(hasExportedMembers ||
1761+
!ED->getInherited().empty());
17621762
checkConstrainedExtensionRequirements(ED, hasExportedMembers);
17631763
}
17641764

@@ -1857,9 +1857,12 @@ void swift::checkAccessControl(Decl *D) {
18571857
checkExtensionGenericParamAccess(ED);
18581858
}
18591859

1860-
//ExportabilityChecker().visit(D);
1861-
if (D->isImplicit() || isa<AccessorDecl>(D))
1860+
if (isa<AccessorDecl>(D))
18621861
return;
18631862

1864-
DeclAvailabilityChecker(D).visit(D);
1863+
auto where = ExportContext::forDeclSignature(D);
1864+
if (where.isImplicit())
1865+
return;
1866+
1867+
DeclAvailabilityChecker(where).visit(D);
18651868
}

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "MiscDiagnostics.h"
18+
#include "TypeCheckAvailability.h"
1819
#include "TypeCheckConcurrency.h"
1920
#include "TypeCheckObjC.h"
2021
#include "TypeCheckType.h"
@@ -1987,6 +1988,9 @@ SynthesizeMainFunctionRequest::evaluate(Evaluator &evaluator,
19871988
mainFunction = viableCandidates[0];
19881989
}
19891990

1991+
auto where = ExportContext::forDeclSignature(D);
1992+
diagnoseDeclAvailability(mainFunction, attr->getRange(), where, None);
1993+
19901994
auto *const func = FuncDecl::createImplicit(
19911995
context, StaticSpellingKind::KeywordStatic,
19921996
DeclName(context, DeclBaseName(context.Id_MainEntryPoint),

0 commit comments

Comments
 (0)