Skip to content

Fix assertion failure when comparing reconstructed SILBoxTypes. #35861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4314,16 +4314,29 @@ case TypeKind::Id:
}

case TypeKind::SILBox: {
bool changed = false;
auto boxTy = cast<SILBoxType>(base);
#ifndef NDEBUG
// This interface isn't suitable for updating the substitution map in a
// generic SILBox.
auto boxTy = cast<SILBoxType>(base);
for (Type type : boxTy->getSubstitutions().getReplacementTypes()) {
assert(type->isEqual(type.transformRec(fn))
&& "SILBoxType can't be transformed");
&& "SILBoxType substitutions can't be transformed");
}
#endif
return base;
SmallVector<SILField, 4> newFields;
auto *l = boxTy->getLayout();
for (auto f : l->getFields()) {
auto fieldTy = f.getLoweredType();
auto transformed = fieldTy.transformRec(fn)->getCanonicalType();
changed |= fieldTy != transformed;
newFields.push_back(SILField(transformed, f.isMutable()));
}
boxTy = SILBoxType::get(Ptr->getASTContext(),
SILLayout::get(Ptr->getASTContext(),
l->getGenericSignature(), newFields),
boxTy->getSubstitutions());
return boxTy;
}

case TypeKind::SILFunction: {
Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/IR/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ bool SILType::isDifferentiable(SILModule &M) const {

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

// Also eliminate substituted function types in the arguments, yields,
Expand Down