Skip to content

Commit efa9966

Browse files
committed
SILGen: Centralize DynamicSelfType hackyness a bit
Get rid of some randomly-placed calls to eraseDynamicSelfType() and refactors things in preparation for the next change.
1 parent 853913d commit efa9966

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
17871787

17881788
FuncDecl *func = cast<FuncDecl>(vd);
17891789
auto funcTy = cast<AnyFunctionType>(
1790-
func->getInterfaceType()->eraseDynamicSelfType()->getCanonicalType());
1790+
func->getInterfaceType()->getCanonicalType());
17911791
return getFunctionInterfaceTypeWithCaptures(funcTy, func);
17921792
}
17931793

lib/SILGen/SILGenProlog.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,22 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
103103
// Pop the next parameter info.
104104
auto parameterInfo = parameters.front();
105105
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;
112106

107+
auto paramType = SGF.F.mapTypeIntoContext(SGF.getSILType(parameterInfo));
113108
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+
}
115122

116123
if (isInOut)
117124
return mv;
@@ -216,7 +223,7 @@ struct ArgumentInitHelper {
216223
assert(ty && "no type?!");
217224

218225
// Create an RValue by emitting destructured arguments into a basic block.
219-
CanType canTy = ty->eraseDynamicSelfType()->getCanonicalType();
226+
CanType canTy = ty->getCanonicalType();
220227
EmitBBArguments argEmitter(SGF, parent, l, parameters);
221228

222229
// Note: inouts of tuples are not exploded, so we bypass visit().
@@ -235,17 +242,6 @@ struct ArgumentInitHelper {
235242

236243
if (vd->isInOut()) {
237244
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-
}
249245
} else {
250246
assert(vd->isImmutable() && "expected parameter to be immutable!");
251247
// If the variable is immutable, we can bind the value as is.
@@ -320,10 +316,7 @@ static void makeArgument(Type ty, ParamDecl *decl,
320316

321317
void SILGenFunction::bindParameterForForwarding(ParamDecl *param,
322318
SmallVectorImpl<SILValue> &parameters) {
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);
327320
}
328321

329322
void SILGenFunction::bindParametersForForwarding(const ParameterList *params,

0 commit comments

Comments
 (0)