Skip to content

Put the AvailabilityContext into the ExportContext #34473

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 7 commits into from
Oct 29, 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
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,7 @@ NOTE(construct_raw_representable_from_unwrapped_value,none,

ERROR(decl_from_hidden_module,none,
"cannot use %0 %1 %select{here|as property wrapper here|"
"as result builder here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances}2; "
"%select{%3 has been imported as implementation-only|"
Expand All @@ -2742,12 +2743,14 @@ ERROR(decl_from_hidden_module,none,
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
WARNING(decl_from_hidden_module_warn,none,
"cannot use %0 %1 %select{in SPI|as property wrapper in SPI|"
"as result builder in SPI|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances}2; "
"%select{%3 has been imported as implementation-only}4",
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
ERROR(conformance_from_implementation_only_module,none,
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
"as result builder here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances}2; "
"%select{%3 has been imported as implementation-only|"
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,9 @@ class BuilderClosureRewriter
if (!nominal)
return false;

ExportContext where = ExportContext::forFunctionBody(dc, loc);
if (auto reason = TypeChecker::checkDeclarationAvailability(
nominal, loc, dc)) {
nominal, where)) {
ctx.Diags.diagnose(
loc, diag::result_builder_missing_limited_availability,
builderTransform.builderType);
Expand Down
7 changes: 5 additions & 2 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//===----------------------------------------------------------------------===//
#include "CSDiagnostics.h"
#include "TypeChecker.h"
#include "TypeCheckAvailability.h"
#include "TypeCheckType.h"
#include "swift/AST/Initializer.h"
#include "swift/AST/GenericEnvironment.h"
Expand Down Expand Up @@ -5057,7 +5058,8 @@ bool ConstraintSystem::isDeclUnavailable(const Decl *D,
}

// If not, let's check contextual unavailability.
auto result = TypeChecker::checkDeclarationAvailability(D, loc, DC);
ExportContext where = ExportContext::forFunctionBody(DC, loc);
auto result = TypeChecker::checkDeclarationAvailability(D, where);
return result.hasValue();
}

Expand Down Expand Up @@ -5242,8 +5244,9 @@ bool ConstraintSystem::isReadOnlyKeyPathComponent(
// If the setter is unavailable, then the keypath ought to be read-only
// in this context.
if (auto setter = storage->getOpaqueAccessor(AccessorKind::Set)) {
ExportContext where = ExportContext::forFunctionBody(DC, referenceLoc);
auto maybeUnavail =
TypeChecker::checkDeclarationAvailability(setter, referenceLoc, DC);
TypeChecker::checkDeclarationAvailability(setter, where);
if (maybeUnavail.hasValue()) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4600,7 +4600,7 @@ void swift::performSyntacticExprDiagnostics(const Expr *E,
if (!ctx.isSwiftVersionAtLeast(5))
diagnoseDeprecatedWritableKeyPath(E, DC);
if (!ctx.LangOpts.DisableAvailabilityChecking)
diagAvailability(E, const_cast<DeclContext*>(DC));
diagnoseExprAvailability(E, const_cast<DeclContext*>(DC));
if (ctx.LangOpts.EnableObjCInterop)
diagDeprecatedObjCSelectors(DC, E);
diagnoseConstantArgumentRequirement(E, DC);
Expand All @@ -4623,7 +4623,7 @@ void swift::performStmtDiagnostics(const Stmt *S, DeclContext *DC) {
checkImplicitPromotionsInCondition(elt, ctx);

if (!ctx.LangOpts.DisableAvailabilityChecking)
diagAvailability(S, const_cast<DeclContext*>(DC));
diagnoseStmtAvailability(S, const_cast<DeclContext*>(DC));
}

//===----------------------------------------------------------------------===//
Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace swift;

bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
const ValueDecl *D,
ExportContext where) {
const ExportContext &where) {
auto fragileKind = where.getFragileFunctionKind();
if (fragileKind.kind == FragileFunctionKind::None)
return false;
Expand Down Expand Up @@ -112,7 +112,7 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
bool
TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
const ValueDecl *D,
ExportContext where) {
const ExportContext &where) {
// Accessors cannot have exportability that's different than the storage,
// so skip them for now.
if (isa<AccessorDecl>(D))
Expand Down Expand Up @@ -160,7 +160,7 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
bool
TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
const RootProtocolConformance *rootConf,
ExportContext where) {
const ExportContext &where) {
if (!where.mustOnlyReferenceExportedDecls())
return false;

Expand Down
28 changes: 19 additions & 9 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
/// Local variant to swift::getDisallowedOriginKind for downgrade to warnings.
DisallowedOriginKind
swift::getDisallowedOriginKind(const Decl *decl,
ExportContext where,
const ExportContext &where,
DowngradeToWarning &downgradeToWarning) {
downgradeToWarning = DowngradeToWarning::No;
ModuleDecl *M = decl->getModuleContext();
Expand Down Expand Up @@ -1496,11 +1496,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
if (allowUnavailableProtocol)
flags |= DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol;

auto loc = context->getLoc();
if (auto *varDecl = dyn_cast<VarDecl>(context))
loc = varDecl->getNameLoc();

diagnoseTypeAvailability(typeRepr, type, loc,
diagnoseTypeAvailability(typeRepr, type, context->getLoc(),
Where.withReason(reason), flags);
}

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

// Check the property wrapper types.
if (anyVar)
for (auto attr : anyVar->getAttachedPropertyWrappers())
if (anyVar) {
for (auto attr : anyVar->getAttachedPropertyWrappers()) {
checkType(attr->getType(), attr->getTypeRepr(), anyVar,
ExportabilityReason::PropertyWrapper);
}

if (auto attr = anyVar->getAttachedResultBuilder()) {
checkType(anyVar->getResultBuilderType(),
attr->getTypeRepr(), anyVar,
ExportabilityReason::ResultBuilder);
}
}
}

void visitPatternBindingDecl(PatternBindingDecl *PBD) {
Expand Down Expand Up @@ -1687,6 +1691,12 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
void visitFuncDecl(FuncDecl *FD) {
visitAbstractFunctionDecl(FD);
checkType(FD->getResultInterfaceType(), FD->getResultTypeRepr(), FD);

if (auto attr = FD->getAttachedResultBuilder()) {
checkType(FD->getResultBuilderType(),
attr->getTypeRepr(), FD,
ExportabilityReason::ResultBuilder);
}
}

void visitEnumElementDecl(EnumElementDecl *EED) {
Expand Down Expand Up @@ -1830,7 +1840,7 @@ static void checkExtensionGenericParamAccess(const ExtensionDecl *ED) {
}

DisallowedOriginKind swift::getDisallowedOriginKind(const Decl *decl,
ExportContext where) {
const ExportContext &where) {
auto downgradeToWarning = DowngradeToWarning::No;
return getDisallowedOriginKind(decl, where, downgradeToWarning);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ enum class DowngradeToWarning: bool {
/// Returns the kind of origin, implementation-only import or SPI declaration,
/// that restricts exporting \p decl from the given file and context.
DisallowedOriginKind getDisallowedOriginKind(const Decl *decl,
ExportContext where);
const ExportContext &where);

DisallowedOriginKind getDisallowedOriginKind(const Decl *decl,
ExportContext where,
const ExportContext &where,
DowngradeToWarning &downgradeToWarning);

} // end namespace swift
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,8 @@ SynthesizeMainFunctionRequest::evaluate(Evaluator &evaluator,
}

auto where = ExportContext::forDeclSignature(D);
diagnoseDeclAvailability(mainFunction, attr->getRange(), where, None);
diagnoseDeclAvailability(mainFunction, attr->getRange(), nullptr,
where, None);

auto *const func = FuncDecl::createImplicit(
context, StaticSpellingKind::KeywordStatic,
Expand Down
Loading