@@ -1877,7 +1877,8 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
18771877 auto &CG = cs.getConstraintGraph();
18781878
18791879 auto isTransferableConformance = [&typeVar](Constraint *constraint) {
1880- if (constraint->getKind() != ConstraintKind::ConformsTo)
1880+ if (constraint->getKind() != ConstraintKind::ConformsTo &&
1881+ constraint->getKind() != ConstraintKind::NonisolatedConformsTo)
18811882 return false;
18821883
18831884 auto requirementTy = constraint->getFirstType();
@@ -2167,6 +2168,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
21672168 case ConstraintKind::BindOverload:
21682169 case ConstraintKind::CheckedCast:
21692170 case ConstraintKind::SubclassOf:
2171+ case ConstraintKind::NonisolatedConformsTo:
21702172 case ConstraintKind::ConformsTo:
21712173 case ConstraintKind::TransitivelyConformsTo:
21722174 case ConstraintKind::Defaultable:
@@ -2530,6 +2532,7 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
25302532 case ConstraintKind::BindOverload:
25312533 case ConstraintKind::CheckedCast:
25322534 case ConstraintKind::SubclassOf:
2535+ case ConstraintKind::NonisolatedConformsTo:
25332536 case ConstraintKind::ConformsTo:
25342537 case ConstraintKind::TransitivelyConformsTo:
25352538 case ConstraintKind::Defaultable:
@@ -3220,6 +3223,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
32203223 case ConstraintKind::BindOverload:
32213224 case ConstraintKind::CheckedCast:
32223225 case ConstraintKind::SubclassOf:
3226+ case ConstraintKind::NonisolatedConformsTo:
32233227 case ConstraintKind::ConformsTo:
32243228 case ConstraintKind::TransitivelyConformsTo:
32253229 case ConstraintKind::Defaultable:
@@ -4100,7 +4104,8 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
41004104
41014105 if (auto layoutConstraint = layout.getLayoutConstraint()) {
41024106 if (layoutConstraint->isClass()) {
4103- if (kind == ConstraintKind::ConformsTo) {
4107+ if (kind == ConstraintKind::ConformsTo ||
4108+ kind == ConstraintKind::NonisolatedConformsTo) {
41044109 if (!type1->satisfiesClassConstraint()) {
41054110 if (shouldAttemptFixes()) {
41064111 if (auto last = locator.last()) {
@@ -7170,6 +7175,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
71707175 case ConstraintKind::BridgingConversion:
71717176 case ConstraintKind::CheckedCast:
71727177 case ConstraintKind::SubclassOf:
7178+ case ConstraintKind::NonisolatedConformsTo:
71737179 case ConstraintKind::ConformsTo:
71747180 case ConstraintKind::TransitivelyConformsTo:
71757181 case ConstraintKind::Defaultable:
@@ -8525,6 +8531,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
85258531 locator, flags);
85268532 }
85278533
8534+ auto conformsToSubKind = (kind == ConstraintKind::NonisolatedConformsTo)
8535+ ? kind
8536+ : ConstraintKind::ConformsTo;
8537+
85288538 // Dig out the fixed type to which this type refers.
85298539 type = getFixedTypeRecursive(type, flags, /*wantRValue=*/true);
85308540
@@ -8538,11 +8548,11 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
85388548 if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
85398549 auto patternLoc =
85408550 locator.withPathElement(ConstraintLocator::PackExpansionPattern);
8541- addConstraint(ConstraintKind::ConformsTo ,
8551+ addConstraint(conformsToSubKind ,
85428552 packExpansionType->getPatternType(), protocol,
85438553 patternLoc);
85448554 } else {
8545- addConstraint(ConstraintKind::ConformsTo , eltType, protocol,
8555+ addConstraint(conformsToSubKind , eltType, protocol,
85468556 locator.withPathElement(LocatorPathElt::PackElement(i)));
85478557 }
85488558 }
@@ -8607,6 +8617,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
86078617 if (type->isTypeVariableOrMember())
86088618 return formUnsolved();
86098619
8620+ auto conformsToSubKind = kind;
8621+ if (kind != ConstraintKind::NonisolatedConformsTo)
8622+ conformsToSubKind = ConstraintKind::ConformsTo;
8623+
86108624 // ConformsTo constraints are generated when opening a generic
86118625 // signature with a RequirementKind::Conformance requirement, so
86128626 // we must handle pack types on the left by splitting up into
@@ -8617,12 +8631,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
86178631 if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
86188632 auto patternLoc =
86198633 locator.withPathElement(ConstraintLocator::PackExpansionPattern);
8620- addConstraint(ConstraintKind::ConformsTo ,
8634+ addConstraint(conformsToSubKind ,
86218635 packExpansionType->getPatternType(),
86228636 protocol->getDeclaredInterfaceType(),
86238637 patternLoc);
86248638 } else {
8625- addConstraint(ConstraintKind::ConformsTo , eltType,
8639+ addConstraint(conformsToSubKind , eltType,
86268640 protocol->getDeclaredInterfaceType(),
86278641 locator.withPathElement(LocatorPathElt::PackElement(i)));
86288642 }
@@ -8634,7 +8648,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
86348648 // We sometimes get a pack expansion type here.
86358649 if (auto *expansionType = type->getAs<PackExpansionType>()) {
86368650 addConstraint(
8637- ConstraintKind::ConformsTo , expansionType->getPatternType(),
8651+ conformsToSubKind , expansionType->getPatternType(),
86388652 protocol->getDeclaredInterfaceType(),
86398653 locator.withPathElement(LocatorPathElt::PackExpansionPattern()));
86408654
@@ -8658,6 +8672,27 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
86588672 if (numMissing > 0)
86598673 increaseScore(SK_MissingSynthesizableConformance, locator, numMissing);
86608674
8675+ // If we aren't allowed to have an isolated conformance, check for any
8676+ // isolated conformances here.
8677+ if (kind == ConstraintKind::NonisolatedConformsTo &&
8678+ !conformance.getRequirement()->isMarkerProtocol()) {
8679+ // Grab the first isolated conformance, if there is one.
8680+ ProtocolConformance *isolatedConformance = nullptr;
8681+ conformance.forEachIsolatedConformance([&](ProtocolConformance *conf) {
8682+ if (!isolatedConformance)
8683+ isolatedConformance = conf;
8684+ return true;
8685+ });
8686+
8687+ if (isolatedConformance) {
8688+ auto fix = IgnoreIsolatedConformance::create(
8689+ *this, getConstraintLocator(locator), isolatedConformance);
8690+ if (recordFix(fix)) {
8691+ return SolutionKind::Error;
8692+ }
8693+ }
8694+ }
8695+
86618696 // This conformance may be conditional, in which case we need to consider
86628697 // those requirements as constraints too.
86638698 if (conformance.isConcrete()) {
@@ -8670,7 +8705,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
86708705 addConstraint(
86718706 req, getConstraintLocator(conformanceLoc,
86728707 LocatorPathElt::ConditionalRequirement(
8673- index++, req.getKind())));
8708+ index++, req.getKind())),
8709+ /*isFavored=*/false, kind == ConstraintKind::NonisolatedConformsTo);
86748710 }
86758711 }
86768712
@@ -8688,6 +8724,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
86888724 return recordConformance(conformance);
86898725 }
86908726 } break;
8727+ case ConstraintKind::NonisolatedConformsTo:
86918728 case ConstraintKind::ConformsTo:
86928729 case ConstraintKind::LiteralConformsTo: {
86938730 // If existential type is used as a for-in sequence, let's open it
@@ -8996,7 +9033,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
89969033
89979034 // Conformance constraint that is introduced by an implicit conversion
89989035 // for example to `AnyHashable`.
8999- if (kind == ConstraintKind::ConformsTo &&
9036+ if ((kind == ConstraintKind::ConformsTo ||
9037+ kind == ConstraintKind::NonisolatedConformsTo) &&
90009038 loc->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
90019039 auto *fix = AllowArgumentMismatch::create(*this, type, protocolTy, loc);
90029040 return recordFix(fix, /*impact=*/2) ? SolutionKind::Error
@@ -15731,6 +15769,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1573115769 case FixKind::IgnoreOutOfPlaceThenStmt:
1573215770 case FixKind::IgnoreMissingEachKeyword:
1573315771 case FixKind::AllowInlineArrayLiteralCountMismatch:
15772+ case FixKind::IgnoreIsolatedConformance:
1573415773 llvm_unreachable("handled elsewhere");
1573515774 }
1573615775
@@ -15780,6 +15819,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1578015819 case ConstraintKind::SubclassOf:
1578115820 return simplifySubclassOfConstraint(first, second, locator, subflags);
1578215821
15822+ case ConstraintKind::NonisolatedConformsTo:
1578315823 case ConstraintKind::ConformsTo:
1578415824 case ConstraintKind::LiteralConformsTo:
1578515825 return simplifyConformsToConstraint(first, second, kind, locator,
@@ -15992,7 +16032,8 @@ ConstraintSystem::addKeyPathConstraint(
1599216032
1599316033void ConstraintSystem::addConstraint(Requirement req,
1599416034 ConstraintLocatorBuilder locator,
15995- bool isFavored) {
16035+ bool isFavored,
16036+ bool prohibitNonisolatedConformance) {
1599616037 bool conformsToAnyObject = false;
1599716038 std::optional<ConstraintKind> kind;
1599816039 switch (req.getKind()) {
@@ -16005,7 +16046,9 @@ void ConstraintSystem::addConstraint(Requirement req,
1600516046 }
1600616047
1600716048 case RequirementKind::Conformance:
16008- kind = ConstraintKind::ConformsTo;
16049+ kind = prohibitNonisolatedConformance
16050+ ? ConstraintKind::NonisolatedConformsTo
16051+ : ConstraintKind::ConformsTo;
1600916052 break;
1601016053 case RequirementKind::Superclass: {
1601116054 // FIXME: Should always use ConstraintKind::SubclassOf, but that breaks
@@ -16348,6 +16391,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1634816391 constraint.getLocator(),
1634916392 /*flags*/ std::nullopt);
1635016393
16394+ case ConstraintKind::NonisolatedConformsTo:
1635116395 case ConstraintKind::ConformsTo:
1635216396 case ConstraintKind::LiteralConformsTo:
1635316397 return simplifyConformsToConstraint(
0 commit comments