@@ -64,34 +64,49 @@ IRGenModule::getAddrOfDispatchThunk(SILDeclRef declRef,
64
64
static FunctionPointer lookupMethod (IRGenFunction &IGF, SILDeclRef declRef) {
65
65
auto expansionContext = IGF.IGM .getMaximalTypeExpansionContext ();
66
66
auto *decl = cast<AbstractFunctionDecl>(declRef.getDecl ());
67
+ auto funcTy = IGF.IGM .getSILModule ().Types .getConstantFunctionType (
68
+ expansionContext, declRef);
69
+
70
+ auto getAsyncContextLayout = [&]() {
71
+ auto originalType = funcTy;
72
+ auto forwardingSubstitutionMap =
73
+ decl->getGenericEnvironment ()
74
+ ? decl->getGenericEnvironment ()->getForwardingSubstitutionMap ()
75
+ : SubstitutionMap ();
76
+ auto substitutedType = originalType->substGenericArgs (
77
+ IGF.IGM .getSILModule (), forwardingSubstitutionMap,
78
+ IGF.IGM .getMaximalTypeExpansionContext ());
79
+ auto layout = irgen::getAsyncContextLayout (
80
+ IGF.IGM , originalType, substitutedType, forwardingSubstitutionMap);
81
+ return layout;
82
+ };
67
83
68
84
// Protocol case.
69
85
if (isa<ProtocolDecl>(decl->getDeclContext ())) {
70
86
// Find the witness table.
71
- llvm::Value *wtable = (IGF.CurFn ->arg_end () - 1 );
87
+ llvm::Value *wtable;
88
+ if (funcTy->isAsync ()) {
89
+ auto layout = getAsyncContextLayout ();
90
+ assert (layout.hasTrailingWitnesses ());
91
+ auto context = layout.emitCastTo (IGF, IGF.getAsyncContext ());
92
+ auto wtableAddr =
93
+ layout.getSelfWitnessTableLayout ().project (IGF, context, llvm::None);
94
+ wtable = IGF.Builder .CreateLoad (wtableAddr);
95
+ } else {
96
+ wtable = (IGF.CurFn ->arg_end () - 1 );
97
+ }
72
98
73
99
// Find the witness we're interested in.
74
100
return emitWitnessMethodValue (IGF, wtable, declRef);
75
101
}
76
102
77
103
// Class case.
78
- auto funcTy = IGF.IGM .getSILModule ().Types .getConstantFunctionType (
79
- expansionContext, declRef);
80
104
81
105
// Load the metadata, or use the 'self' value if we have a static method.
82
106
llvm::Value *self;
83
107
84
108
if (funcTy->isAsync ()) {
85
- auto originalType = funcTy;
86
- auto forwardingSubstitutionMap =
87
- decl->getGenericEnvironment ()
88
- ? decl->getGenericEnvironment ()->getForwardingSubstitutionMap ()
89
- : SubstitutionMap ();
90
- auto substitutedType = originalType->substGenericArgs (
91
- IGF.IGM .getSILModule (), forwardingSubstitutionMap,
92
- IGF.IGM .getMaximalTypeExpansionContext ());
93
- auto layout = getAsyncContextLayout (IGF.IGM , originalType, substitutedType,
94
- forwardingSubstitutionMap);
109
+ auto layout = getAsyncContextLayout ();
95
110
assert (layout.hasLocalContext ());
96
111
auto context = layout.emitCastTo (IGF, IGF.getAsyncContext ());
97
112
auto localContextAddr =
0 commit comments