Skip to content

Commit 341a119

Browse files
Merge pull request #35437 from nate-chandler/rdar73203508
[TBDGen] Use effective linkage for class member async function pointers.
2 parents f641a26 + 2e880af commit 341a119

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,20 @@ void TBDGenVisitor::addSymbol(SILDeclRef declRef) {
418418
addSymbol(declRef.mangle(), SymbolSource::forSILDeclRef(declRef));
419419
}
420420

421+
void TBDGenVisitor::addAsyncFunctionPointerSymbol(AbstractFunctionDecl *AFD) {
422+
auto declRef = SILDeclRef(AFD);
423+
auto silLinkage = effectiveLinkageForClassMember(
424+
declRef.getLinkage(ForDefinition),
425+
declRef.getSubclassScope());
426+
if (Opts.PublicSymbolsOnly && silLinkage != SILLinkage::Public)
427+
return;
428+
429+
auto entity = LinkEntity::forAsyncFunctionPointer(AFD);
430+
auto linkage =
431+
LinkInfo::get(UniversalLinkInfo, SwiftModule, entity, ForDefinition);
432+
addSymbol(linkage.getName(), SymbolSource::forSILDeclRef(declRef));
433+
}
434+
421435
void TBDGenVisitor::addSymbol(LinkEntity entity) {
422436
auto linkage =
423437
LinkInfo::get(UniversalLinkInfo, SwiftModule, entity, ForDefinition);
@@ -724,7 +738,7 @@ void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
724738
visitDefaultArguments(AFD, AFD->getParameters());
725739

726740
if (AFD->hasAsync()) {
727-
addSymbol(LinkEntity::forAsyncFunctionPointer(AFD));
741+
addAsyncFunctionPointerSymbol(AFD);
728742
}
729743
}
730744

lib/TBDGen/TBDGenVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9999
SymbolKind kind = SymbolKind::GlobalSymbol);
100100

101101
void addSymbol(SILDeclRef declRef);
102+
void addAsyncFunctionPointerSymbol(AbstractFunctionDecl *AFD);
102103

103104
void addSymbol(LinkEntity entity);
104105

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import _Concurrency
2+
3+
func printGeneric<T>(_ t: T) {
4+
print(t)
5+
}
6+
// CHECK-LL: @"$s4main6call_fyyAA1CCYFTu" = {{(dllexport )?}}{{(protected )?}}global %swift.async_func_pointer
7+
// CHECK-LL: @"$s4main1CC1fyyYFTu" = {{(dllexport )?}}{{(protected )?}}global %swift.async_func_pointer
8+
9+
// CHECK-LL: define {{(dllexport )?}}{{(protected )?}}swiftcc void @"$s4main6call_fyyAA1CCYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) {{#[0-9]*}} {
10+
// CHECK-LL: define {{(dllexport )?}}{{(protected )?}}swiftcc void @"$s4main1CC1fyyYF"(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) {{#[0-9]*}} {
11+
public func call_f(_ c: C) async {
12+
print("entering call_f")
13+
await c.f()
14+
print("exiting call_f")
15+
}
16+
open class C {
17+
public init() {}
18+
func f() async {
19+
printGeneric("entering f")
20+
printGeneric(Self.self)
21+
printGeneric(self)
22+
printGeneric("exiting f")
23+
}
24+
}
25+
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-build-swift-dylib(%t/%target-library-name(NonresilientClass)) %S/Inputs/class_open-1instance-void_to_void.swift -Xfrontend -enable-experimental-concurrency -module-name NonresilientClass -emit-module -emit-module-path %t/NonresilientClass.swiftmodule
3+
// RUN: %target-codesign %t/%target-library-name(NonresilientClass)
4+
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %S/Inputs/class_open-1instance-void_to_void.swift -emit-ir -I %t -L %t -lNonresilientClass | %FileCheck %S/Inputs/class_open-1instance-void_to_void.swift --check-prefix=CHECK-LL
5+
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency %s -module-name main -o %t/main -I %t -L %t -lNonresilientClass %target-rpath(%t)
6+
// RUN: %target-codesign %t/main
7+
// RUN: %target-run %t/main %t/%target-library-name(NonresilientClass) | %FileCheck %s
8+
9+
// REQUIRES: executable_test
10+
// REQUIRES: swift_test_mode_optimize_none
11+
// REQUIRES: concurrency
12+
// UNSUPPORTED: use_os_stdlib
13+
// XFAIL: windows
14+
15+
import _Concurrency
16+
import NonresilientClass
17+
18+
class D : C {
19+
}
20+
21+
// CHECK: entering call_f
22+
// CHECK: entering f
23+
// CHECK: D
24+
// CHECK: main.D
25+
// CHECK: exiting f
26+
// CHECK: exiting call_f
27+
runAsyncAndBlock {
28+
let c = D()
29+
await call_f(c)
30+
}

test/TBD/async-function-pointer.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55

66
@asyncHandler
77
public func testit() { }
8+
9+
// CHECK: @"$s4test1CC1f33_295642D23064661A21CD592AD781409CLLyyYFTu" = global %swift.async_func_pointer
10+
11+
open class C {
12+
private func f() async { }
13+
}

0 commit comments

Comments
 (0)