Skip to content

[IRGen] Use a async function pointer for default async protocol witness implemenations #37579

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
May 22, 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
4 changes: 4 additions & 0 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,10 @@ namespace {
if (!entry.isValid() || entry.getKind() != SILWitnessTable::Method ||
entry.getMethodWitness().Requirement != func)
continue;
auto silFunc = entry.getMethodWitness().Witness;
if (silFunc->isAsync()) {
return IGM.getAddrOfAsyncFunctionPointer(silFunc);
}
return IGM.getAddrOfSILFunction(entry.getMethodWitness().Witness,
NotForDefinition);
}
Expand Down
9 changes: 9 additions & 0 deletions test/Interpreter/Inputs/resilient_async.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public protocol Problem : class {
}

public extension Problem {
}

public func callGenericWitness<T: Problem> (_ t: T) async -> Int {
return 0
}
13 changes: 13 additions & 0 deletions test/Interpreter/Inputs/resilient_async2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public protocol Problem : class {
func theProblem() async -> Int
}

public extension Problem {
func theProblem() async -> Int {
return 1
}
}

public func callGenericWitness<T: Problem> (_ t: T) async -> Int {
return await t.theProblem()
}
29 changes: 29 additions & 0 deletions test/Interpreter/async_resilience.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %empty-directory(%t)

// 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
// RUN: %target-codesign %t/%target-library-name(resilient_async)

// RUN: %target-build-swift -parse-as-library %s -lresilient_async -I %t -L %t -o %t/main %target-rpath(%t)
// RUN: %target-codesign %t/main

// Introduce a defaulted protocol method.
// 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
// RUN: %target-codesign %t/%target-library-name(resilient_async)

// RUN: %target-run %t/main %t/%target-library-name(resilient_async)

// REQUIRES: executable_test


import resilient_async

class Impl : Problem {}

@main struct Main {
static func main() async {
let i = Impl()
// This used to crash.
let r = await callGenericWitness(i)
assert(r == 1)
}
}