@@ -1877,7 +1877,8 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
1877
1877
auto &CG = cs.getConstraintGraph();
1878
1878
1879
1879
auto isTransferableConformance = [&typeVar](Constraint *constraint) {
1880
- if (constraint->getKind() != ConstraintKind::ConformsTo)
1880
+ if (constraint->getKind() != ConstraintKind::ConformsTo &&
1881
+ constraint->getKind() != ConstraintKind::NonisolatedConformsTo)
1881
1882
return false;
1882
1883
1883
1884
auto requirementTy = constraint->getFirstType();
@@ -2167,6 +2168,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
2167
2168
case ConstraintKind::BindOverload:
2168
2169
case ConstraintKind::CheckedCast:
2169
2170
case ConstraintKind::SubclassOf:
2171
+ case ConstraintKind::NonisolatedConformsTo:
2170
2172
case ConstraintKind::ConformsTo:
2171
2173
case ConstraintKind::TransitivelyConformsTo:
2172
2174
case ConstraintKind::Defaultable:
@@ -2530,6 +2532,7 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
2530
2532
case ConstraintKind::BindOverload:
2531
2533
case ConstraintKind::CheckedCast:
2532
2534
case ConstraintKind::SubclassOf:
2535
+ case ConstraintKind::NonisolatedConformsTo:
2533
2536
case ConstraintKind::ConformsTo:
2534
2537
case ConstraintKind::TransitivelyConformsTo:
2535
2538
case ConstraintKind::Defaultable:
@@ -3220,6 +3223,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
3220
3223
case ConstraintKind::BindOverload:
3221
3224
case ConstraintKind::CheckedCast:
3222
3225
case ConstraintKind::SubclassOf:
3226
+ case ConstraintKind::NonisolatedConformsTo:
3223
3227
case ConstraintKind::ConformsTo:
3224
3228
case ConstraintKind::TransitivelyConformsTo:
3225
3229
case ConstraintKind::Defaultable:
@@ -4100,7 +4104,8 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
4100
4104
4101
4105
if (auto layoutConstraint = layout.getLayoutConstraint()) {
4102
4106
if (layoutConstraint->isClass()) {
4103
- if (kind == ConstraintKind::ConformsTo) {
4107
+ if (kind == ConstraintKind::ConformsTo ||
4108
+ kind == ConstraintKind::NonisolatedConformsTo) {
4104
4109
if (!type1->satisfiesClassConstraint()) {
4105
4110
if (shouldAttemptFixes()) {
4106
4111
if (auto last = locator.last()) {
@@ -7170,6 +7175,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
7170
7175
case ConstraintKind::BridgingConversion:
7171
7176
case ConstraintKind::CheckedCast:
7172
7177
case ConstraintKind::SubclassOf:
7178
+ case ConstraintKind::NonisolatedConformsTo:
7173
7179
case ConstraintKind::ConformsTo:
7174
7180
case ConstraintKind::TransitivelyConformsTo:
7175
7181
case ConstraintKind::Defaultable:
@@ -8525,6 +8531,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8525
8531
locator, flags);
8526
8532
}
8527
8533
8534
+ auto conformsToSubKind = (kind == ConstraintKind::NonisolatedConformsTo)
8535
+ ? kind
8536
+ : ConstraintKind::ConformsTo;
8537
+
8528
8538
// Dig out the fixed type to which this type refers.
8529
8539
type = getFixedTypeRecursive(type, flags, /*wantRValue=*/true);
8530
8540
@@ -8538,11 +8548,11 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8538
8548
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
8539
8549
auto patternLoc =
8540
8550
locator.withPathElement(ConstraintLocator::PackExpansionPattern);
8541
- addConstraint(ConstraintKind::ConformsTo ,
8551
+ addConstraint(conformsToSubKind ,
8542
8552
packExpansionType->getPatternType(), protocol,
8543
8553
patternLoc);
8544
8554
} else {
8545
- addConstraint(ConstraintKind::ConformsTo , eltType, protocol,
8555
+ addConstraint(conformsToSubKind , eltType, protocol,
8546
8556
locator.withPathElement(LocatorPathElt::PackElement(i)));
8547
8557
}
8548
8558
}
@@ -8607,6 +8617,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8607
8617
if (type->isTypeVariableOrMember())
8608
8618
return formUnsolved();
8609
8619
8620
+ auto conformsToSubKind = kind;
8621
+ if (kind != ConstraintKind::NonisolatedConformsTo)
8622
+ conformsToSubKind = ConstraintKind::ConformsTo;
8623
+
8610
8624
// ConformsTo constraints are generated when opening a generic
8611
8625
// signature with a RequirementKind::Conformance requirement, so
8612
8626
// we must handle pack types on the left by splitting up into
@@ -8617,12 +8631,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8617
8631
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
8618
8632
auto patternLoc =
8619
8633
locator.withPathElement(ConstraintLocator::PackExpansionPattern);
8620
- addConstraint(ConstraintKind::ConformsTo ,
8634
+ addConstraint(conformsToSubKind ,
8621
8635
packExpansionType->getPatternType(),
8622
8636
protocol->getDeclaredInterfaceType(),
8623
8637
patternLoc);
8624
8638
} else {
8625
- addConstraint(ConstraintKind::ConformsTo , eltType,
8639
+ addConstraint(conformsToSubKind , eltType,
8626
8640
protocol->getDeclaredInterfaceType(),
8627
8641
locator.withPathElement(LocatorPathElt::PackElement(i)));
8628
8642
}
@@ -8634,7 +8648,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8634
8648
// We sometimes get a pack expansion type here.
8635
8649
if (auto *expansionType = type->getAs<PackExpansionType>()) {
8636
8650
addConstraint(
8637
- ConstraintKind::ConformsTo , expansionType->getPatternType(),
8651
+ conformsToSubKind , expansionType->getPatternType(),
8638
8652
protocol->getDeclaredInterfaceType(),
8639
8653
locator.withPathElement(LocatorPathElt::PackExpansionPattern()));
8640
8654
@@ -8658,6 +8672,27 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8658
8672
if (numMissing > 0)
8659
8673
increaseScore(SK_MissingSynthesizableConformance, locator, numMissing);
8660
8674
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
+
8661
8696
// This conformance may be conditional, in which case we need to consider
8662
8697
// those requirements as constraints too.
8663
8698
if (conformance.isConcrete()) {
@@ -8670,7 +8705,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8670
8705
addConstraint(
8671
8706
req, getConstraintLocator(conformanceLoc,
8672
8707
LocatorPathElt::ConditionalRequirement(
8673
- index++, req.getKind())));
8708
+ index++, req.getKind())),
8709
+ /*isFavored=*/false, kind == ConstraintKind::NonisolatedConformsTo);
8674
8710
}
8675
8711
}
8676
8712
@@ -8688,6 +8724,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8688
8724
return recordConformance(conformance);
8689
8725
}
8690
8726
} break;
8727
+ case ConstraintKind::NonisolatedConformsTo:
8691
8728
case ConstraintKind::ConformsTo:
8692
8729
case ConstraintKind::LiteralConformsTo: {
8693
8730
// If existential type is used as a for-in sequence, let's open it
@@ -8996,7 +9033,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8996
9033
8997
9034
// Conformance constraint that is introduced by an implicit conversion
8998
9035
// for example to `AnyHashable`.
8999
- if (kind == ConstraintKind::ConformsTo &&
9036
+ if ((kind == ConstraintKind::ConformsTo ||
9037
+ kind == ConstraintKind::NonisolatedConformsTo) &&
9000
9038
loc->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
9001
9039
auto *fix = AllowArgumentMismatch::create(*this, type, protocolTy, loc);
9002
9040
return recordFix(fix, /*impact=*/2) ? SolutionKind::Error
@@ -15731,6 +15769,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
15731
15769
case FixKind::IgnoreOutOfPlaceThenStmt:
15732
15770
case FixKind::IgnoreMissingEachKeyword:
15733
15771
case FixKind::AllowInlineArrayLiteralCountMismatch:
15772
+ case FixKind::IgnoreIsolatedConformance:
15734
15773
llvm_unreachable("handled elsewhere");
15735
15774
}
15736
15775
@@ -15780,6 +15819,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
15780
15819
case ConstraintKind::SubclassOf:
15781
15820
return simplifySubclassOfConstraint(first, second, locator, subflags);
15782
15821
15822
+ case ConstraintKind::NonisolatedConformsTo:
15783
15823
case ConstraintKind::ConformsTo:
15784
15824
case ConstraintKind::LiteralConformsTo:
15785
15825
return simplifyConformsToConstraint(first, second, kind, locator,
@@ -15992,7 +16032,8 @@ ConstraintSystem::addKeyPathConstraint(
15992
16032
15993
16033
void ConstraintSystem::addConstraint(Requirement req,
15994
16034
ConstraintLocatorBuilder locator,
15995
- bool isFavored) {
16035
+ bool isFavored,
16036
+ bool prohibitNonisolatedConformance) {
15996
16037
bool conformsToAnyObject = false;
15997
16038
std::optional<ConstraintKind> kind;
15998
16039
switch (req.getKind()) {
@@ -16005,7 +16046,9 @@ void ConstraintSystem::addConstraint(Requirement req,
16005
16046
}
16006
16047
16007
16048
case RequirementKind::Conformance:
16008
- kind = ConstraintKind::ConformsTo;
16049
+ kind = prohibitNonisolatedConformance
16050
+ ? ConstraintKind::NonisolatedConformsTo
16051
+ : ConstraintKind::ConformsTo;
16009
16052
break;
16010
16053
case RequirementKind::Superclass: {
16011
16054
// FIXME: Should always use ConstraintKind::SubclassOf, but that breaks
@@ -16348,6 +16391,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
16348
16391
constraint.getLocator(),
16349
16392
/*flags*/ std::nullopt);
16350
16393
16394
+ case ConstraintKind::NonisolatedConformsTo:
16351
16395
case ConstraintKind::ConformsTo:
16352
16396
case ConstraintKind::LiteralConformsTo:
16353
16397
return simplifyConformsToConstraint(
0 commit comments