Skip to content

Commit 36e1ee1

Browse files
committed
Guard feature behind experimental flag.
1 parent b776f3b commit 36e1ee1

File tree

8 files changed

+26
-6
lines changed

8 files changed

+26
-6
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ EXPERIMENTAL_FEATURE(TupleConformances, false)
233233
EXPERIMENTAL_FEATURE(FullTypedThrows, false)
234234
EXPERIMENTAL_FEATURE(SameElementRequirements, false)
235235
EXPERIMENTAL_FEATURE(GlobalActorInferenceCutoff, false)
236+
EXPERIMENTAL_FEATURE(KeyPathWithStaticMember, false)
236237

237238
// Whether to enable @_used and @_section attributes
238239
EXPERIMENTAL_FEATURE(SymbolLinkageMarkers, true)

include/swift/Sema/CSFix.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,9 @@ class TreatKeyPathSubscriptIndexAsHashable final : public ConstraintFix {
20262026

20272027
class AllowInvalidRefInKeyPath final : public ConstraintFix {
20282028
enum RefKind {
2029+
// Allow a reference to a static member as a key path component if it is
2030+
// declared in a module with built with Swift 6.0 compiler version or older.
2031+
StaticMember,
20292032
// Allow a reference to a declaration with mutating getter as
20302033
// a key path component.
20312034
MutatingGetter,
@@ -2050,6 +2053,8 @@ class AllowInvalidRefInKeyPath final : public ConstraintFix {
20502053
public:
20512054
std::string getName() const override {
20522055
switch (Kind) {
2056+
case RefKind::StaticMember:
2057+
return "allow reference to a static member as a key path component";
20532058
case RefKind::MutatingGetter:
20542059
return "allow reference to a member with mutating getter as a key "
20552060
"path component";

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ UNINTERESTING_FEATURE(GroupActorErrors)
206206
UNINTERESTING_FEATURE(SameElementRequirements)
207207
UNINTERESTING_FEATURE(UnspecifiedMeansMainActorIsolated)
208208
UNINTERESTING_FEATURE(GlobalActorInferenceCutoff)
209+
UNINTERESTING_FEATURE(KeyPathWithStaticMember)
209210

210211
static bool usesFeatureSendingArgsAndResults(Decl *decl) {
211212
auto isFunctionTypeWithSending = [](Type type) {

lib/Sema/CSFix.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,9 @@ TreatKeyPathSubscriptIndexAsHashable::create(ConstraintSystem &cs, Type type,
12301230
bool AllowInvalidRefInKeyPath::diagnose(const Solution &solution,
12311231
bool asNote) const {
12321232
switch (Kind) {
1233+
case RefKind::StaticMember: {
1234+
}
1235+
12331236
case RefKind::EnumCase: {
12341237
InvalidEnumCaseRefInKeyPath failure(solution, Member, getLocator());
12351238
return failure.diagnose(asNote);
@@ -1277,6 +1280,13 @@ AllowInvalidRefInKeyPath *
12771280
AllowInvalidRefInKeyPath::forRef(ConstraintSystem &cs, Type baseType,
12781281
ValueDecl *member,
12791282
ConstraintLocator *locator) {
1283+
1284+
if (!cs.getASTContext().LangOpts.hasFeature(
1285+
Feature::KeyPathWithStaticMember) &&
1286+
member->isStatic())
1287+
return AllowInvalidRefInKeyPath::create(cs, baseType, RefKind::StaticMember,
1288+
member, locator);
1289+
12801290
// Referencing (instance or static) methods in key path is
12811291
// not currently allowed.
12821292
if (isa<FuncDecl>(member))

test/Interpreter/keypath.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// RUN: %target-run-simple-swift | %FileCheck %s
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-feature -Xfrontend KeyPathWithStaticMember) | %FileCheck %s
22

3+
// REQUIRES: asserts
34
// REQUIRES: executable_test
45

56
// UNSUPPORTED: use_os_stdlib

test/ModuleInterface/static_keypaths.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// RUN: split-file %s %t/src
33

44
/// Build LibA
5-
// RUN: %host-build-swift %t/src/LibA.swift -swift-version 5 -emit-module -emit-library -enable-library-evolution -module-name LibA -o %t/%target-library-name(LibA) -emit-module-interface-path %t/LibA.swiftinterface
5+
// RUN: %host-build-swift %t/src/LibA.swift -swift-version 5 -enable-experimental-feature StaticKeyPath -emit-module -emit-library -enable-library-evolution -module-name LibA -o %t/%target-library-name(LibA) -emit-module-interface-path %t/LibA.swiftinterface
66

77
// Build LibB
8-
// RUN: %target-build-swift %t/src/LibB.swift -I %t -L %t -l LibA -swift-version 5 -emit-module -emit-library -module-name LibB -o %t/%target-library-name(LibB)
8+
// RUN: %target-build-swift %t/src/LibB.swift -I %t -L %t -l LibA -swift-version 5 -enable-experimental-feature StaticKeyPath -emit-module -emit-library -module-name LibB -o %t/%target-library-name(LibB)
99

1010
// Build LibC
11-
// RUN: %target-build-swift %t/src/LibC.swift -I %t -L %t -l LibA -swift-version 5 -emit-module -emit-library -module-name LibC -o %t/%target-library-name(LibC)
11+
// RUN: %target-build-swift %t/src/LibC.swift -I %t -L %t -l LibA -swift-version 5 -enable-experimental-feature StaticKeyPath -emit-module -emit-library -module-name LibC -o %t/%target-library-name(LibC)
1212

1313
// Build & run main.swift
1414
// RUN: %target-build-swift -I %t -L %t -l LibA -l LibB -l LibC %t/src/main.swift -o %t/a.out

test/SILGen/keypaths.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %target-swift-emit-silgen -disable-availability-checking -parse-stdlib -module-name keypaths %s | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen -enable-experimental-feature KeyPathWithStaticMember -disable-availability-checking -parse-stdlib -module-name keypaths %s | %FileCheck %s
2+
3+
// REQUIRES: asserts
24

35
import Swift
46

test/expr/unary/keypath/keypath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck -parse-as-library %s -verify
1+
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature StaticKeyPath -parse-as-library %s -verify
22

33
struct Sub: Hashable {
44
static func ==(_: Sub, _: Sub) -> Bool { return true }

0 commit comments

Comments
 (0)