Skip to content

Commit 72051ef

Browse files
committed
[Concurrency] Async CC for protocol extension methods.
Use the TypeInfo for the argument lowering type of the self parameter rather than for the self parameter's type itself.
1 parent 1a106d3 commit 72051ef

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ AsyncContextLayout irgen::getAsyncContextLayout(
138138
SILType ty =
139139
IGF.IGM.silConv.getSILType(localContextParameter, substitutedType,
140140
IGF.IGM.getMaximalTypeExpansionContext());
141-
auto &ti = IGF.getTypeInfoForLowered(ty.getASTType());
141+
auto argumentLoweringType =
142+
getArgumentLoweringType(ty.getASTType(), localContextParameter,
143+
/*isNoEscape*/ true);
144+
145+
auto &ti = IGF.getTypeInfoForLowered(argumentLoweringType);
142146
valTypes.push_back(ty);
143147
typeInfos.push_back(&ti);
144148
localContextInfo = {ty, localContextParameter.getConvention()};
@@ -1999,7 +2003,6 @@ class AsyncCallEmission final : public CallEmission {
19992003
ti.initialize(IGF, llArgs, fieldAddr, isOutlined);
20002004
}
20012005
}
2002-
}
20032006
void emitCallToUnmappedExplosion(llvm::CallInst *call, Explosion &out) override {
20042007
SILFunctionConventions fnConv(getCallee().getSubstFunctionType(),
20052008
IGF.getSILModule());
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule
3+
// RUN: %target-codesign %t/%target-library-name(PrintShims)
4+
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL
5+
// RUN: %target-build-swift -Xfrontend -enable-experimental-concurrency -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t)
6+
// RUN: %target-codesign %t/main
7+
// RUN: %target-run %t/main | %FileCheck %s
8+
9+
// REQUIRES: executable_test
10+
// REQUIRES: swift_test_mode_optimize_none
11+
// UNSUPPORTED: use_os_stdlib
12+
13+
import Builtin
14+
import Swift
15+
import PrintShims
16+
17+
sil public_external @printGeneric : $@convention(thin) <T> (@in_guaranteed T) -> ()
18+
sil public_external @printInt64 : $@convention(thin) (Int64) -> ()
19+
20+
protocol P {
21+
func printMe() -> Int64
22+
}
23+
24+
extension P {
25+
func callPrintMe() async -> Int64
26+
}
27+
28+
struct I : P {
29+
@_hasStorage let int: Int64 { get }
30+
func printMe() -> Int64
31+
init(int: Int64)
32+
}
33+
34+
// CHECK-LL: define hidden swiftcc void @callPrintMe(%swift.context* {{%[0-9]*}}) {{#[0-9]*}} {
35+
sil hidden @callPrintMe : $@async @convention(method) <Self where Self : P> (@in_guaranteed Self) -> Int64 {
36+
bb0(%self : $*Self):
37+
%P_printMe = witness_method $Self, #P.printMe : <Self where Self : P> (Self) -> () -> Int64 : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
38+
%result = apply %P_printMe<Self>(%self) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
39+
return %result : $Int64
40+
}
41+
42+
sil hidden @I_printMe : $@convention(method) (I) -> Int64 {
43+
bb0(%self : $I):
44+
%self_addr = alloc_stack $I
45+
store %self to %self_addr : $*I
46+
%printGeneric = function_ref @printGeneric : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
47+
%printGeneric_result = apply %printGeneric<I>(%self_addr) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
48+
dealloc_stack %self_addr : $*I
49+
%result = struct_extract %self : $I, #I.int
50+
return %result : $Int64
51+
}
52+
53+
sil private [transparent] [thunk] @I_P_printMe : $@convention(witness_method: P) (@in_guaranteed I) -> Int64 {
54+
bb0(%self_addr : $*I):
55+
%self = load %self_addr : $*I
56+
%I_printMe = function_ref @I_printMe : $@convention(method) (I) -> Int64
57+
%result = apply %I_printMe(%self) : $@convention(method) (I) -> Int64
58+
return %result : $Int64
59+
}
60+
61+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
62+
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
63+
%i_type = metatype $@thin I.Type
64+
%i_int_literal = integer_literal $Builtin.Int64, 99
65+
%i_int = struct $Int64 (%i_int_literal : $Builtin.Int64)
66+
%i = struct $I (%i_int : $Int64)
67+
%i_addr = alloc_stack $I
68+
store %i to %i_addr : $*I
69+
%callPrintMe = function_ref @callPrintMe : $@async @convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
70+
%result = apply %callPrintMe<I>(%i_addr) : $@async @convention(method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 // CHECK: I(int: 99)
71+
dealloc_stack %i_addr : $*I
72+
%printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> ()
73+
%printInt64_result = apply %printInt64(%result) : $@convention(thin) (Int64) -> () // CHECK: 99
74+
75+
%out_literal = integer_literal $Builtin.Int32, 0
76+
%out = struct $Int32 (%out_literal : $Builtin.Int32)
77+
return %out : $Int32
78+
}
79+
80+
sil_witness_table hidden I: P module main {
81+
method #P.printMe: <Self where Self : P> (Self) -> () -> Int64 : @I_P_printMe
82+
}

0 commit comments

Comments
 (0)