Skip to content

Commit 35159da

Browse files
authored
Merge pull request #31569 from apple/rdar-62842651-workaround
[ConstraintSystem] Temporary revert `84a3db45db96` as a workaround for rdar://problem/62842651
2 parents b4ede30 + 29ae605 commit 35159da

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,34 +4392,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
43924392
auto meta1 = cast<AnyMetatypeType>(desugar1);
43934393
auto meta2 = cast<AnyMetatypeType>(desugar2);
43944394

4395-
auto instanceType1 = meta1->getInstanceType();
4396-
auto instanceType2 = meta2->getInstanceType();
4397-
43984395
// A.Type < B.Type if A < B and both A and B are classes.
43994396
// P.Type < Q.Type if P < Q, both P and Q are protocols, and P.Type
4400-
// and Q.Type are both existential metatypes.
4401-
auto getSubKind = [&]() -> ConstraintKind {
4402-
auto subKind = std::min(kind, ConstraintKind::Subtype);
4403-
4404-
// If we have existential metatypes, we need to perform subtyping.
4405-
if (!isa<MetatypeType>(meta1))
4406-
return subKind;
4407-
4408-
// If the LHS cannot be a type with a superclass, we can perform a bind.
4409-
if (!instanceType1->isTypeVariableOrMember() &&
4410-
!instanceType1->mayHaveSuperclass())
4411-
return ConstraintKind::Bind;
4412-
4413-
// If the RHS cannot be a class type, we can perform a bind.
4414-
if (!instanceType2->isTypeVariableOrMember() &&
4415-
!instanceType2->getClassOrBoundGenericClass())
4416-
return ConstraintKind::Bind;
4417-
4418-
return subKind;
4419-
};
4397+
// and Q.Type are both existential metatypes
4398+
auto subKind = std::min(kind, ConstraintKind::Subtype);
4399+
// If instance types can't have a subtype relationship
4400+
// it means that such types can be simply equated.
4401+
auto instanceType1 = meta1->getInstanceType();
4402+
auto instanceType2 = meta2->getInstanceType();
4403+
if (isa<MetatypeType>(meta1) &&
4404+
!(instanceType1->mayHaveSuperclass() &&
4405+
instanceType2->getClassOrBoundGenericClass())) {
4406+
subKind = ConstraintKind::Bind;
4407+
}
44204408

44214409
auto result =
4422-
matchTypes(instanceType1, instanceType2, getSubKind(), subflags,
4410+
matchTypes(instanceType1, instanceType2, subKind, subflags,
44234411
locator.withPathElement(ConstraintLocator::InstanceType));
44244412

44254413
// If matching of the instance types resulted in the failure make sure

test/Constraints/rdar62842651.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
2+
3+
class A {}
4+
class B: A {}
5+
6+
func test<T>(_ type: T.Type) -> T? {
7+
fatalError()
8+
}
9+
10+
// CHECK: [[RESULT:%.*]] = function_ref @$s12rdar628426514testyxSgxmlF
11+
// CHECK-NEXT: apply [[RESULT]]<B>({{.*}})
12+
let _: A? = test(B.self)

0 commit comments

Comments
 (0)