Skip to content

Commit b03d246

Browse files
authored
Merge pull request #34473 from slavapestov/export-context-os-version
Put the AvailabilityContext into the ExportContext
2 parents a69502e + ae5bca9 commit b03d246

15 files changed

+236
-149
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,7 @@ NOTE(construct_raw_representable_from_unwrapped_value,none,
27342734

27352735
ERROR(decl_from_hidden_module,none,
27362736
"cannot use %0 %1 %select{here|as property wrapper here|"
2737+
"as result builder here|"
27372738
"in an extension with public or '@usableFromInline' members|"
27382739
"in an extension with conditional conformances}2; "
27392740
"%select{%3 has been imported as implementation-only|"
@@ -2742,12 +2743,14 @@ ERROR(decl_from_hidden_module,none,
27422743
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
27432744
WARNING(decl_from_hidden_module_warn,none,
27442745
"cannot use %0 %1 %select{in SPI|as property wrapper in SPI|"
2746+
"as result builder in SPI|"
27452747
"in an extension with public or '@usableFromInline' members|"
27462748
"in an extension with conditional conformances}2; "
27472749
"%select{%3 has been imported as implementation-only}4",
27482750
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
27492751
ERROR(conformance_from_implementation_only_module,none,
27502752
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
2753+
"as result builder here|"
27512754
"in an extension with public or '@usableFromInline' members|"
27522755
"in an extension with conditional conformances}2; "
27532756
"%select{%3 has been imported as implementation-only|"

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,9 @@ class BuilderClosureRewriter
12441244
if (!nominal)
12451245
return false;
12461246

1247+
ExportContext where = ExportContext::forFunctionBody(dc, loc);
12471248
if (auto reason = TypeChecker::checkDeclarationAvailability(
1248-
nominal, loc, dc)) {
1249+
nominal, where)) {
12491250
ctx.Diags.diagnose(
12501251
loc, diag::result_builder_missing_limited_availability,
12511252
builderTransform.builderType);

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//===----------------------------------------------------------------------===//
1818
#include "CSDiagnostics.h"
1919
#include "TypeChecker.h"
20+
#include "TypeCheckAvailability.h"
2021
#include "TypeCheckType.h"
2122
#include "swift/AST/Initializer.h"
2223
#include "swift/AST/GenericEnvironment.h"
@@ -5057,7 +5058,8 @@ bool ConstraintSystem::isDeclUnavailable(const Decl *D,
50575058
}
50585059

50595060
// If not, let's check contextual unavailability.
5060-
auto result = TypeChecker::checkDeclarationAvailability(D, loc, DC);
5061+
ExportContext where = ExportContext::forFunctionBody(DC, loc);
5062+
auto result = TypeChecker::checkDeclarationAvailability(D, where);
50615063
return result.hasValue();
50625064
}
50635065

@@ -5242,8 +5244,9 @@ bool ConstraintSystem::isReadOnlyKeyPathComponent(
52425244
// If the setter is unavailable, then the keypath ought to be read-only
52435245
// in this context.
52445246
if (auto setter = storage->getOpaqueAccessor(AccessorKind::Set)) {
5247+
ExportContext where = ExportContext::forFunctionBody(DC, referenceLoc);
52455248
auto maybeUnavail =
5246-
TypeChecker::checkDeclarationAvailability(setter, referenceLoc, DC);
5249+
TypeChecker::checkDeclarationAvailability(setter, where);
52475250
if (maybeUnavail.hasValue()) {
52485251
return true;
52495252
}

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4600,7 +4600,7 @@ void swift::performSyntacticExprDiagnostics(const Expr *E,
46004600
if (!ctx.isSwiftVersionAtLeast(5))
46014601
diagnoseDeprecatedWritableKeyPath(E, DC);
46024602
if (!ctx.LangOpts.DisableAvailabilityChecking)
4603-
diagAvailability(E, const_cast<DeclContext*>(DC));
4603+
diagnoseExprAvailability(E, const_cast<DeclContext*>(DC));
46044604
if (ctx.LangOpts.EnableObjCInterop)
46054605
diagDeprecatedObjCSelectors(DC, E);
46064606
diagnoseConstantArgumentRequirement(E, DC);
@@ -4623,7 +4623,7 @@ void swift::performStmtDiagnostics(const Stmt *S, DeclContext *DC) {
46234623
checkImplicitPromotionsInCondition(elt, ctx);
46244624

46254625
if (!ctx.LangOpts.DisableAvailabilityChecking)
4626-
diagAvailability(S, const_cast<DeclContext*>(DC));
4626+
diagnoseStmtAvailability(S, const_cast<DeclContext*>(DC));
46274627
}
46284628

46294629
//===----------------------------------------------------------------------===//

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace swift;
2929

3030
bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
3131
const ValueDecl *D,
32-
ExportContext where) {
32+
const ExportContext &where) {
3333
auto fragileKind = where.getFragileFunctionKind();
3434
if (fragileKind.kind == FragileFunctionKind::None)
3535
return false;
@@ -112,7 +112,7 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
112112
bool
113113
TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
114114
const ValueDecl *D,
115-
ExportContext where) {
115+
const ExportContext &where) {
116116
// Accessors cannot have exportability that's different than the storage,
117117
// so skip them for now.
118118
if (isa<AccessorDecl>(D))
@@ -160,7 +160,7 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
160160
bool
161161
TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
162162
const RootProtocolConformance *rootConf,
163-
ExportContext where) {
163+
const ExportContext &where) {
164164
if (!where.mustOnlyReferenceExportedDecls())
165165
return false;
166166

lib/Sema/TypeCheckAccess.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
14481448
/// Local variant to swift::getDisallowedOriginKind for downgrade to warnings.
14491449
DisallowedOriginKind
14501450
swift::getDisallowedOriginKind(const Decl *decl,
1451-
ExportContext where,
1451+
const ExportContext &where,
14521452
DowngradeToWarning &downgradeToWarning) {
14531453
downgradeToWarning = DowngradeToWarning::No;
14541454
ModuleDecl *M = decl->getModuleContext();
@@ -1496,11 +1496,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
14961496
if (allowUnavailableProtocol)
14971497
flags |= DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol;
14981498

1499-
auto loc = context->getLoc();
1500-
if (auto *varDecl = dyn_cast<VarDecl>(context))
1501-
loc = varDecl->getNameLoc();
1502-
1503-
diagnoseTypeAvailability(typeRepr, type, loc,
1499+
diagnoseTypeAvailability(typeRepr, type, context->getLoc(),
15041500
Where.withReason(reason), flags);
15051501
}
15061502

@@ -1595,10 +1591,18 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
15951591
TP->getTypeRepr(), anyVar ? (Decl *)anyVar : (Decl *)PBD);
15961592

15971593
// Check the property wrapper types.
1598-
if (anyVar)
1599-
for (auto attr : anyVar->getAttachedPropertyWrappers())
1594+
if (anyVar) {
1595+
for (auto attr : anyVar->getAttachedPropertyWrappers()) {
16001596
checkType(attr->getType(), attr->getTypeRepr(), anyVar,
16011597
ExportabilityReason::PropertyWrapper);
1598+
}
1599+
1600+
if (auto attr = anyVar->getAttachedResultBuilder()) {
1601+
checkType(anyVar->getResultBuilderType(),
1602+
attr->getTypeRepr(), anyVar,
1603+
ExportabilityReason::ResultBuilder);
1604+
}
1605+
}
16021606
}
16031607

16041608
void visitPatternBindingDecl(PatternBindingDecl *PBD) {
@@ -1687,6 +1691,12 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
16871691
void visitFuncDecl(FuncDecl *FD) {
16881692
visitAbstractFunctionDecl(FD);
16891693
checkType(FD->getResultInterfaceType(), FD->getResultTypeRepr(), FD);
1694+
1695+
if (auto attr = FD->getAttachedResultBuilder()) {
1696+
checkType(FD->getResultBuilderType(),
1697+
attr->getTypeRepr(), FD,
1698+
ExportabilityReason::ResultBuilder);
1699+
}
16901700
}
16911701

16921702
void visitEnumElementDecl(EnumElementDecl *EED) {
@@ -1830,7 +1840,7 @@ static void checkExtensionGenericParamAccess(const ExtensionDecl *ED) {
18301840
}
18311841

18321842
DisallowedOriginKind swift::getDisallowedOriginKind(const Decl *decl,
1833-
ExportContext where) {
1843+
const ExportContext &where) {
18341844
auto downgradeToWarning = DowngradeToWarning::No;
18351845
return getDisallowedOriginKind(decl, where, downgradeToWarning);
18361846
}

lib/Sema/TypeCheckAccess.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ enum class DowngradeToWarning: bool {
5656
/// Returns the kind of origin, implementation-only import or SPI declaration,
5757
/// that restricts exporting \p decl from the given file and context.
5858
DisallowedOriginKind getDisallowedOriginKind(const Decl *decl,
59-
ExportContext where);
59+
const ExportContext &where);
6060

6161
DisallowedOriginKind getDisallowedOriginKind(const Decl *decl,
62-
ExportContext where,
62+
const ExportContext &where,
6363
DowngradeToWarning &downgradeToWarning);
6464

6565
} // end namespace swift

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,8 @@ SynthesizeMainFunctionRequest::evaluate(Evaluator &evaluator,
19901990
}
19911991

19921992
auto where = ExportContext::forDeclSignature(D);
1993-
diagnoseDeclAvailability(mainFunction, attr->getRange(), where, None);
1993+
diagnoseDeclAvailability(mainFunction, attr->getRange(), nullptr,
1994+
where, None);
19941995

19951996
auto *const func = FuncDecl::createImplicit(
19961997
context, StaticSpellingKind::KeywordStatic,

0 commit comments

Comments
 (0)