@@ -103,15 +103,22 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
103
103
// Pop the next parameter info.
104
104
auto parameterInfo = parameters.front ();
105
105
parameters = parameters.slice (1 );
106
- assert (
107
- argType
108
- == parent->getParent ()->mapTypeIntoContext (
109
- SGF.getSILType (parameterInfo))
110
- && " argument does not have same type as specified by parameter info" );
111
- (void )parameterInfo;
112
106
107
+ auto paramType = SGF.F .mapTypeIntoContext (SGF.getSILType (parameterInfo));
113
108
ManagedValue mv = SGF.B .createInputFunctionArgument (
114
- argType, loc.getAsASTNode <ValueDecl>());
109
+ paramType, loc.getAsASTNode <ValueDecl>());
110
+
111
+ if (argType != paramType) {
112
+ // This is a hack to deal with the fact that Self.Type comes in as a
113
+ // static metatype, but we have to downcast it to a dynamic Self
114
+ // metatype to get the right semantics.
115
+ assert (
116
+ cast<DynamicSelfType>(
117
+ argType.castTo <MetatypeType>().getInstanceType ())
118
+ .getSelfType ()
119
+ == paramType.castTo <MetatypeType>().getInstanceType ());
120
+ mv = SGF.B .createUncheckedBitCast (loc, mv, argType);
121
+ }
115
122
116
123
if (isInOut)
117
124
return mv;
@@ -216,7 +223,7 @@ struct ArgumentInitHelper {
216
223
assert (ty && " no type?!" );
217
224
218
225
// Create an RValue by emitting destructured arguments into a basic block.
219
- CanType canTy = ty->eraseDynamicSelfType ()-> getCanonicalType ();
226
+ CanType canTy = ty->getCanonicalType ();
220
227
EmitBBArguments argEmitter (SGF, parent, l, parameters);
221
228
222
229
// Note: inouts of tuples are not exploded, so we bypass visit().
@@ -235,17 +242,6 @@ struct ArgumentInitHelper {
235
242
236
243
if (vd->isInOut ()) {
237
244
assert (argrv.getType ().isAddress () && " expected inout to be address" );
238
- } else if (auto *metatypeTy = ty->getAs <MetatypeType>()) {
239
- // This is a hack to deal with the fact that Self.Type comes in as a
240
- // static metatype, but we have to downcast it to a dynamic Self
241
- // metatype to get the right semantics.
242
- if (metatypeTy->getInstanceType ()->is <DynamicSelfType>()) {
243
- auto loweredTy = SGF.getLoweredType (ty);
244
- if (loweredTy != argrv.getType ()) {
245
- argrv = ManagedValue::forUnmanaged (
246
- SGF.B .createUncheckedBitCast (loc, argrv.getValue (), loweredTy));
247
- }
248
- }
249
245
} else {
250
246
assert (vd->isImmutable () && " expected parameter to be immutable!" );
251
247
// If the variable is immutable, we can bind the value as is.
@@ -320,10 +316,7 @@ static void makeArgument(Type ty, ParamDecl *decl,
320
316
321
317
void SILGenFunction::bindParameterForForwarding (ParamDecl *param,
322
318
SmallVectorImpl<SILValue> ¶meters) {
323
- Type type = (param->hasType ()
324
- ? param->getType ()
325
- : F.mapTypeIntoContext (param->getInterfaceType ()));
326
- makeArgument (type->eraseDynamicSelfType (), param, parameters, *this );
319
+ makeArgument (param->getType (), param, parameters, *this );
327
320
}
328
321
329
322
void SILGenFunction::bindParametersForForwarding (const ParameterList *params,
0 commit comments