@@ -159,6 +159,7 @@ class Callee {
159
159
};
160
160
SILValue SelfValue;
161
161
ArrayRef<Substitution> Substitutions;
162
+ CanType OrigFormalOldType;
162
163
CanType OrigFormalInterfaceType;
163
164
CanAnyFunctionType SubstFormalType;
164
165
Optional<SILLocation> SpecializeLoc;
@@ -176,11 +177,18 @@ class Callee {
176
177
SILLocation L)
177
178
: kind(Kind::IndirectValue),
178
179
IndirectValue (indirectValue),
180
+ OrigFormalOldType(origFormalType),
179
181
OrigFormalInterfaceType(origFormalType),
180
182
SubstFormalType(substFormalType),
181
183
Loc(L)
182
184
{}
183
185
186
+ static CanAnyFunctionType getConstantFormalType (SILGenFunction &gen,
187
+ SILDeclRef fn)
188
+ SIL_FUNCTION_TYPE_DEPRECATED {
189
+ return gen.SGM .Types .getConstantInfo (fn.atUncurryLevel (0 )).FormalType ;
190
+ }
191
+
184
192
static CanAnyFunctionType getConstantFormalInterfaceType (SILGenFunction &gen,
185
193
SILDeclRef fn) {
186
194
return gen.SGM .Types .getConstantInfo (fn.atUncurryLevel (0 ))
@@ -191,6 +199,7 @@ class Callee {
191
199
CanAnyFunctionType substFormalType,
192
200
SILLocation l)
193
201
: kind(Kind::StandaloneFunction), Constant(standaloneFunction),
202
+ OrigFormalOldType(getConstantFormalType(gen, standaloneFunction)),
194
203
OrigFormalInterfaceType(getConstantFormalInterfaceType(gen,
195
204
standaloneFunction)),
196
205
SubstFormalType(substFormalType),
@@ -205,6 +214,7 @@ class Callee {
205
214
CanAnyFunctionType substFormalType,
206
215
SILLocation l)
207
216
: kind(methodKind), Constant(methodName), SelfValue(selfValue),
217
+ OrigFormalOldType(getConstantFormalType(gen, methodName)),
208
218
OrigFormalInterfaceType(getConstantFormalInterfaceType(gen, methodName)),
209
219
SubstFormalType(substFormalType),
210
220
Loc(l)
@@ -237,18 +247,11 @@ class Callee {
237
247
return CanType (TupleType::get (field, ctx));
238
248
}
239
249
250
+ // These first two asserts will crash before they return if
251
+ // they're actually wrong.
252
+ assert (getArchetypeForSelf (origParamType));
253
+ assert (getArchetypeForSelf (selfType));
240
254
assert (isa<MetatypeType>(origParamType) == isa<MetatypeType>(selfType));
241
-
242
- if (auto mt = dyn_cast<MetatypeType>(origParamType))
243
- assert (mt.getInstanceType ()->isTypeParameter ());
244
- else
245
- assert (origParamType->isTypeParameter ());
246
-
247
- if (auto mt = dyn_cast<MetatypeType>(selfType))
248
- assert (isa<ArchetypeType>(mt.getInstanceType ()));
249
- else
250
- assert (isa<ArchetypeType>(selfType));
251
-
252
255
return selfType;
253
256
}
254
257
@@ -287,13 +290,13 @@ class Callee {
287
290
288
291
// Add the 'self' parameter back. We want it to look like a
289
292
// substitution of the appropriate clause from the original type.
290
- auto origFormalType = cast<AnyFunctionType>(OrigFormalInterfaceType );
293
+ auto polyFormalType = cast<PolymorphicFunctionType>(OrigFormalOldType );
291
294
auto substSelfType =
292
- buildSubstSelfType (origFormalType .getInput (), protocolSelfType, ctx);
295
+ buildSubstSelfType (polyFormalType .getInput (), protocolSelfType, ctx);
293
296
294
297
auto extInfo = FunctionType::ExtInfo (FunctionType::Representation::Thin,
295
298
/* noreturn*/ false ,
296
- /* throws*/ origFormalType ->throws ());
299
+ /* throws*/ polyFormalType ->throws ());
297
300
298
301
SubstFormalType = CanFunctionType::get (substSelfType, SubstFormalType,
299
302
extInfo);
@@ -305,18 +308,17 @@ class Callee {
305
308
assert (kind == Kind::DynamicMethod);
306
309
307
310
// Drop the original self clause.
308
- CanType methodType = OrigFormalInterfaceType ;
311
+ CanType methodType = OrigFormalOldType ;
309
312
methodType = cast<AnyFunctionType>(methodType).getResult ();
310
313
311
314
// Replace it with the dynamic self type.
312
- OrigFormalInterfaceType
315
+ OrigFormalOldType = OrigFormalInterfaceType
313
316
= getDynamicMethodFormalType (SGM, SelfValue,
314
317
Constant.getDecl (),
315
318
Constant, methodType);
316
- assert (!OrigFormalInterfaceType->hasTypeParameter ());
317
319
318
320
// Add a self clause to the substituted type.
319
- auto origFormalType = cast<AnyFunctionType>(OrigFormalInterfaceType );
321
+ auto origFormalType = cast<AnyFunctionType>(OrigFormalOldType );
320
322
auto selfType = origFormalType.getInput ();
321
323
SubstFormalType
322
324
= CanFunctionType::get (selfType, SubstFormalType,
@@ -415,7 +417,7 @@ class Callee {
415
417
}
416
418
417
419
CanType getOrigFormalType () const {
418
- return OrigFormalInterfaceType ;
420
+ return OrigFormalOldType ;
419
421
}
420
422
421
423
CanAnyFunctionType getSubstFormalType () const {
@@ -3646,11 +3648,11 @@ SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
3646
3648
ArrayRef<ManagedValue> args,
3647
3649
SGFContext ctx) {
3648
3650
auto origFormalType =
3649
- cast<AnyFunctionType>(fn->getInterfaceType ()->getCanonicalType ());
3651
+ cast<AnyFunctionType>(fn->getType ()->getCanonicalType ());
3650
3652
auto substFormalType = origFormalType;
3651
3653
if (!subs.empty ()) {
3652
- auto genericFnType = cast<GenericFunctionType >(substFormalType);
3653
- auto applied = genericFnType ->substGenericArgs (SGM.SwiftModule , subs);
3654
+ auto polyFnType = cast<PolymorphicFunctionType >(substFormalType);
3655
+ auto applied = polyFnType ->substGenericArgs (SGM.SwiftModule , subs);
3654
3656
substFormalType = cast<FunctionType>(applied->getCanonicalType ());
3655
3657
}
3656
3658
@@ -3669,7 +3671,7 @@ SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc,
3669
3671
== SILFunctionLanguage::Swift);
3670
3672
3671
3673
return emitApply (loc, mv, subs, args, substFnType,
3672
- AbstractionPattern (origFormalType). getFunctionResultType ( ),
3674
+ AbstractionPattern (origFormalType. getResult () ),
3673
3675
substFormalType.getResult (),
3674
3676
options, None, None, ctx);
3675
3677
}
@@ -3805,10 +3807,10 @@ emitSpecializedAccessorFunctionRef(SILGenFunction &gen,
3805
3807
SILConstantInfo constantInfo = gen.getConstantInfo (constant);
3806
3808
3807
3809
// Apply substitutions to the callee type.
3808
- CanAnyFunctionType substAccessorType = constantInfo.FormalInterfaceType ;
3810
+ CanAnyFunctionType substAccessorType = constantInfo.FormalType ;
3809
3811
if (!substitutions.empty ()) {
3810
- auto genericFn = cast<GenericFunctionType >(substAccessorType);
3811
- auto substFn = genericFn ->substGenericArgs (gen.SGM .SwiftModule , substitutions);
3812
+ auto polyFn = cast<PolymorphicFunctionType >(substAccessorType);
3813
+ auto substFn = polyFn ->substGenericArgs (gen.SGM .SwiftModule , substitutions);
3812
3814
substAccessorType = cast<FunctionType>(substFn->getCanonicalType ());
3813
3815
}
3814
3816
0 commit comments