Skip to content

Commit 937d9d0

Browse files
committed
[AST] Route hasInverse through hasInverseMarking and simplify it
1 parent 355e02d commit 937d9d0

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,9 +3368,8 @@ static bool usesFeatureFlowSensitiveConcurrencyCaptures(Decl *decl) {
33683368
/// \param isRelevantInverse the function used to inspect a mark corresponding
33693369
/// to an inverse to determine whether it "has" an inverse that we care about.
33703370
static bool hasInverse(
3371-
Decl *decl,
3372-
InvertibleProtocolKind ip,
3373-
std::function<bool(InverseMarking const&)> isRelevantInverse) {
3371+
Decl *decl, InvertibleProtocolKind ip,
3372+
std::function<bool(InverseMarking::Mark const &)> isRelevantInverse) {
33743373

33753374
auto getTypeDecl = [](Type type) -> TypeDecl* {
33763375
if (auto genericTy = type->getAnyGeneric())
@@ -3382,38 +3381,22 @@ static bool hasInverse(
33823381

33833382
if (auto *extension = dyn_cast<ExtensionDecl>(decl)) {
33843383
if (auto *nominal = extension->getSelfNominalTypeDecl())
3385-
if (isRelevantInverse(nominal->getMarking(ip)))
3386-
return true;
3384+
return hasInverse(nominal, ip, isRelevantInverse);
33873385
}
33883386

3389-
if (auto typeDecl = dyn_cast<TypeDecl>(decl)) {
3390-
if (isRelevantInverse(typeDecl->getMarking(ip)))
3391-
return true;
3392-
3393-
// Check the protocol's associated types too.
3394-
if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
3395-
auto hasInverse =
3396-
llvm::any_of(proto->getAssociatedTypeMembers(),
3397-
[&](AssociatedTypeDecl *assocTyDecl) {
3398-
return isRelevantInverse(assocTyDecl->getMarking(ip));
3399-
});
3400-
if (hasInverse)
3401-
return true;
3402-
}
3403-
}
3387+
if (auto *TD = dyn_cast<TypeDecl>(decl))
3388+
return isRelevantInverse(TD->hasInverseMarking(ip));
34043389

34053390
if (auto value = dyn_cast<ValueDecl>(decl)) {
34063391
// Check for noncopyable types in the types of this declaration.
34073392
if (Type type = value->getInterfaceType()) {
3408-
bool hasInverse = type.findIf([&](Type type) {
3393+
bool foundInverse = type.findIf([&](Type type) -> bool {
34093394
if (auto *typeDecl = getTypeDecl(type))
3410-
if (isRelevantInverse(typeDecl->getMarking(ip)))
3411-
return true;
3412-
3395+
return hasInverse(typeDecl, ip, isRelevantInverse);
34133396
return false;
34143397
});
34153398

3416-
if (hasInverse)
3399+
if (foundInverse)
34173400
return true;
34183401
}
34193402
}
@@ -3424,8 +3407,8 @@ static bool hasInverse(
34243407
static bool usesFeatureMoveOnly(Decl *decl) {
34253408
return hasInverse(decl, InvertibleProtocolKind::Copyable,
34263409
[](auto &marking) -> bool {
3427-
return marking.getInverse().is(InverseMarking::Kind::LegacyExplicit);
3428-
});
3410+
return marking.is(InverseMarking::Kind::LegacyExplicit);
3411+
});
34293412
}
34303413

34313414
static bool usesFeatureLazyImmediate(Decl *D) { return false; }
@@ -3469,8 +3452,8 @@ static bool usesFeatureMoveOnlyPartialReinitialization(Decl *decl) {
34693452
}
34703453

34713454
static bool usesFeatureNoncopyableGenerics(Decl *decl) {
3472-
auto checkMarking = [](auto &marking) -> bool {
3473-
switch (marking.getInverse().getKind()) {
3455+
auto checkInverseMarking = [](auto &marking) -> bool {
3456+
switch (marking.getKind()) {
34743457
case InverseMarking::Kind::None:
34753458
case InverseMarking::Kind::LegacyExplicit: // covered by other checks.
34763459
return false;
@@ -3481,8 +3464,10 @@ static bool usesFeatureNoncopyableGenerics(Decl *decl) {
34813464
}
34823465
};
34833466

3484-
return hasInverse(decl, InvertibleProtocolKind::Copyable, checkMarking)
3485-
|| hasInverse(decl, InvertibleProtocolKind::Escapable, checkMarking);
3467+
return hasInverse(decl, InvertibleProtocolKind::Copyable,
3468+
checkInverseMarking) ||
3469+
hasInverse(decl, InvertibleProtocolKind::Escapable,
3470+
checkInverseMarking);
34863471
}
34873472

34883473
static bool usesFeatureOneWayClosureParameters(Decl *decl) {

0 commit comments

Comments
 (0)