Skip to content

Commit 15b79c5

Browse files
committed
[AST/Sema] NFC: Remove obsolete getMarking(...) and InvertibleAnnotationRequest
1 parent cc72581 commit 15b79c5

File tree

5 files changed

+0
-207
lines changed

5 files changed

+0
-207
lines changed

include/swift/AST/InverseMarking.h

-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
namespace swift {
2121

22-
class InvertibleAnnotationRequest;
23-
2422
/// Describes the way an inverse and its corresponding positive contraint
2523
/// appears on a TypeDecl, i.e., the way it was marked.
2624
struct InverseMarking {
@@ -91,8 +89,6 @@ struct InverseMarking {
9189
Mark inverse;
9290
Mark positive;
9391

94-
// This friend initializes the marks.
95-
friend InvertibleAnnotationRequest;
9692
public:
9793

9894
// Creates an empty marking.

include/swift/AST/TypeCheckRequests.h

-22
Original file line numberDiff line numberDiff line change
@@ -429,28 +429,6 @@ class IsFinalRequest :
429429
void cacheResult(bool value) const;
430430
};
431431

432-
/// Determine the kind of invertible protocol markings for this declaration,
433-
/// for example, if a conformance to IP or ~IP was written on it in the
434-
/// inheritance clause and/or where clause.
435-
class InvertibleAnnotationRequest
436-
: public SimpleRequest<InvertibleAnnotationRequest,
437-
InverseMarking(TypeDecl *, InvertibleProtocolKind),
438-
RequestFlags::Cached> {
439-
public:
440-
using SimpleRequest::SimpleRequest;
441-
442-
private:
443-
friend SimpleRequest;
444-
445-
// Evaluation.
446-
InverseMarking evaluate(Evaluator &evaluator,
447-
TypeDecl *decl, InvertibleProtocolKind ip) const;
448-
449-
public:
450-
// Caching.
451-
bool isCached() const { return true; }
452-
};
453-
454432
/// Determine whether the given declaration is 'dynamic''.
455433
class IsDynamicRequest :
456434
public SimpleRequest<IsDynamicRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

-3
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ SWIFT_REQUEST(TypeChecker, IsDynamicRequest, bool(ValueDecl *),
217217
SeparatelyCached, NoLocationInfo)
218218
SWIFT_REQUEST(TypeChecker, IsFinalRequest, bool(ValueDecl *), SeparatelyCached,
219219
NoLocationInfo)
220-
SWIFT_REQUEST(TypeChecker, InvertibleAnnotationRequest,
221-
InverseMarking(TypeDecl *, InvertibleProtocolKind),
222-
Cached, NoLocationInfo)
223220
SWIFT_REQUEST(TypeChecker, IsGetterMutatingRequest, bool(AbstractStorageDecl *),
224221
SeparatelyCached, NoLocationInfo)
225222
SWIFT_REQUEST(TypeChecker, IsImplicitlyUnwrappedOptionalRequest,

lib/AST/Decl.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -4909,14 +4909,6 @@ TypeDecl::hasInverseMarking(InvertibleProtocolKind target) const {
49094909
return InverseMarking::Mark(InverseMarking::Kind::None);
49104910
}
49114911

4912-
InverseMarking TypeDecl::getMarking(InvertibleProtocolKind ip) const {
4913-
return evaluateOrDefault(
4914-
getASTContext().evaluator,
4915-
InvertibleAnnotationRequest{const_cast<TypeDecl *>(this), ip},
4916-
InverseMarking::forInverse(InverseMarking::Kind::None)
4917-
);
4918-
}
4919-
49204912
static TypeDecl::CanBeInvertible::Result
49214913
conformanceExists(TypeDecl const *decl, InvertibleProtocolKind ip) {
49224914
auto *proto = decl->getASTContext().getProtocol(getKnownProtocolKind(ip));

lib/Sema/TypeCheckDecl.cpp

-170
Original file line numberDiff line numberDiff line change
@@ -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-
1084914
bool
1085915
IsStaticRequest::evaluate(Evaluator &evaluator, FuncDecl *decl) const {
1086916
if (auto *accessor = dyn_cast<AccessorDecl>(decl))

0 commit comments

Comments
 (0)