Skip to content

Commit 3419345

Browse files
Merge pull request #37582 from aschwaighofer/async_default_witness_5.5-05142021
[5.5-0514202] Use a async function pointer for default async protocol witness implemenations
2 parents b5313ca + bc7c357 commit 3419345

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,10 @@ namespace {
916916
if (!entry.isValid() || entry.getKind() != SILWitnessTable::Method ||
917917
entry.getMethodWitness().Requirement != func)
918918
continue;
919+
auto silFunc = entry.getMethodWitness().Witness;
920+
if (silFunc->isAsync()) {
921+
return IGM.getAddrOfAsyncFunctionPointer(silFunc);
922+
}
919923
return IGM.getAddrOfSILFunction(entry.getMethodWitness().Witness,
920924
NotForDefinition);
921925
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public protocol Problem : class {
2+
}
3+
4+
public extension Problem {
5+
}
6+
7+
public func callGenericWitness<T: Problem> (_ t: T) async -> Int {
8+
return 0
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public protocol Problem : class {
2+
func theProblem() async -> Int
3+
}
4+
5+
public extension Problem {
6+
func theProblem() async -> Int {
7+
return 1
8+
}
9+
}
10+
11+
public func callGenericWitness<T: Problem> (_ t: T) async -> Int {
12+
return await t.theProblem()
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift-dylib(%t/%target-library-name(resilient_async)) -enable-library-evolution %S/Inputs/resilient_async.swift -emit-module -emit-module-path %t/resilient_async.swiftmodule -module-name resilient_async
4+
// RUN: %target-codesign %t/%target-library-name(resilient_async)
5+
6+
// RUN: %target-build-swift -parse-as-library %s -lresilient_async -I %t -L %t -o %t/main %target-rpath(%t)
7+
// RUN: %target-codesign %t/main
8+
9+
// Introduce a defaulted protocol method.
10+
// RUN: %target-build-swift-dylib(%t/%target-library-name(resilient_async)) -enable-library-evolution %S/Inputs/resilient_async2.swift -emit-module -emit-module-path %t/resilient_async.swiftmodule -module-name resilient_async
11+
// RUN: %target-codesign %t/%target-library-name(resilient_async)
12+
13+
// RUN: %target-run %t/main %t/%target-library-name(resilient_async)
14+
15+
// REQUIRES: executable_test
16+
17+
18+
import resilient_async
19+
20+
class Impl : Problem {}
21+
22+
@main struct Main {
23+
static func main() async {
24+
let i = Impl()
25+
// This used to crash.
26+
let r = await callGenericWitness(i)
27+
assert(r == 1)
28+
}
29+
}

0 commit comments

Comments
 (0)