Skip to content

Commit a0eeabc

Browse files
committed
When computing the field type of a SILType, add substitutions to the orig type.
1 parent 8ff61d6 commit a0eeabc

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
@@ -301,9 +301,30 @@ bool SILType::canRefCast(SILType operTy, SILType resultTy, SILModule &M) {
301301
&& toTy.isHeapObjectReferenceType();
302302
}
303303

304+
static bool needsFieldSubstitutions(const AbstractionPattern &origType) {
305+
if (origType.isTypeParameter()) return false;
306+
auto type = origType.getType();
307+
if (!type->hasTypeParameter()) return false;
308+
return type.findIf([](CanType type) {
309+
return isa<PackExpansionType>(type);
310+
});
311+
}
312+
313+
static void addFieldSubstitutionsIfNeeded(TypeConverter &TC, SILType ty,
314+
ValueDecl *field,
315+
AbstractionPattern &origType) {
316+
if (needsFieldSubstitutions(origType)) {
317+
auto subMap = ty.getASTType()->getContextSubstitutionMap(
318+
&TC.M, field->getDeclContext());
319+
origType = origType.withSubstitutions(subMap);
320+
}
321+
}
322+
304323
SILType SILType::getFieldType(VarDecl *field, TypeConverter &TC,
305324
TypeExpansionContext context) const {
306325
AbstractionPattern origFieldTy = TC.getAbstractionPattern(field);
326+
addFieldSubstitutionsIfNeeded(TC, *this, field, origFieldTy);
327+
307328
CanType substFieldTy;
308329
if (field->hasClangNode()) {
309330
substFieldTy = origFieldTy.getType();
@@ -372,6 +393,9 @@ SILType SILType::getEnumElementType(EnumElementDecl *elt, TypeConverter &TC,
372393
getCategory());
373394
}
374395

396+
auto origEltType = TC.getAbstractionPattern(elt);
397+
addFieldSubstitutionsIfNeeded(TC, *this, elt, origEltType);
398+
375399
auto substEltTy = getASTType()->getTypeOfMember(
376400
&TC.M, elt, elt->getArgumentInterfaceType());
377401
auto loweredTy = TC.getLoweredRValueType(

0 commit comments

Comments
 (0)