Skip to content

Commit 2c48da8

Browse files
committed
[AST] Relax the assertion for SILBox types in Type::transformRec.
There are places in the frontend that strip off ExistentialType from a type, e.g. in the round-trip check for type reconstruction, which is a valid transformation for SILBox types' substitutions because it doesn't invalidate conformances.
1 parent 0b8ed95 commit 2c48da8

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lib/AST/Type.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4734,14 +4734,29 @@ case TypeKind::Id:
47344734
case TypeKind::SILBox: {
47354735
bool changed = false;
47364736
auto boxTy = cast<SILBoxType>(base);
4737-
#ifndef NDEBUG
4738-
// This interface isn't suitable for updating the substitution map in a
4739-
// generic SILBox.
4740-
for (Type type : boxTy->getSubstitutions().getReplacementTypes()) {
4741-
assert(type->isEqual(type.transformRec(fn))
4737+
4738+
SmallVector<Type, 4> newReplacements;
4739+
auto subs = boxTy->getSubstitutions();
4740+
for (Type type : subs.getReplacementTypes()) {
4741+
auto transformed = type.transformRec(fn);
4742+
// This interface isn't suitable for updating the substitution map in a
4743+
// generic SILBox, with the exception of stripping off ExistentialType.
4744+
assert((type->isEqual(transformed) ||
4745+
type.findIf([](Type type) {
4746+
return type->is<ExistentialType>();
4747+
}))
47424748
&& "SILBoxType substitutions can't be transformed");
4749+
newReplacements.push_back(transformed->getCanonicalType());
4750+
if (!type->isEqual(transformed))
4751+
changed = true;
47434752
}
4744-
#endif
4753+
4754+
if (changed) {
4755+
subs = SubstitutionMap::get(subs.getGenericSignature(),
4756+
newReplacements,
4757+
subs.getConformances());
4758+
}
4759+
47454760
SmallVector<SILField, 4> newFields;
47464761
auto *l = boxTy->getLayout();
47474762
for (auto f : l->getFields()) {
@@ -4753,7 +4768,7 @@ case TypeKind::Id:
47534768
boxTy = SILBoxType::get(Ptr->getASTContext(),
47544769
SILLayout::get(Ptr->getASTContext(),
47554770
l->getGenericSignature(), newFields),
4756-
boxTy->getSubstitutions());
4771+
subs);
47574772
return boxTy;
47584773
}
47594774

0 commit comments

Comments
 (0)