@@ -82,11 +82,10 @@ SILValue SILGenFunction::emitDynamicMethodRef(SILLocation loc,
82
82
return B.createFunctionRef (loc, F);
83
83
}
84
84
85
- static SILValue getNextUncurryLevelRef (SILGenFunction &SGF,
86
- SILLocation loc,
87
- SILDeclRef thunk,
88
- SILValue selfArg,
89
- SubstitutionList curriedSubs) {
85
+ static ManagedValue getNextUncurryLevelRef (SILGenFunction &SGF, SILLocation loc,
86
+ SILDeclRef thunk,
87
+ ManagedValue selfArg,
88
+ SubstitutionList curriedSubs) {
90
89
auto *vd = thunk.getDecl ();
91
90
92
91
// Reference the next uncurrying level of the function.
@@ -95,23 +94,26 @@ static SILValue getNextUncurryLevelRef(SILGenFunction &SGF,
95
94
96
95
// If the function is natively foreign, reference its foreign entry point.
97
96
if (requiresForeignToNativeThunk (vd))
98
- return SGF.emitGlobalFunctionRef (loc, next);
97
+ return ManagedValue::forUnmanaged ( SGF.emitGlobalFunctionRef (loc, next) );
99
98
100
99
// If the thunk is a curry thunk for a direct method reference, we are
101
100
// doing a direct dispatch (eg, a fragile 'super.foo()' call).
102
101
if (thunk.isDirectReference )
103
- return SGF.emitGlobalFunctionRef (loc, next);
102
+ return ManagedValue::forUnmanaged ( SGF.emitGlobalFunctionRef (loc, next) );
104
103
105
104
auto constantInfo = SGF.SGM .Types .getConstantInfo (next);
106
105
107
106
if (auto *func = dyn_cast<AbstractFunctionDecl>(vd)) {
108
107
if (getMethodDispatch (func) == MethodDispatch::Class) {
109
108
// Use the dynamic thunk if dynamic.
110
109
if (vd->isDynamic ())
111
- return SGF.emitDynamicMethodRef (loc, next, constantInfo.SILFnType );
110
+ return ManagedValue::forUnmanaged (
111
+ SGF.emitDynamicMethodRef (loc, next, constantInfo.SILFnType ));
112
112
113
113
auto methodTy = SGF.SGM .Types .getConstantOverrideType (next);
114
- return SGF.emitClassMethodRef (loc, selfArg, next, methodTy);
114
+ SILValue result =
115
+ SGF.emitClassMethodRef (loc, selfArg.getValue (), next, methodTy);
116
+ return ManagedValue::forUnmanaged (result);
115
117
}
116
118
117
119
// If the fully-uncurried reference is to a generic method, look up the
@@ -125,13 +127,14 @@ static SILValue getNextUncurryLevelRef(SILGenFunction &SGF,
125
127
auto origSelfType = protocol->getSelfInterfaceType ()->getCanonicalType ();
126
128
auto substSelfType = origSelfType.subst (subMap)->getCanonicalType ();
127
129
auto conformance = subMap.lookupConformance (origSelfType, protocol);
128
- return SGF.B .createWitnessMethod (loc, substSelfType, *conformance, next,
129
- constantInfo.getSILType ());
130
+ auto result = SGF.B .createWitnessMethod (loc, substSelfType, *conformance,
131
+ next, constantInfo.getSILType ());
132
+ return ManagedValue::forUnmanaged (result);
130
133
}
131
134
}
132
135
133
136
// Otherwise, emit a direct call.
134
- return SGF.emitGlobalFunctionRef (loc, next);
137
+ return ManagedValue::forUnmanaged ( SGF.emitGlobalFunctionRef (loc, next) );
135
138
}
136
139
137
140
void SILGenFunction::emitCurryThunk (SILDeclRef thunk) {
@@ -148,13 +151,13 @@ void SILGenFunction::emitCurryThunk(SILDeclRef thunk) {
148
151
auto selfTy = vd->getInterfaceType ()->castTo <AnyFunctionType>()
149
152
->getInput ();
150
153
selfTy = vd->getInnermostDeclContext ()->mapTypeIntoContext (selfTy);
151
- auto selfArg = F.begin ()->createFunctionArgument (getLoweredType (selfTy));
154
+ ManagedValue selfArg =
155
+ B.createFunctionArgument (getLoweredType (selfTy), nullptr );
152
156
153
157
// Forward substitutions.
154
158
auto subs = F.getForwardingSubstitutions ();
155
159
156
- SILValue toFn = getNextUncurryLevelRef (*this , vd, thunk,
157
- selfArg, subs);
160
+ ManagedValue toFn = getNextUncurryLevelRef (*this , vd, thunk, selfArg, subs);
158
161
159
162
// FIXME: Using the type from the ConstantInfo instead of looking at
160
163
// getConstantOverrideInfo() for methods looks suspect in the presence
@@ -163,25 +166,23 @@ void SILGenFunction::emitCurryThunk(SILDeclRef thunk) {
163
166
SGM.Types .getConstantInfo (thunk).SILFnType , SGM.M );
164
167
SILType resultTy = fromConv.getSingleSILResultType ();
165
168
resultTy = F.mapTypeIntoContext (resultTy);
166
- auto substTy = toFn-> getType ().substGenericArgs (SGM.M , subs);
169
+ auto substTy = toFn. getType ().substGenericArgs (SGM.M , subs);
167
170
168
171
auto calleeConvention = ParameterConvention::Direct_Guaranteed;
169
172
170
173
// Partially apply the next uncurry level and return the result closure.
171
174
auto closureTy = SILGenBuilder::getPartialApplyResultType (
172
- toFn-> getType (), /* appliedParams=*/ 1 , SGM.M , subs, calleeConvention);
173
- SILValue toClosure =
174
- B.createPartialApply (vd, toFn, substTy, subs, {selfArg}, closureTy);
175
+ toFn. getType (), /* appliedParams=*/ 1 , SGM.M , subs, calleeConvention);
176
+ ManagedValue toClosure =
177
+ B.createPartialApply (vd, toFn, substTy, subs, {selfArg}, closureTy);
175
178
if (resultTy != closureTy) {
176
179
CanSILFunctionType resultFnTy = resultTy.castTo <SILFunctionType>();
177
180
CanSILFunctionType closureFnTy = closureTy.castTo <SILFunctionType>();
178
181
if (resultFnTy->isABICompatibleWith (closureFnTy).isCompatible ()) {
179
182
toClosure = B.createConvertFunction (vd, toClosure, resultTy);
180
183
} else {
181
184
toClosure =
182
- emitCanonicalFunctionThunk (vd, ManagedValue::forUnmanaged (toClosure),
183
- closureFnTy, resultFnTy)
184
- .forward (*this );
185
+ emitCanonicalFunctionThunk (vd, toClosure, closureFnTy, resultFnTy);
185
186
}
186
187
}
187
188
B.createReturn (ImplicitReturnLocation::getImplicitReturnLoc (vd), toClosure);
0 commit comments