Skip to content

Commit 7117966

Browse files
Merge pull request #33211 from aschwaighofer/type_substitute_objc_generics_assert_take_2
Type substitution: When substituting SILFunctionTypes we substitute unbound Objective-C generic for bound ones (take 2)
2 parents c7cc158 + caab28a commit 7117966

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/AST/Type.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,7 +4313,14 @@ case TypeKind::Id:
43134313
case TypeKind::SILFunction: {
43144314
auto fnTy = cast<SILFunctionType>(base);
43154315
bool changed = false;
4316-
4316+
auto hasTypeErasedGenericClassType = [](Type ty) -> bool {
4317+
return ty.findIf([](Type subType) -> bool {
4318+
if (subType->getCanonicalType().isTypeErasedGenericClassType())
4319+
return true;
4320+
else
4321+
return false;
4322+
});
4323+
};
43174324
auto updateSubs = [&](SubstitutionMap &subs) -> bool {
43184325
// This interface isn't suitable for updating the substitution map in a
43194326
// substituted SILFunctionType.
@@ -4323,9 +4330,8 @@ case TypeKind::Id:
43234330
auto transformed = type.transformRec(fn);
43244331
assert((type->isEqual(transformed) ||
43254332
(type->hasTypeParameter() && transformed->hasTypeParameter()) ||
4326-
(type->getCanonicalType().isTypeErasedGenericClassType() &&
4327-
transformed->getCanonicalType()
4328-
.isTypeErasedGenericClassType())) &&
4333+
(hasTypeErasedGenericClassType(type) &&
4334+
hasTypeErasedGenericClassType(transformed))) &&
43294335
"Substituted SILFunctionType can't be transformed into a "
43304336
"concrete type");
43314337
newReplacements.push_back(transformed->getCanonicalType());

test/IRGen/generic_classes_objc.sil

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ bb0(%0 : $Optional< @callee_guaranteed @substituted <τ_0_1> (@in_guaranteed Res
8484
%2 = tuple ()
8585
return %2 : $()
8686
}
87+
88+
struct PlainGeneric<T> {}
89+
90+
// This used to assert.
91+
sil @repo2 : $@convention(thin) (@guaranteed Optional< @callee_guaranteed @substituted <τ_0_1> (@in_guaranteed Result<τ_0_1, Error>) -> () for <PlainGeneric<ObjcGenericClass<SomeClass>>>>) -> () {
92+
bb0(%0 : $Optional< @callee_guaranteed @substituted <τ_0_1> (@in_guaranteed Result<τ_0_1, Error>) -> () for <PlainGeneric<ObjcGenericClass<SomeClass>>> >):
93+
debug_value %0 : $Optional<@callee_guaranteed @substituted <τ_0_1> (@in_guaranteed Result<τ_0_1, Error>) -> () for <PlainGeneric<ObjcGenericClass<SomeClass>>>>, let, name "completion", argno 1
94+
%2 = tuple ()
95+
return %2 : $()
96+
}

0 commit comments

Comments
 (0)