Skip to content

Commit f53d7a2

Browse files
committed
[AST] InvertibleAnnotationRequest: Remove logic associated with protocol handling
1 parent 4921e77 commit f53d7a2

File tree

2 files changed

+19
-65
lines changed

2 files changed

+19
-65
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,8 @@ InverseMarking
915915
InvertibleAnnotationRequest::evaluate(Evaluator &evaluator,
916916
TypeDecl *decl,
917917
InvertibleProtocolKind ip) const {
918+
assert(!isa<ProtocolDecl>(decl));
919+
918920
auto &ctx = decl->getASTContext();
919921
const auto TARGET = ip;
920922
using Kind = InverseMarking::Kind;
@@ -1062,69 +1064,20 @@ InvertibleAnnotationRequest::evaluate(Evaluator &evaluator,
10621064
return result;
10631065
};
10641066

1065-
// Checks a where clause for constraints of the form:
1066-
// - Self : TARGET
1067-
// - Self : ~TARGET
1068-
// and records them in the `InverseMarking` result.
1069-
auto whereClauseVisitor = [&](GenericContext *GC, unsigned reqIdx,
1070-
RequirementRepr &reqRepr,
1071-
InverseMarking &result) {
1072-
if (reqRepr.isInvalid() ||
1073-
reqRepr.getKind() != RequirementReprKind::TypeConstraint)
1074-
return;
1075-
1076-
auto *subjectRepr = dyn_cast<IdentTypeRepr>(reqRepr.getSubjectRepr());
1077-
auto *constraintRepr = reqRepr.getConstraintRepr();
1078-
1079-
if (!subjectRepr || !subjectRepr->getNameRef().isSimpleName(ctx.Id_Self))
1080-
return;
1081-
1082-
auto req = resolveRequirement(GC, reqIdx);
1083-
1084-
if (!req || req->getKind() != RequirementKind::Conformance)
1085-
return;
1086-
1087-
auto constraint = req->getSecondType();
1088-
1089-
if (isTarget(constraint))
1090-
result.positive.setIfUnset(Kind::Explicit, constraintRepr->getLoc());
1091-
1092-
if (isInverseTarget(constraint))
1093-
result.inverse.setIfUnset(Kind::Explicit, constraintRepr->getLoc());
1094-
};
1095-
10961067
/// MARK: procedure for determining if a nominal is marked with ~TARGET.
10971068

1098-
if (auto *nominal = dyn_cast<NominalTypeDecl>(decl)) {
1099-
// Claim that the tuple decl has an inferred ~TARGET marking.
1100-
if (isa<BuiltinTupleDecl>(nominal))
1101-
return InverseMarking::forInverse(InverseMarking::Kind::Inferred);
1102-
1103-
if (!isa<ProtocolDecl>(nominal)) {
1104-
// Handle non-protocol nominals specially because they infer a ~TARGET
1105-
// based on their generic parameters.
1106-
auto result = searchInheritanceClause(nominal->getInherited());
1107-
result.inverse.setIfUnset(hasInferredInverseTarget(nominal));
1108-
return result;
1109-
}
1110-
}
1111-
1112-
1113-
/// MARK: procedure for handling other TypeDecls
1114-
1115-
// Check inheritance clause.
1116-
auto result = searchInheritanceClause(decl->getInherited());
1069+
auto *nominal = dyn_cast<NominalTypeDecl>(decl);
1070+
if (!nominal)
1071+
return InverseMarking::forInverse(Kind::None);
11171072

1118-
// Check the where clause for markings that refer to this decl, if this
1119-
// TypeDecl has a where-clause at all.
1120-
if (auto *proto = dyn_cast<ProtocolDecl>(decl)) {
1121-
if (auto whereClause = proto->getTrailingWhereClause()) {
1122-
auto requirements = whereClause->getRequirements();
1123-
for (unsigned i : indices(requirements))
1124-
whereClauseVisitor(proto, i, requirements[i], result);
1125-
}
1126-
}
1073+
// Claim that the tuple decl has an inferred ~TARGET marking.
1074+
if (isa<BuiltinTupleDecl>(nominal))
1075+
return InverseMarking::forInverse(InverseMarking::Kind::Inferred);
11271076

1077+
// Handle non-protocol nominals specially because they infer a ~TARGET
1078+
// based on their generic parameters.
1079+
auto result = searchInheritanceClause(nominal->getInherited());
1080+
result.inverse.setIfUnset(hasInferredInverseTarget(nominal));
11281081
return result;
11291082
}
11301083

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,15 +2033,16 @@ static void checkProtocolRefinementRequirements(ProtocolDecl *proto) {
20332033
if (EnabledNoncopyableGenerics) {
20342034
if (auto kp = otherProto->getKnownProtocolKind()) {
20352035
if (auto ip = getInvertibleProtocolKind(*kp)) {
2036-
auto inverse = proto->getMarking(*ip).getInverse();
2037-
if (!inverse.isPresent())
2036+
bool hasInverse;
2037+
SourceLoc inverseLoc;
2038+
2039+
std::tie(hasInverse, inverseLoc) = proto->hasInverseMarking(*ip);
2040+
if (!hasInverse)
20382041
continue; // no ~IP annotation
20392042

20402043
auto &Diags = proto->getASTContext().Diags;
2041-
Diags.diagnose(inverse.getLoc(),
2042-
diag::inverse_generic_but_also_conforms,
2043-
proto->getSelfInterfaceType(),
2044-
getProtocolName(*kp));
2044+
Diags.diagnose(inverseLoc, diag::inverse_generic_but_also_conforms,
2045+
proto->getSelfInterfaceType(), getProtocolName(*kp));
20452046
continue;
20462047
}
20472048
}

0 commit comments

Comments
 (0)