@@ -915,6 +915,8 @@ InverseMarking
915
915
InvertibleAnnotationRequest::evaluate (Evaluator &evaluator,
916
916
TypeDecl *decl,
917
917
InvertibleProtocolKind ip) const {
918
+ assert (!isa<ProtocolDecl>(decl));
919
+
918
920
auto &ctx = decl->getASTContext ();
919
921
const auto TARGET = ip;
920
922
using Kind = InverseMarking::Kind;
@@ -1062,69 +1064,20 @@ InvertibleAnnotationRequest::evaluate(Evaluator &evaluator,
1062
1064
return result;
1063
1065
};
1064
1066
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
-
1096
1067
// / MARK: procedure for determining if a nominal is marked with ~TARGET.
1097
1068
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);
1117
1072
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);
1127
1076
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));
1128
1081
return result;
1129
1082
}
1130
1083
0 commit comments