Skip to content

[SourceKit/DocInfo] Add is_async for properties with async getters #38401

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
merged 1 commit into from
Jul 16, 2021
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
10 changes: 10 additions & 0 deletions test/SourceKit/DocSupport/Inputs/async/async.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import Foundation;

@interface AsyncImports : NSObject

-(void)methodWithCompletion:(void (^)(void))completionHandler;

-(void)propWithCompletion:(void (^)(BOOL))completionHandler
__attribute__((swift_async_name("getter:asyncProp()")));

@end
3 changes: 3 additions & 0 deletions test/SourceKit/DocSupport/Inputs/async/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "asyncmod" {
header "async.h"
}
58 changes: 45 additions & 13 deletions test/SourceKit/DocSupport/doc_async.swift
Original file line number Diff line number Diff line change
@@ -1,56 +1,88 @@
// RUN: %empty-directory(%t.mod)
// RUN: %swift -enable-experimental-concurrency -emit-module -o %t.mod/async.swiftmodule %s -parse-as-library -emit-module-doc-path %t.mod/async.swiftdoc
// RUN: %sourcekitd-test -req=doc-info -module async -- -I %t.mod | %FileCheck %s

// REQUIRES: concurrency
// REQUIRES: objc_interop

// RUN: %sourcekitd-test -req=doc-info %s -- -module-name asyncmod -target %target-triple | %FileCheck %s

// RUN: %sourcekitd-test -req=doc-info -module asyncmod -- -target %target-triple %clang-importer-sdk-nosource -I %S/Inputs/async/ | %FileCheck %s --check-prefix=CHECK-OBJC
// CHECK-OBJC: key.name: "method()",
// CHECK-OBJC: key.usr: "c:objc(cs)AsyncImports(im)methodWithCompletion:"
// CHECK-OBJC-NOT: },
// CHECK-OBJC: key.is_async: 1
// CHECK-OBJC: },

// CHECK-OBJC: key.name: "asyncProp",
// CHECK-OBJC: key.usr: "c:objc(cs)AsyncImports(im)propWithCompletion:"
// CHECK-OBJC: key.fully_annotated_decl:
// CHECK-OBJC-NEXT: key.is_async: 1
// CHECK-OBJC: }

public protocol AsyncProto {
// CHECK: key.usr: "s:8asyncmod10AsyncProtoP05protoB4PropSivp"
// CHECK-NOT: },
// CHECK: key.is_async: 1
// CHECK: },
var protoAsyncProp: Int { get async }
// CHECK: key.usr: "s:8asyncmod10AsyncProtoP08protoNonB4PropSivp"
// CHECK-NOT: key.is_async: 1
// CHECK: },
var protoNonAsyncProp: Int { get }

func protoAsyncFunc() async
// CHECK: key.usr: "s:5async10AsyncProtoP05protoB4FuncyyYaF"
// CHECK: key.usr: "s:8asyncmod10AsyncProtoP05protoB4FuncyyYaF"
// CHECK-NOT: }
// CHECK: key.is_async: 1
// CHECK: }
func protoNonAsyncFunc()
// CHECK: key.usr: "s:5async10AsyncProtoP08protoNonB4FuncyyF"
// CHECK: key.usr: "s:8asyncmod10AsyncProtoP08protoNonB4FuncyyF"
// CHECK-NOT: key.is_async: 1
// CHECK: }
}

public struct AsyncStruct: AsyncProto {
// CHECK: key.usr: "s:8asyncmod11AsyncStructV05protoB4PropSivp"
// CHECK-NOT: },
// CHECK: key.is_async: 1
// CHECK: },
public var protoAsyncProp: Int { get async { return 1 } }
// CHECK: key.usr: "s:8asyncmod11AsyncStructV08protoNonB4PropSivp"
// CHECK-NOT: key.is_async: 1
// CHECK: },
public var protoNonAsyncProp: Int

public func structAsyncFunc() async { }
// CHECK: key.usr: "s:5async11AsyncStructV06structB4FuncyyYaF"
// CHECK: key.usr: "s:8asyncmod11AsyncStructV06structB4FuncyyYaF"
// CHECK-NOT: }
// CHECK: key.is_async: 1
// CHECK: }
public func structNonAsyncFunc() { }
// CHECK: key.usr: "s:5async11AsyncStructV09structNonB4FuncyyF"
// CHECK: key.usr: "s:8asyncmod11AsyncStructV09structNonB4FuncyyF"
// CHECK-NOT: key.is_async: 1
// CHECK: }

public func protoAsyncFunc() async { }
// CHECK: key.usr: "s:5async11AsyncStructV05protoB4FuncyyYaF"
// CHECK: key.usr: "s:8asyncmod11AsyncStructV05protoB4FuncyyYaF"
// CHECK-NOT: }
// CHECK: key.conforms
// CHECK: {
// CHECK: key.usr: "s:5async10AsyncProtoP05protoB4FuncyyYaF"
// CHECK: key.usr: "s:8asyncmod10AsyncProtoP05protoB4FuncyyYaF"
// CHECK-NOT: }
// CHECK: key.is_async: 1
// CHECK: }
// CHECK: key.is_async: 1
// CHECK: }
public func protoNonAsyncFunc() { }
// CHECK: key.usr: "s:5async11AsyncStructV08protoNonB4FuncyyF"
// CHECK: key.usr: "s:8asyncmod11AsyncStructV08protoNonB4FuncyyF"
// CHECK-NOT: key.is_async: 1
// CHECK: }
}

public func topLevelAsyncFunc() async { }
// CHECK: key.usr: "s:5async17topLevelAsyncFuncyyYaF"
// CHECK: key.usr: "s:8asyncmod17topLevelAsyncFuncyyYaF"
// CHECK-NOT: }
// CHECK: key.is_async: 1
// CHECK: }
public func topLevelNonAsyncFunc() { }
// CHECK: key.usr: "s:5async20topLevelNonAsyncFuncyyF"
// CHECK: key.usr: "s:8asyncmod20topLevelNonAsyncFuncyyF"
// CHECK-NOT: key.is_async: 1
// CHECK: }

3 changes: 3 additions & 0 deletions tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ static bool initDocEntityInfo(const Decl *D,
Info.IsOptional = D->getAttrs().hasAttribute<OptionalAttr>();
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
Info.IsAsync = AFD->hasAsync();
} else if (auto *Storage = dyn_cast<AbstractStorageDecl>(D)) {
if (auto *Getter = Storage->getAccessor(AccessorKind::Get))
Info.IsAsync = Getter->hasAsync();
}

if (!IsRef) {
Expand Down