Skip to content

Commit 1bdf006

Browse files
authored
Merge pull request #37190 from kavon/eff-prop-swiftinterface-ifguard-fix
fix feature guards in swiftinterface for eff. props
2 parents 513774e + c5ec5bf commit 1bdf006

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", true)
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
@@ -2475,6 +2475,12 @@ static bool usesFeatureStaticAssert(Decl *decl) {
24752475
return false;
24762476
}
24772477

2478+
static bool usesFeatureEffectfulProp(Decl *decl) {
2479+
if (auto asd = dyn_cast<AbstractStorageDecl>(decl))
2480+
return asd->getEffectfulGetAccessor() != nullptr;
2481+
return false;
2482+
}
2483+
24782484
static bool usesFeatureAsyncAwait(Decl *decl) {
24792485
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
24802486
if (func->hasAsync())
@@ -2834,6 +2840,12 @@ static std::vector<Feature> getUniqueFeaturesUsed(Decl *decl) {
28342840

28352841
bool swift::printCompatibilityFeatureChecksPre(
28362842
ASTPrinter &printer, Decl *decl) {
2843+
2844+
// A single accessor does not get a feature check,
2845+
// it should go around the whole decl.
2846+
if (isa<AccessorDecl>(decl))
2847+
return false;
2848+
28372849
auto features = getUniqueFeaturesUsed(decl);
28382850
if (features.empty())
28392851
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)