Skip to content

Commit e939b90

Browse files
authored
Merge pull request swiftlang#41153 from hborla/existential-class
[Sema] Don't wrap class types in existential types.
2 parents f69d528 + cd84df5 commit e939b90

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,6 +4313,8 @@ Type ExistentialType::get(Type constraint) {
43134313
if (constraint->is<ExistentialMetatypeType>())
43144314
return constraint;
43154315

4316+
assert(constraint->isConstraintType());
4317+
43164318
auto properties = constraint->getRecursiveProperties();
43174319
auto arena = getArena(properties);
43184320

lib/AST/Type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,6 +3362,13 @@ Type ArchetypeType::getExistentialType() const {
33623362
auto constraint = ProtocolCompositionType::get(
33633363
ctx, constraintTypes, requiresClass());
33643364

3365+
// If the archetype is only constrained to a class type,
3366+
// return the class type directly.
3367+
if (!constraint->isConstraintType()) {
3368+
assert(constraint->getClassOrBoundGenericClass());
3369+
return constraint;
3370+
}
3371+
33653372
return ExistentialType::get(constraint);
33663373
}
33673374

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -emit-ir %s
2+
3+
import Swift
4+
5+
class C {}
6+
sil_vtable C {}
7+
8+
sil @repo: $@convention(c) @pseudogeneric <S, I where S : AnyObject, S : Hashable, I : C> (@inout_aliasable @block_storage @callee_guaranteed (@guaranteed S, Int, UnsafeMutablePointer<Bool>) -> (), S, Int, UnsafeMutablePointer<Bool>) -> () {
9+
bb0(%0 : $*@block_storage @callee_guaranteed (@guaranteed S, Int, UnsafeMutablePointer<Bool>) -> (), %1 : $S, %2 : $Int, %3 : $UnsafeMutablePointer<Bool>):
10+
%9 = tuple () // user: %10
11+
return %9 : $() // id: %10
12+
}

0 commit comments

Comments
 (0)