Skip to content

Commit 3400022

Browse files
committed
Sema: Remove ConstraintKind::SelfObjectOfProtocol
1 parent 5416884 commit 3400022

File tree

5 files changed

+11
-34
lines changed

5 files changed

+11
-34
lines changed

include/swift/Sema/Constraint.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ enum class ConstraintKind : char {
9292
LiteralConformsTo,
9393
/// A checked cast from the first type to the second.
9494
CheckedCast,
95-
/// The first type can act as the Self type of the second type (which
96-
/// is a protocol).
97-
///
98-
/// This constraint is slightly looser than a conforms-to constraint, because
99-
/// an existential can be used as the Self of any protocol within the
100-
/// existential, even if it doesn't conform to that protocol (e.g., due to
101-
/// the use of associated types).
102-
SelfObjectOfProtocol,
10395
/// Both types are function types. The first function type's
10496
/// input is the value being passed to the function and its output
10597
/// is a type variable that describes the output. The second
@@ -690,7 +682,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
690682
case ConstraintKind::LiteralConformsTo:
691683
case ConstraintKind::TransitivelyConformsTo:
692684
case ConstraintKind::CheckedCast:
693-
case ConstraintKind::SelfObjectOfProtocol:
694685
case ConstraintKind::ApplicableFunction:
695686
case ConstraintKind::DynamicCallableApplicableFunction:
696687
case ConstraintKind::BindOverload:

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4720,10 +4720,10 @@ class ConstraintSystem {
47204720
/// Subroutine of \c matchTypes(), which matches up a value to an
47214721
/// existential type.
47224722
///
4723-
/// \param kind Either ConstraintKind::SelfObjectOfProtocol or
4724-
/// ConstraintKind::ConformsTo. Usually this uses SelfObjectOfProtocol,
4725-
/// but when matching the instance type of a metatype with the instance type
4726-
/// of an existential metatype, since we want an actual conformance check.
4723+
/// \param kind Either ConstraintKind::Subtype or ConstraintKind::ConformsTo.
4724+
/// Usually this uses Subtype, but when matching the instance type of a
4725+
/// metatype with the instance type of an existential metatype, since we
4726+
/// want an actual conformance check.
47274727
TypeMatchResult matchExistentialTypes(Type type1, Type type2,
47284728
ConstraintKind kind,
47294729
TypeMatchOptions flags,
@@ -4930,7 +4930,7 @@ class ConstraintSystem {
49304930
///
49314931
/// \param type The type being tested.
49324932
/// \param protocol The protocol to which the type should conform.
4933-
/// \param kind Either ConstraintKind::SelfObjectOfProtocol or
4933+
/// \param kind Either ConstraintKind::Subtype or
49344934
/// ConstraintKind::ConformsTo.
49354935
/// \param locator Locator describing where this constraint occurred.
49364936
SolutionKind simplifyConformsToConstraint(Type type, ProtocolDecl *protocol,

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,8 +1873,7 @@ void PotentialBindings::infer(Constraint *constraint) {
18731873
DelayedBy.push_back(constraint);
18741874
break;
18751875

1876-
case ConstraintKind::ConformsTo:
1877-
case ConstraintKind::SelfObjectOfProtocol: {
1876+
case ConstraintKind::ConformsTo: {
18781877
auto protocolTy = constraint->getSecondType();
18791878
if (protocolTy->is<ProtocolType>())
18801879
Protocols.push_back(constraint);
@@ -1985,7 +1984,6 @@ void PotentialBindings::retract(Constraint *constraint) {
19851984

19861985
switch (constraint->getKind()) {
19871986
case ConstraintKind::ConformsTo:
1988-
case ConstraintKind::SelfObjectOfProtocol:
19891987
Protocols.erase(llvm::remove_if(Protocols, isMatchingConstraint),
19901988
Protocols.end());
19911989
break;

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,6 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
21472147
case ConstraintKind::KeyPathApplication:
21482148
case ConstraintKind::LiteralConformsTo:
21492149
case ConstraintKind::OptionalObject:
2150-
case ConstraintKind::SelfObjectOfProtocol:
21512150
case ConstraintKind::UnresolvedValueMember:
21522151
case ConstraintKind::ValueMember:
21532152
case ConstraintKind::ValueWitness:
@@ -2509,7 +2508,6 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
25092508
case ConstraintKind::KeyPathApplication:
25102509
case ConstraintKind::LiteralConformsTo:
25112510
case ConstraintKind::OptionalObject:
2512-
case ConstraintKind::SelfObjectOfProtocol:
25132511
case ConstraintKind::UnresolvedValueMember:
25142512
case ConstraintKind::ValueMember:
25152513
case ConstraintKind::ValueWitness:
@@ -3154,7 +3152,6 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
31543152
case ConstraintKind::KeyPathApplication:
31553153
case ConstraintKind::LiteralConformsTo:
31563154
case ConstraintKind::OptionalObject:
3157-
case ConstraintKind::SelfObjectOfProtocol:
31583155
case ConstraintKind::UnresolvedValueMember:
31593156
case ConstraintKind::ValueMember:
31603157
case ConstraintKind::ValueWitness:
@@ -3981,8 +3978,8 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
39813978
}
39823979

39833980
if (layout.explicitSuperclass) {
3984-
auto subKind = std::min(ConstraintKind::Subtype, kind);
3985-
auto result = matchTypes(type1, layout.explicitSuperclass, subKind,
3981+
auto result = matchTypes(type1, layout.explicitSuperclass,
3982+
ConstraintKind::Subtype,
39863983
subflags, locator);
39873984
if (result.isFailure())
39883985
return result;
@@ -6957,7 +6954,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
69576954
case ConstraintKind::KeyPathApplication:
69586955
case ConstraintKind::LiteralConformsTo:
69596956
case ConstraintKind::OptionalObject:
6960-
case ConstraintKind::SelfObjectOfProtocol:
69616957
case ConstraintKind::UnresolvedValueMember:
69626958
case ConstraintKind::ValueMember:
69636959
case ConstraintKind::ValueWitness:
@@ -8468,7 +8464,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
84688464
// conform -- they only need to contain the protocol, so check that
84698465
// separately.
84708466
switch (kind) {
8471-
case ConstraintKind::SelfObjectOfProtocol: {
8467+
case ConstraintKind::Subtype: {
84728468
auto conformance = TypeChecker::containsProtocol(
84738469
type, protocol, /*allowMissing=*/true);
84748470
if (conformance) {
@@ -14268,7 +14264,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1426814264
case ConversionRestrictionKind::Existential:
1426914265
addContextualScore();
1427014266
return matchExistentialTypes(type1, type2,
14271-
ConstraintKind::SelfObjectOfProtocol,
14267+
ConstraintKind::Subtype,
1427214268
subflags, locator);
1427314269

1427414270
// for $< in { <, <c, <oc }:
@@ -15535,7 +15531,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1553515531

1553615532
case ConstraintKind::ConformsTo:
1553715533
case ConstraintKind::LiteralConformsTo:
15538-
case ConstraintKind::SelfObjectOfProtocol:
1553915534
return simplifyConformsToConstraint(first, second, kind, locator,
1554015535
subflags);
1554115536

@@ -16066,7 +16061,6 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1606616061

1606716062
case ConstraintKind::ConformsTo:
1606816063
case ConstraintKind::LiteralConformsTo:
16069-
case ConstraintKind::SelfObjectOfProtocol:
1607016064
return simplifyConformsToConstraint(
1607116065
constraint.getFirstType(), constraint.getSecondType(),
1607216066
constraint.getKind(), constraint.getLocator(), std::nullopt);

lib/Sema/Constraint.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
7070
case ConstraintKind::LiteralConformsTo:
7171
case ConstraintKind::TransitivelyConformsTo:
7272
case ConstraintKind::CheckedCast:
73-
case ConstraintKind::SelfObjectOfProtocol:
7473
case ConstraintKind::DynamicTypeOf:
7574
case ConstraintKind::EscapableFunctionOf:
7675
case ConstraintKind::OpenedExistentialOf:
@@ -151,7 +150,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third,
151150
case ConstraintKind::LiteralConformsTo:
152151
case ConstraintKind::TransitivelyConformsTo:
153152
case ConstraintKind::CheckedCast:
154-
case ConstraintKind::SelfObjectOfProtocol:
155153
case ConstraintKind::DynamicTypeOf:
156154
case ConstraintKind::EscapableFunctionOf:
157155
case ConstraintKind::OpenedExistentialOf:
@@ -294,7 +292,6 @@ Constraint::Constraint(ASTNode node, ContextualTypeInfo context,
294292
ProtocolDecl *Constraint::getProtocol() const {
295293
assert((Kind == ConstraintKind::ConformsTo ||
296294
Kind == ConstraintKind::LiteralConformsTo ||
297-
Kind == ConstraintKind::SelfObjectOfProtocol ||
298295
Kind == ConstraintKind::TransitivelyConformsTo)
299296
&& "Not a conformance constraint");
300297
return Types.Second->castTo<ProtocolType>()->getDecl();
@@ -394,7 +391,6 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm,
394391
case ConstraintKind::LiteralConformsTo: Out << " literal conforms to "; break;
395392
case ConstraintKind::TransitivelyConformsTo: Out << " transitive conformance to "; break;
396393
case ConstraintKind::CheckedCast: Out << " checked cast to "; break;
397-
case ConstraintKind::SelfObjectOfProtocol: Out << " Self type of "; break;
398394
case ConstraintKind::ApplicableFunction: Out << " applicable fn "; break;
399395
case ConstraintKind::DynamicCallableApplicableFunction:
400396
Out << " dynamic callable applicable fn "; break;
@@ -682,7 +678,6 @@ gatherReferencedTypeVars(Constraint *constraint,
682678
case ConstraintKind::ConformsTo:
683679
case ConstraintKind::LiteralConformsTo:
684680
case ConstraintKind::TransitivelyConformsTo:
685-
case ConstraintKind::SelfObjectOfProtocol:
686681
case ConstraintKind::OneWayEqual:
687682
case ConstraintKind::OneWayBindParam:
688683
case ConstraintKind::FallbackType:
@@ -751,8 +746,7 @@ Constraint *Constraint::create(ConstraintSystem &cs, ConstraintKind kind,
751746

752747
// Conformance constraints expect an existential on the right-hand side.
753748
assert((kind != ConstraintKind::ConformsTo &&
754-
kind != ConstraintKind::TransitivelyConformsTo &&
755-
kind != ConstraintKind::SelfObjectOfProtocol) ||
749+
kind != ConstraintKind::TransitivelyConformsTo) ||
756750
second->isExistentialType());
757751

758752
// Literal protocol conformances expect a protocol.

0 commit comments

Comments
 (0)