Skip to content

Commit ce2f375

Browse files
committed
IRGen: Add #_hasSymbol support for async declarations.
Actor isolated methods are still not supported, though, because typechecking doesn't allow a partial application of those. Resolves rdar://102094672
1 parent 6df38a6 commit ce2f375

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

lib/IRGen/Linking.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,7 @@ Alignment LinkEntity::getAlignment(IRGenModule &IGM) const {
11401140
case Kind::PartialApplyForwarderAsyncFunctionPointer:
11411141
case Kind::DistributedAccessorAsyncPointer:
11421142
case Kind::KnownAsyncFunctionPointer:
1143+
case Kind::AsyncFunctionPointerAST:
11431144
case Kind::ObjCClassRef:
11441145
case Kind::ObjCClass:
11451146
case Kind::TypeMetadataLazyCacheVariable:

test/IRGen/Inputs/has_symbol_helper.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
public let global: Int = 0
22

3+
#if CONCURRENCY
4+
@globalActor
5+
public struct GA {
6+
public actor A {}
7+
public static let shared = A()
8+
}
9+
#endif
10+
311
public func function(with argument: Int) {}
412
public func throwingFunc() throws {}
513
public func genericFunc<T: P>(_ t: T) {}
614
public func funcWithOpaqueResult() -> some P { return S(member: 0) }
715
@_cdecl("cdecl_func") public func cdeclFunc() {}
816
@_silgen_name("forward_declared_func") public func forwardDeclaredFunc()
17+
#if CONCURRENCY
18+
@GA public func isolatedFunc() {}
19+
public func asyncFunc() async {}
20+
#endif
921

1022
public protocol P {
1123
func requirement()
@@ -33,3 +45,10 @@ public enum E {
3345
case basicCase
3446
case payloadCase(_: S)
3547
}
48+
49+
#if CONCURRENCY
50+
public actor A {
51+
public init() {}
52+
public func asyncMethod() async {}
53+
}
54+
#endif

test/IRGen/has_symbol_async.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/has_symbol_helper.swiftmodule -parse-as-library %S/Inputs/has_symbol_helper.swift -enable-library-evolution -disable-availability-checking -DCONCURRENCY
3+
// RUN: %target-swift-frontend -emit-irgen %s -I %t -module-name test | %FileCheck %s
4+
5+
// REQUIRES: concurrency
6+
// REQUIRES: VENDOR=apple
7+
8+
@_weakLinked import has_symbol_helper
9+
10+
func testGlobalFunctions() {
11+
if #_hasSymbol(asyncFunc) {}
12+
// CHECK: define linkonce_odr hidden swiftcc i1 @"$s17has_symbol_helper9asyncFuncyyYaFTwS"()
13+
// CHECK: ret i1 and (i1 icmp ne (void (%swift.context*)* @"$s17has_symbol_helper9asyncFuncyyYaF", void (%swift.context*)* null), i1 icmp ne (%swift.async_func_pointer* @"$s17has_symbol_helper9asyncFuncyyYaFTu", %swift.async_func_pointer* null))
14+
15+
if #_hasSymbol(isolatedFunc) {}
16+
// CHECK: define linkonce_odr hidden swiftcc i1 @"$s17has_symbol_helper12isolatedFuncyyFTwS"()
17+
// CHECK: ret i1 icmp ne (void ()* @"$s17has_symbol_helper12isolatedFuncyyF", void ()* null)
18+
}
19+
20+
func testActor(_ a: A) {
21+
if #_hasSymbol(A.init) {}
22+
// CHECK: define linkonce_odr hidden swiftcc i1 @"$s17has_symbol_helper1ACACycfcTwS"()
23+
// CHECK: ret i1 and (i1 icmp ne (%T17has_symbol_helper1AC* (%T17has_symbol_helper1AC*)* @"$s17has_symbol_helper1ACACycfc", %T17has_symbol_helper1AC* (%T17has_symbol_helper1AC*)* null), i1 icmp ne (%T17has_symbol_helper1AC* (%swift.type*)* @"$s17has_symbol_helper1ACACycfC", %T17has_symbol_helper1AC* (%swift.type*)* null))
24+
25+
if #_hasSymbol(a.asyncMethod) {}
26+
// CHECK: define linkonce_odr hidden swiftcc i1 @"$s17has_symbol_helper1AC11asyncMethodyyYaFTwS"()
27+
// CHECK: ret i1 and (i1 and (i1 icmp ne (void (%swift.context*, %T17has_symbol_helper1AC*)* @"$s17has_symbol_helper1AC11asyncMethodyyYaFTj", void (%swift.context*, %T17has_symbol_helper1AC*)* null), i1 icmp ne (%swift.async_func_pointer* @"$s17has_symbol_helper1AC11asyncMethodyyYaFTjTu", %swift.async_func_pointer* null)), i1 icmp ne (%swift.method_descriptor* @"$s17has_symbol_helper1AC11asyncMethodyyYaFTq", %swift.method_descriptor* null))
28+
29+
// FIXME: Add support for actor isolated methods
30+
}

0 commit comments

Comments
 (0)