Skip to content
Draft
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
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ MIGRATABLE_UPCOMING_FEATURE(MemberImportVisibility, 444, 7)
MIGRATABLE_UPCOMING_FEATURE(InferIsolatedConformances, 470, 7)
MIGRATABLE_UPCOMING_FEATURE(NonisolatedNonsendingByDefault, 461, 7)
UPCOMING_FEATURE(ImmutableWeakCaptures, 481, 7)
UPCOMING_FEATURE(StrictAccessControl, 0, 7)

// Optional language features / modes

Expand Down
1 change: 1 addition & 0 deletions lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ static bool usesFeatureTildeSendable(Decl *decl) {
}

UNINTERESTING_FEATURE(AnyAppleOSAvailability)
UNINTERESTING_FEATURE(StrictAccessControl)

// ----------------------------------------------------------------------------
// MARK: - FeatureSet
Expand Down
10 changes: 7 additions & 3 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
}

// Swift 5.0 did not check the underlying types of local typealiases.
if (isa<TypeAliasDecl>(DC) && !Context.isLanguageModeAtLeast(6))
if (isa<TypeAliasDecl>(DC) &&
!Context.LangOpts.hasFeature(Feature::StrictAccessControl) &&
!Context.isLanguageModeAtLeast(6))
downgradeToWarning = DowngradeToWarning::Yes;

auto diagID = diag::resilience_decl_unavailable;
Expand Down Expand Up @@ -207,7 +209,8 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
}
D->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);

if (originKind == DisallowedOriginKind::MissingImport &&
if (!ctx.LangOpts.hasFeature(Feature::StrictAccessControl) &&
originKind == DisallowedOriginKind::MissingImport &&
!ctx.isLanguageModeAtLeast(6))
addMissingImport(loc, D, where);

Expand Down Expand Up @@ -460,7 +463,8 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
originKind == DisallowedOriginKind::MissingImport,
6);

