Skip to content

Commit 462eef6

Browse files
committed
Fix assertion failure when comparing reconstructed SILBoxTypes.
Substitutions in SILFunctionTypes are not handled by TypeDecoder, by adding support for SILBoxTypes to Type::transform() we can avoid an assertion failure when running the compatibility test suite. rdar://74153042
1 parent 22acb2f commit 462eef6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/AST/Type.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,16 +4314,29 @@ case TypeKind::Id:
43144314
}
43154315

43164316
case TypeKind::SILBox: {
4317+
bool changed = false;
4318+
auto boxTy = cast<SILBoxType>(base);
43174319
#ifndef NDEBUG
43184320
// This interface isn't suitable for updating the substitution map in a
43194321
// generic SILBox.
4320-
auto boxTy = cast<SILBoxType>(base);
43214322
for (Type type : boxTy->getSubstitutions().getReplacementTypes()) {
43224323
assert(type->isEqual(type.transformRec(fn))
4323-
&& "SILBoxType can't be transformed");
4324+
&& "SILBoxType substitutions can't be transformed");
43244325
}
43254326
#endif
4326-
return base;
4327+
SmallVector<SILField, 4> newFields;
4328+
auto *l = boxTy->getLayout();
4329+
for (auto f : l->getFields()) {
4330+
auto fieldTy = f.getLoweredType();
4331+
auto transformed = fieldTy.transformRec(fn)->getCanonicalType();
4332+
changed |= fieldTy != transformed;
4333+
newFields.push_back(SILField(transformed, f.isMutable()));
4334+
}
4335+
boxTy = SILBoxType::get(Ptr->getASTContext(),
4336+
SILLayout::get(Ptr->getASTContext(),
4337+
l->getGenericSignature(), newFields),
4338+
boxTy->getSubstitutions());
4339+
return boxTy;
43274340
}
43284341

43294342
case TypeKind::SILFunction: {

lib/SIL/IR/SILType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ bool SILType::isDifferentiable(SILModule &M) const {
637637

638638
Type
639639
TypeBase::replaceSubstitutedSILFunctionTypesWithUnsubstituted(SILModule &M) const {
640-
return Type(const_cast<TypeBase*>(this)).transform([&](Type t) -> Type {
641-
if (auto f = t->getAs<SILFunctionType>()) {
640+
return Type(const_cast<TypeBase *>(this)).transform([&](Type t) -> Type {
641+
if (auto *f = t->getAs<SILFunctionType>()) {
642642
auto sft = f->getUnsubstitutedType(M);
643643

644644
// Also eliminate substituted function types in the arguments, yields,

0 commit comments

Comments
 (0)