Skip to content

Commit ec097d6

Browse files
authored
Merge pull request #37175 from kavon/cherry-pick-5.5/eff-prop-extension-interface-bug
[5.5] fix missing effects specifiers on some properties in swiftinterface
2 parents b32f878 + db34e76 commit ec097d6

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
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: 16 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;
@@ -3496,6 +3508,10 @@ void PrintAST::visitAccessorDecl(AccessorDecl *decl) {
34963508
});
34973509
}
34983510

3511+
// handle effects specifiers before the body
3512+
if (decl->hasAsync()) Printer << " async";
3513+
if (decl->hasThrows()) Printer << " throws";
3514+
34993515
printBodyIfNecessary(decl);
35003516
}
35013517

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %target-swift-frontend -enable-experimental-concurrency -typecheck -swift-version 5 -enable-library-evolution -emit-module-interface-path %t.swiftinterface %s -module-name EffProps
2+
// RUN: %FileCheck %s < %t.swiftinterface
3+
4+
public struct MyStruct {}
5+
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
11+
12+
public extension MyStruct {
13+
struct InnerStruct {
14+
public var status: Bool { get async throws { false } }
15+
}
16+
}
17+
18+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
19+
// CHECK: public var hello: Swift.Int {
20+
// CHECK: get async
21+
// CHECK: }
22+
// CHECK: #endif
23+
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
30+
31+
public class C {
32+
public var hello: Int { get async { 0 } }
33+
34+
public subscript(_ x: Int) -> Void {
35+
get async throws { }
36+
}
37+
}
38+
39+
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
40+
// CHECK: public var world: Swift.Int {
41+
// CHECK: get throws
42+
// CHECK: }
43+
// CHECK: #endif
44+
45+
public enum E {
46+
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 }
61+
}

0 commit comments

Comments
 (0)