if (originKind == DisallowedOriginKind::MissingImport &&
if (!ctx.LangOpts.hasFeature(Feature::StrictAccessControl) &&
originKind == DisallowedOriginKind::MissingImport &&
!ctx.isLanguageModeAtLeast(6))
addMissingImport(loc, ext, where);

Expand Down
26 changes: 15 additions & 11 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,12 @@ void AccessControlCheckerBase::checkGenericParamAccess(
if (minAccessScope.isPublic())
return;

// FIXME: Promote these to an error in the next -swift-version break.
if (isa<SubscriptDecl>(ownerDecl) || isa<TypeAliasDecl>(ownerDecl))
auto &Context = ownerDecl->getASTContext();

if (!Context.LangOpts.hasFeature(Feature::StrictAccessControl) &&
(isa<SubscriptDecl>(ownerDecl) || isa<TypeAliasDecl>(ownerDecl)))
downgradeToWarning = DowngradeToWarning::Yes;

auto &Context = ownerDecl->getASTContext();
if (checkUsableFromInline) {
if (!Context.isLanguageModeAtLeast(5))
downgradeToWarning = DowngradeToWarning::Yes;
Expand Down Expand Up @@ -2042,14 +2043,16 @@ swift::getDisallowedOriginKind(const Decl *decl,
downgradeToWarning = DowngradeToWarning::No;
ModuleDecl *M = decl->getModuleContext();
auto *SF = where.getDeclContext()->getParentSourceFile();
auto &Context = M->getASTContext();

RestrictedImportKind howImported = SF->getRestrictedImportKind(M);
if (howImported != RestrictedImportKind::None) {
// Temporarily downgrade implementation-only exportability in SPI to
// a warning.
if (where.isSPI() &&
if (!Context.LangOpts.hasFeature(Feature::StrictAccessControl) &&
where.isSPI() &&
where.getFragileFunctionKind().kind == FragileFunctionKind::None &&
!SF->getASTContext().LangOpts.EnableSPIOnlyImports)
!Context.LangOpts.EnableSPIOnlyImports)
downgradeToWarning = DowngradeToWarning::Yes;

if (where.isSPI() && howImported == RestrictedImportKind::SPIOnly)
Expand All @@ -2058,8 +2061,9 @@ swift::getDisallowedOriginKind(const Decl *decl,
// Before Swift 6, implicit imports were not reported unless an
// implementation-only import was also present. Downgrade to a warning
// just in this case.
if (howImported == RestrictedImportKind::MissingImport &&
!SF->getASTContext().isLanguageModeAtLeast(6) &&
if (!Context.LangOpts.hasFeature(Feature::StrictAccessControl) &&
howImported == RestrictedImportKind::MissingImport &&
!Context.isLanguageModeAtLeast(6) &&
!SF->hasImportsWithFlag(ImportFlags::ImplementationOnly)) {
downgradeToWarning = DowngradeToWarning::Yes;
}
Expand Down Expand Up @@ -2087,7 +2091,7 @@ swift::getDisallowedOriginKind(const Decl *decl,
if (!owningModule)
continue;
auto moduleWrapper =
decl->getASTContext().getClangModuleLoader()->getWrapperForModule(
Context.getClangModuleLoader()->getWrapperForModule(
owningModule);
auto visibleAccessPath =
find_if(sfImportedModules, [&moduleWrapper](auto importedModule) {
Expand Down Expand Up @@ -2150,7 +2154,7 @@ swift::getDisallowedOriginKind(const Decl *decl,
}

// C++ APIs do not support library evolution.
if (SF->getASTContext().LangOpts.EnableCXXInterop && where.getDeclContext() &&
if (Context.LangOpts.EnableCXXInterop && where.getDeclContext() &&
where.getDeclContext()->getAsDecl() &&
where.getDeclContext()->getAsDecl()->getModuleContext()->isResilient() &&
!where.getDeclContext()
Expand All @@ -2159,13 +2163,13 @@ swift::getDisallowedOriginKind(const Decl *decl,
->getUnderlyingModuleIfOverlay() &&
decl->hasClangNode() && !decl->getModuleContext()->isSwiftShimsModule() &&
isFragileClangNode(decl->getClangNode()) &&
!SF->getASTContext().LangOpts.hasFeature(
!Context.LangOpts.hasFeature(
Feature::AssumeResilientCxxTypes))
return DisallowedOriginKind::FragileCxxAPI;

// Implementation-only memory layouts for non-library-evolution mode.
if (isa<NominalTypeDecl>(decl) &&
decl->getASTContext().LangOpts.hasFeature(
Context.LangOpts.hasFeature(
Feature::CheckImplementationOnly) &&
decl->getAttrs().hasAttribute<ImplementationOnlyAttr>())
return DisallowedOriginKind::ImplementationOnlyMemoryLayout;
Expand Down
25 changes: 15 additions & 10 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ static bool diagnosePotentialUnavailability(
// Don't downgrade
} else if (behaviorLimit >= DiagnosticBehavior::Warning) {
err.limitBehavior(behaviorLimit);
} else {
} else if (!ctx.LangOpts.hasFeature(Feature::StrictAccessControl)) {
err.warnUntilLanguageMode(6);
}

Expand Down Expand Up @@ -2161,7 +2161,8 @@ bool diagnoseExplicitUnavailability(
// obsolete decls still map to valid ObjC runtime names, so behave correctly
// at runtime, even though their use would produce an error outside of a
// #keyPath expression.
auto limit = Flags.contains(DeclAvailabilityFlag::ForObjCKeyPath)
auto limit = (!ctx.LangOpts.hasFeature(Feature::StrictAccessControl) &&
Flags.contains(DeclAvailabilityFlag::ForObjCKeyPath))
? DiagnosticBehavior::Warning
: DiagnosticBehavior::Unspecified;

Expand Down Expand Up @@ -2950,10 +2951,12 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
attr->getMessage());
if (D->preconcurrency()) {
diag.limitBehavior(DiagnosticBehavior::Warning);
} else if (shouldWarnUntilFutureVersion()) {
diag.warnUntilFutureLanguageMode();
} else {
diag.warnUntilLanguageMode(6);
} else if (!ctx.LangOpts.hasFeature(Feature::StrictAccessControl)) {
if (shouldWarnUntilFutureVersion()) {
diag.warnUntilFutureLanguageMode();
} else {
diag.warnUntilLanguageMode(6);
}
}

if (!attr->getRename().empty()) {
Expand All @@ -2974,10 +2977,12 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
SourceLoc diagLoc = call ? call->getLoc() : R.Start;
auto diag = ctx.Diags.diagnose(diagLoc, diag::async_unavailable_decl, D,
attr->Message);
if (shouldWarnUntilFutureVersion()) {
diag.warnUntilFutureLanguageMode();
} else {
diag.warnUntilLanguageMode(6);
if (!ctx.LangOpts.hasFeature(Feature::StrictAccessControl)) {
if (shouldWarnUntilFutureVersion()) {
diag.warnUntilFutureLanguageMode();
} else {
diag.warnUntilLanguageMode(6);
}
}
}
D->diagnose(diag::decl_declared_here, D);
Expand Down