Skip to content

[5.5] fix missing effects specifiers on some properties in swiftinterface #37175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

LANGUAGE_FEATURE(StaticAssert, 0, "#assert", langOpts.EnableExperimentalStaticAssert)
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties", langOpts.EnableExperimentalConcurrency)
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
LANGUAGE_FEATURE(Actors, 0, "actors", langOpts.EnableExperimentalConcurrency)
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)
Expand Down
16 changes: 16 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2481,6 +2481,12 @@ static bool usesFeatureStaticAssert(Decl *decl) {
return false;
}

static bool usesFeatureEffectfulProp(Decl *decl) {
if (auto asd = dyn_cast<AbstractStorageDecl>(decl))
return asd->getEffectfulGetAccessor() != nullptr;
return false;
}

static bool usesFeatureAsyncAwait(Decl *decl) {
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
if (func->hasAsync())
Expand Down Expand Up @@ -2857,6 +2863,12 @@ static std::vector<Feature> getUniqueFeaturesUsed(Decl *decl) {

bool swift::printCompatibilityFeatureChecksPre(
ASTPrinter &printer, Decl *decl) {

// A single accessor does not get a feature check,
// it should go around the whole decl.
if (isa<AccessorDecl>(decl))
return false;

auto features = getUniqueFeaturesUsed(decl);
if (features.empty())
return false;
Expand Down Expand Up @@ -3496,6 +3508,10 @@ void PrintAST::visitAccessorDecl(AccessorDecl *decl) {
});
}

// handle effects specifiers before the body
if (decl->hasAsync()) Printer << " async";
if (decl->hasThrows()) Printer << " throws";

printBodyIfNecessary(decl);
}

Expand Down
61 changes: 61 additions & 0 deletions test/ModuleInterface/effectful_properties.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// RUN: %target-swift-frontend -enable-experimental-concurrency -typecheck -swift-version 5 -enable-library-evolution -emit-module-interface-path %t.swiftinterface %s -module-name EffProps
// RUN: %FileCheck %s < %t.swiftinterface

public struct MyStruct {}

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

public extension MyStruct {
struct InnerStruct {
public var status: Bool { get async throws { false } }
}
}

// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
// CHECK: public var hello: Swift.Int {
// CHECK: get async
// CHECK: }
// CHECK: #endif


// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
// CHECK: public subscript(x: Swift.Int) -> Swift.Void {
// CHECK: get async throws
// CHECK: }
// CHECK: #endif

public class C {
public var hello: Int { get async { 0 } }

public subscript(_ x: Int) -> Void {
get async throws { }
}
}

// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
// CHECK: public var world: Swift.Int {
// CHECK: get throws
// CHECK: }
// CHECK: #endif

public enum E {
public var world: Int { get throws { 0 } }
}

// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
// CHECK: var books: Swift.Int { get async }
// CHECK: #endif


// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
// CHECK: subscript(x: Swift.Int) -> Swift.Int { get throws }
// CHECK: #endif

public protocol P {
var books: Int { get async }
subscript(_ x: Int) -> Int { get throws }
}