Skip to content

Commit 06db612

Browse files
committed
Sema: Intro the CheckImplementationOnlyStrict feature
1 parent e2b0d53 commit 06db612

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

include/swift/Basic/Features.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ EXPERIMENTAL_FEATURE(AnyAppleOSAvailability, true)
557557
/// Check @_implementationOnly imports in non-library-evolution mode.
558558
EXPERIMENTAL_FEATURE(CheckImplementationOnly, true)
559559

560+
/// Extends CheckImplementationOnly with an extra check at serialization to
561+
/// report references to implementation-only imported modules.
562+
EXPERIMENTAL_FEATURE(CheckImplementationOnlyStrict, false)
563+
560564
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
561565
#undef EXPERIMENTAL_FEATURE
562566
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ UNINTERESTING_FEATURE(GroupActorErrors)
145145
UNINTERESTING_FEATURE(SameElementRequirements)
146146
UNINTERESTING_FEATURE(SendingArgsAndResults)
147147
UNINTERESTING_FEATURE(CheckImplementationOnly)
148+
UNINTERESTING_FEATURE(CheckImplementationOnlyStrict)
148149

149150
static bool findUnderscoredLifetimeAttr(Decl *decl) {
150151
auto hasUnderscoredLifetimeAttr = [](Decl *decl) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
18971897
Opts.enableFeature(Feature::NoExplicitNonIsolated);
18981898
}
18991899

1900+
if (Opts.hasFeature(Feature::CheckImplementationOnlyStrict) &&
1901+
!::getenv("SWIFT_DISABLE_IMPLICIT_CHECK_IMPLEMENTATION_ONLY"))
1902+
Opts.enableFeature(Feature::CheckImplementationOnly);
1903+
19001904
#if !defined(NDEBUG) && SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
19011905
/// Enable round trip parsing via the new swift parser unless it is disabled
19021906
/// explicitly. The new Swift parser can have mismatches with C++ parser -

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5051,7 +5051,8 @@ AttributeChecker::visitImplementationOnlyAttr(ImplementationOnlyAttr *attr) {
50515051

50525052
// @_implementationOnly on types only applies to non-public types.
50535053
if (isa<NominalTypeDecl>(D)) {
5054-
if (!Ctx.LangOpts.hasFeature(Feature::CheckImplementationOnly)) {
5054+
if (!Ctx.LangOpts.hasFeature(Feature::CheckImplementationOnly) &&
5055+
!Ctx.LangOpts.hasFeature(Feature::CheckImplementationOnlyStrict)) {
50555056
diagnoseAndRemoveAttr(attr, diag::implementation_only_on_types_feature);
50565057
return;
50575058
}

test/Sema/hidden-memory-layout.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@
4848
// RUN: -verify-additional-prefix embedded-opt-in- \
4949
// RUN: -enable-experimental-feature CheckImplementationOnly
5050

51+
/// Same diags with CheckImplementationOnlyStrict
52+
// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unrelated %s -I %t \
53+
// RUN: -swift-version 5 -target arm64-apple-none-macho \
54+
// RUN: -enable-experimental-feature Embedded \
55+
// RUN: -verify-additional-prefix opt-in- -DUseImplementationOnly \
56+
// RUN: -verify-additional-prefix embedded-opt-in- \
57+
// RUN: -enable-experimental-feature CheckImplementationOnlyStrict
58+
5159
// REQUIRES: swift_feature_Embedded
5260
// REQUIRES: swift_feature_CheckImplementationOnly
61+
// REQUIRES: swift_feature_CheckImplementationOnlyStrict
5362
// REQUIRES: embedded_stdlib_cross_compiling
5463

5564
@_implementationOnly import directs

0 commit comments

Comments
 (0)