Skip to content

Commit 7d315d4

Browse files
committed
When computing the field type of a SILType, add substitutions to the orig type.
1 parent f4fbc11 commit 7d315d4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/SIL/IR/SILType.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,30 @@ bool SILType::canRefCast(SILType operTy, SILType resultTy, SILModule &M) {
296296
&& toTy.isHeapObjectReferenceType();
297297
}
298298

299+
static bool needsFieldSubstitutions(const AbstractionPattern &origType) {
300+
if (origType.isTypeParameter()) return false;
301+
auto type = origType.getType();
302+
if (!type->hasTypeParameter()) return false;
303+
return type.findIf([](CanType type) {
304+
return isa<PackExpansionType>(type);
305+
});
306+
}
307+
308+
static void addFieldSubstitutionsIfNeeded(TypeConverter &TC, SILType ty,
309+
ValueDecl *field,
310+
AbstractionPattern &origType) {
311+
if (needsFieldSubstitutions(origType)) {
312+
auto subMap = ty.getASTType()->getContextSubstitutionMap(
313+
&TC.M, field->getDeclContext());
314+
origType = origType.withSubstitutions(subMap);
315+
}
316+
}
317+
299318
SILType SILType::getFieldType(VarDecl *field, TypeConverter &TC,
300319
TypeExpansionContext context) const {
301320
AbstractionPattern origFieldTy = TC.getAbstractionPattern(field);
321+
addFieldSubstitutionsIfNeeded(TC, *this, field, origFieldTy);
322+
302323
CanType substFieldTy;
303324
if (field->hasClangNode()) {
304325
substFieldTy = origFieldTy.getType();
@@ -348,6 +369,9 @@ SILType SILType::getEnumElementType(EnumElementDecl *elt, TypeConverter &TC,
348369
getCategory());
349370
}
350371

372+
auto origEltType = TC.getAbstractionPattern(elt);
373+
addFieldSubstitutionsIfNeeded(TC, *this, elt, origEltType);
374+
351375
auto substEltTy = getASTType()->getTypeOfMember(
352376
&TC.M, elt, elt->getArgumentInterfaceType());
353377
auto loweredTy = TC.getLoweredRValueType(

0 commit comments

Comments
 (0)