Skip to content

Commit db34e76

Browse files
committed
fix feature guards in swiftinterface for eff. props
1 parent 1c8cf3f commit db34e76

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
LANGUAGE_FEATURE(StaticAssert, 0, "#assert", langOpts.EnableExperimentalStaticAssert)
3838
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
39+
LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties", langOpts.EnableExperimentalConcurrency)
3940
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
4041
LANGUAGE_FEATURE(Actors, 0, "actors", langOpts.EnableExperimentalConcurrency)
4142
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)

lib/AST/ASTPrinter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,6 +2481,12 @@ static bool usesFeatureStaticAssert(Decl *decl) {
24812481
return false;
24822482
}
24832483

2484+
static bool usesFeatureEffectfulProp(Decl *decl) {
2485+
if (auto asd = dyn_cast<AbstractStorageDecl>(decl))
2486+
return asd->getEffectfulGetAccessor() != nullptr;
2487+
return false;
2488+
}
2489+
24842490
static bool usesFeatureAsyncAwait(Decl *decl) {
24852491
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
24862492
if (func->hasAsync())
@@ -2857,6 +2863,12 @@ static std::vector<Feature> getUniqueFeaturesUsed(Decl *decl) {
28572863

28582864
bool swift::printCompatibilityFeatureChecksPre(
28592865
ASTPrinter &printer, Decl *decl) {
2866+
2867+
// A single accessor does not get a feature check,
2868+
// it should go around the whole decl.
2869+
if (isa<AccessorDecl>(decl))
2870+
return false;
2871+
28602872
auto features = getUniqueFeaturesUsed(decl);
28612873
if (features.empty())
28622874
return false;

test/ModuleInterface/effectful_properties.swift

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@
33

44
public struct MyStruct {}
55

6-
// CHECK-LABEL: public var status
7-
// CHECK: get async throws
6+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
7+
// CHECK: public var status: Swift.Bool {
8+
// CHECK: get async throws
9+
// CHECK: }
10+
// CHECK: #endif
811

912
public extension MyStruct {
1013
struct InnerStruct {
1114
public var status: Bool { get async throws { false } }
1215
}
1316
}
1417

15-
// CHECK-LABEL: public var hello
16-
// CHECK: get async
18+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
19+
// CHECK: public var hello: Swift.Int {
20+
// CHECK: get async
21+
// CHECK: }
22+
// CHECK: #endif
1723

18-
// CHECK-LABEL: public subscript
19-
// CHECK: get async throws
24+
25+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
26+
// CHECK: public subscript(x: Swift.Int) -> Swift.Void {
27+
// CHECK: get async throws
28+
// CHECK: }
29+
// CHECK: #endif
2030

2131
public class C {
2232
public var hello: Int { get async { 0 } }
@@ -26,9 +36,26 @@ public class C {
2636
}
2737
}
2838

29-
// CHECK-LABEL: public var world
30-
// CHECK: get throws
39+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
40+
// CHECK: public var world: Swift.Int {
41+
// CHECK: get throws
42+
// CHECK: }
43+
// CHECK: #endif
3144

3245
public enum E {
3346
public var world: Int { get throws { 0 } }
47+
}
48+
49+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
50+
// CHECK: var books: Swift.Int { get async }
51+
// CHECK: #endif
52+
53+
54+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
55+
// CHECK: subscript(x: Swift.Int) -> Swift.Int { get throws }
56+
// CHECK: #endif
57+
58+
public protocol P {
59+
var books: Int { get async }
60+
subscript(_ x: Int) -> Int { get throws }
3461
}

0 commit comments

Comments
 (0)