Skip to content

Commit 68b49b6

Browse files
committed
[AST] NonCopyableGenerics: Don't resolve requirements in NominalTypeDecl::hasInverseMarking
TypeRepr for the subject should be already bound to a generic type declaration, so there is no need to resolve the requirement to check that.
1 parent 15b79c5 commit 68b49b6

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

lib/AST/Decl.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6726,21 +6726,6 @@ NominalTypeDecl::hasInverseMarking(InvertibleProtocolKind target) const {
67266726
return false;
67276727
};
67286728

6729-
auto resolveRequirement = [&](unsigned reqIdx) -> std::optional<Requirement> {
6730-
WhereClauseOwner owner(const_cast<NominalTypeDecl *>(this));
6731-
auto req = ctx.evaluator(
6732-
RequirementRequest{owner, reqIdx, TypeResolutionStage::Structural},
6733-
[&]() {
6734-
return Requirement(RequirementKind::SameType, ErrorType::get(ctx),
6735-
ErrorType::get(ctx));
6736-
});
6737-
6738-
if (req.hasError())
6739-
return std::nullopt;
6740-
6741-
return req;
6742-
};
6743-
67446729
llvm::SmallSet<GenericTypeParamDecl *, 4> params;
67456730

67466731
// Scan the inheritance clauses of generic parameters only for an inverse.
@@ -6765,28 +6750,23 @@ NominalTypeDecl::hasInverseMarking(InvertibleProtocolKind target) const {
67656750
if (requirementRepr.getKind() != RequirementReprKind::TypeConstraint)
67666751
continue;
67676752

6768-
auto *constraintRepr =
6769-
dyn_cast<InverseTypeRepr>(requirementRepr.getConstraintRepr());
6770-
if (!constraintRepr || constraintRepr->isInvalid())
6771-
continue;
6772-
6773-
auto req = resolveRequirement(i);
6774-
if (!req)
6775-
continue;
6753+
auto *subjectRepr =
6754+
dyn_cast<IdentTypeRepr>(requirementRepr.getSubjectRepr());
67766755

6777-
if (req->getKind() != RequirementKind::Conformance)
6756+
if (!(subjectRepr && subjectRepr->isBound()))
67786757
continue;
67796758

6780-
auto subject = req->getFirstType();
6781-
if (!subject->isTypeParameter())
6759+
auto *subjectGP =
6760+
dyn_cast<GenericTypeParamDecl>(subjectRepr->getBoundDecl());
6761+
if (!subjectGP || !params.contains(subjectGP))
67826762
continue;
67836763

6784-
// Skip outer params and implicit ones.
6785-
auto *param = subject->getRootGenericParam()->getDecl();
6786-
if (!param || !params.contains(param))
6764+
auto *constraintRepr =
6765+
dyn_cast<InverseTypeRepr>(requirementRepr.getConstraintRepr());
6766+
if (!constraintRepr || constraintRepr->isInvalid())
67876767
continue;
67886768

6789-
if (isInverseTarget(req->getSecondType()))
6769+
if (constraintRepr->isInverseOf(target, getDeclContext()))
67906770
return InverseMarking::Mark(InverseMarking::Kind::Inferred,
67916771
constraintRepr->getLoc());
67926772
}

0 commit comments

Comments
 (0)