@@ -911,176 +911,6 @@ IsFinalRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
911911 return explicitFinalAttr;
912912}
913913
914- InverseMarking
915- InvertibleAnnotationRequest::evaluate (Evaluator &evaluator,
916- TypeDecl *decl,
917- InvertibleProtocolKind ip) const {
918- assert (!isa<ProtocolDecl>(decl));
919-
920- auto &ctx = decl->getASTContext ();
921- const auto TARGET = ip;
922- using Kind = InverseMarking::Kind;
923- using Mark = InverseMarking::Mark;
924-
925- switch (TARGET) {
926- case InvertibleProtocolKind::Copyable:
927- // Handle the legacy '@_moveOnly' for types they can validly appear.
928- // TypeCheckAttr handles the illegal situations for us.
929- if (auto attr = decl->getAttrs ().getAttribute <MoveOnlyAttr>())
930- if (isa<StructDecl, EnumDecl, ClassDecl>(decl))
931- return InverseMarking::forInverse (Kind::LegacyExplicit,
932- attr->getLocation ());
933- break ;
934-
935- case InvertibleProtocolKind::Escapable:
936- // Handle the legacy '@_nonEscapable' attribute
937- if (auto attr = decl->getAttrs ().getAttribute <NonEscapableAttr>()) {
938- assert ((isa<ClassDecl, StructDecl, EnumDecl>(decl)));
939- return InverseMarking::forInverse (Kind::LegacyExplicit,
940- attr->getLocation ());
941- }
942- break ;
943- }
944-
945- // Legacy support stops here.
946- if (!ctx.LangOpts .hasFeature (Feature::NoncopyableGenerics))
947- return InverseMarking::forInverse (Kind::None);
948-
949- // / The invertible protocol being targeted by this annotation request.
950-
951- std::function<bool (Type)> isTarget = [&](Type t) -> bool {
952- if (auto kp = t->getKnownProtocol ()) {
953- if (auto ip = getInvertibleProtocolKind (*kp))
954- return *ip == TARGET;
955- } else if (auto pct = t->getAs <ProtocolCompositionType>()) {
956- return llvm::any_of (pct->getMembers (), isTarget);
957- }
958-
959- return false ;
960- };
961-
962- auto isInverseTarget = [&](Type t) -> bool {
963- if (auto pct = t->getAs <ProtocolCompositionType>())
964- return pct->getInverses ().contains (TARGET);
965-
966- return false ;
967- };
968-
969- auto resolveRequirement = [&](GenericContext *GC,
970- unsigned reqIdx) -> std::optional<Requirement> {
971- auto req = evaluator (
972- RequirementRequest{GC, reqIdx, TypeResolutionStage::Structural}, [&]() {
973- return Requirement (RequirementKind::SameType, ErrorType::get (ctx),
974- ErrorType::get (ctx));
975- });
976-
977- if (req.hasError ())
978- return std::nullopt ;
979-
980- return req;
981- };
982-
983- // Function to check an inheritance clause for the ~IP marking.
984- auto searchInheritanceClause =
985- [&](InheritedTypes inherited) -> InverseMarking {
986- InverseMarking result;
987-
988- for (size_t i = 0 ; i < inherited.size (); i++) {
989- auto type = inherited.getResolvedType (i, TypeResolutionStage::Structural);
990- if (!type)
991- continue ;
992-
993- SourceLoc loc;
994- if (auto *repr = inherited.getTypeRepr (i))
995- loc = repr->getLoc ();
996-
997- if (isTarget (type))
998- result.positive .setIfUnset (Kind::Explicit, loc);
999-
1000- if (isInverseTarget (type))
1001- result.inverse .setIfUnset (Kind::Explicit, loc);
1002- }
1003-
1004- return result;
1005- };
1006-
1007- // Function to check the generic parameters for an explicit ~TARGET marking
1008- // which would result in an Inferred ~TARGET marking for this context.
1009- auto hasInferredInverseTarget = [&](GenericContext *genCtx) -> Mark {
1010- auto *gpList = genCtx->getParsedGenericParams ();
1011- if (!gpList)
1012- return InverseMarking::Mark ();
1013-
1014- llvm::SmallSet<GenericTypeParamDecl*, 4 > params;
1015-
1016- // Scan the inheritance clauses of generic parameters only for an inverse.
1017- for (GenericTypeParamDecl *param : gpList->getParams ()) {
1018- auto clause = searchInheritanceClause (param->getInherited ());
1019- if (auto &inverse = clause.getInverse ())
1020- return inverse.with (Kind::Inferred);
1021-
1022- params.insert (param);
1023- }
1024-
1025- Mark result;
1026- // Next, scan the where clause and return the result.
1027- auto whereClause = genCtx->getTrailingWhereClause ();
1028- if (!whereClause)
1029- return result;
1030-
1031- auto requirements = whereClause->getRequirements ();
1032- for (unsigned i : indices (requirements)) {
1033- auto requirementRepr = requirements[i];
1034- if (requirementRepr.getKind () != RequirementReprKind::TypeConstraint)
1035- continue ;
1036-
1037- auto *constraintRepr =
1038- dyn_cast<InverseTypeRepr>(requirementRepr.getConstraintRepr ());
1039- if (!constraintRepr || constraintRepr->isInvalid ())
1040- continue ;
1041-
1042- auto req = resolveRequirement (genCtx, i);
1043- if (!req)
1044- continue ;
1045-
1046- if (req->getKind () != RequirementKind::Conformance)
1047- continue ;
1048-
1049- auto subject = req->getFirstType ();
1050- if (!subject->isTypeParameter ())
1051- continue ;
1052-
1053- // Skip outer params and implicit ones.
1054- auto *param = subject->getRootGenericParam ()->getDecl ();
1055- if (!param || !params.contains (param))
1056- continue ;
1057-
1058- if (isInverseTarget (req->getSecondType ())) {
1059- result.set (Kind::Inferred, constraintRepr->getLoc ());
1060- break ;
1061- }
1062- }
1063-
1064- return result;
1065- };
1066-
1067- // / MARK: procedure for determining if a nominal is marked with ~TARGET.
1068-
1069- auto *nominal = dyn_cast<NominalTypeDecl>(decl);
1070- if (!nominal)
1071- return InverseMarking::forInverse (Kind::None);
1072-
1073- // Claim that the tuple decl has an inferred ~TARGET marking.
1074- if (isa<BuiltinTupleDecl>(nominal))
1075- return InverseMarking::forInverse (InverseMarking::Kind::Inferred);
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));
1081- return result;
1082- }
1083-
1084914bool
1085915IsStaticRequest::evaluate (Evaluator &evaluator, FuncDecl *decl) const {
1086916 if (auto *accessor = dyn_cast<AccessorDecl>(decl))
0 commit comments