@@ -837,7 +837,7 @@ Type ConstraintSystem::openUnboundGenericType(GenericTypeDecl *decl,
837
837
838
838
return result.transform ([&](Type type) {
839
839
if (auto *expansion = dyn_cast<PackExpansionType>(type.getPointer ()))
840
- return openPackExpansionType (expansion, replacements);
840
+ return openPackExpansionType (expansion, replacements, locator );
841
841
return type;
842
842
});
843
843
}
@@ -963,7 +963,8 @@ Type ConstraintSystem::replaceInferableTypesWithTypeVars(
963
963
return type;
964
964
}
965
965
966
- Type ConstraintSystem::openType (Type type, OpenedTypeMap &replacements) {
966
+ Type ConstraintSystem::openType (Type type, OpenedTypeMap &replacements,
967
+ ConstraintLocatorBuilder locator) {
967
968
assert (!type->hasUnboundGenericType ());
968
969
969
970
if (!type->hasTypeParameter ())
@@ -980,14 +981,15 @@ Type ConstraintSystem::openType(Type type, OpenedTypeMap &replacements) {
980
981
if (!elt.hasName () && elt.getType ()->is <PackExpansionType>()) {
981
982
return TupleType::get (
982
983
{openPackExpansionType (
983
- elt.getType ()->castTo <PackExpansionType>(), replacements)},
984
+ elt.getType ()->castTo <PackExpansionType>(), replacements,
985
+ locator)},
984
986
tuple->getASTContext ());
985
987
}
986
988
}
987
989
}
988
990
989
991
if (auto *expansion = type->getAs <PackExpansionType>()) {
990
- return openPackExpansionType (expansion, replacements);
992
+ return openPackExpansionType (expansion, replacements, locator );
991
993
}
992
994
993
995
// Replace a generic type parameter with its corresponding type variable.
@@ -1007,28 +1009,29 @@ Type ConstraintSystem::openType(Type type, OpenedTypeMap &replacements) {
1007
1009
}
1008
1010
1009
1011
Type ConstraintSystem::openPackExpansionType (PackExpansionType *expansion,
1010
- OpenedTypeMap &replacements) {
1011
- auto patternType = openType (expansion->getPatternType (), replacements);
1012
- auto shapeType = openType (expansion->getCountType (), replacements);
1012
+ OpenedTypeMap &replacements,
1013
+ ConstraintLocatorBuilder locator) {
1014
+ auto patternType =
1015
+ openType (expansion->getPatternType (), replacements, locator);
1016
+ auto shapeType = openType (expansion->getCountType (), replacements, locator);
1013
1017
1014
1018
auto openedPackExpansion = PackExpansionType::get (patternType, shapeType);
1015
1019
1016
1020
auto known = OpenedPackExpansionTypes.find (openedPackExpansion);
1017
1021
if (known != OpenedPackExpansionTypes.end ())
1018
1022
return known->second ;
1019
1023
1020
- auto *expansionVar = createTypeVariable (
1021
- getConstraintLocator (
1022
- {}, LocatorPathElt::PackExpansionType (openedPackExpansion)),
1023
- TVO_PackExpansion);
1024
+ auto *expansionLoc = getConstraintLocator (locator. withPathElement (
1025
+ LocatorPathElt::PackExpansionType (openedPackExpansion)));
1026
+
1027
+ auto *expansionVar = createTypeVariable (expansionLoc, TVO_PackExpansion);
1024
1028
1025
1029
// This constraint is important to make sure that pack expansion always
1026
1030
// has a binding and connect pack expansion var to any type variables
1027
1031
// that appear in pattern and shape types.
1028
- addUnsolvedConstraint (Constraint::create (
1029
- *this , ConstraintKind::Defaultable, expansionVar, openedPackExpansion,
1030
- getConstraintLocator (
1031
- {}, LocatorPathElt::PackExpansionType (openedPackExpansion))));
1032
+ addUnsolvedConstraint (Constraint::create (*this , ConstraintKind::Defaultable,
1033
+ expansionVar, openedPackExpansion,
1034
+ expansionLoc));
1032
1035
1033
1036
OpenedPackExpansionTypes[openedPackExpansion] = expansionVar;
1034
1037
return expansionVar;
@@ -1066,7 +1069,7 @@ Type ConstraintSystem::openOpaqueType(OpaqueTypeArchetypeType *opaque,
1066
1069
1067
1070
recordOpenedTypes (opaqueLocatorKey, replacements);
1068
1071
1069
- return openType (opaque->getInterfaceType (), replacements);
1072
+ return openType (opaque->getInterfaceType (), replacements, locator );
1070
1073
}
1071
1074
1072
1075
Type ConstraintSystem::openOpaqueType (Type type, ContextualTypePurpose context,
@@ -1113,12 +1116,14 @@ FunctionType *ConstraintSystem::openFunctionType(
1113
1116
1114
1117
openGenericParameters (outerDC, signature, replacements, locator);
1115
1118
1116
- openGenericRequirements (
1117
- outerDC, signature, /* skipProtocolSelfConstraint=*/ false , locator,
1118
- [&](Type type) -> Type { return openType (type, replacements); });
1119
+ openGenericRequirements (outerDC, signature,
1120
+ /* skipProtocolSelfConstraint=*/ false , locator,
1121
+ [&](Type type) -> Type {
1122
+ return openType (type, replacements, locator);
1123
+ });
1119
1124
1120
1125
funcType = genericFn->substGenericArgs (
1121
- [&](Type type) { return openType (type, replacements); });
1126
+ [&](Type type) { return openType (type, replacements, locator ); });
1122
1127
}
1123
1128
1124
1129
return funcType->castTo <FunctionType>();
@@ -1558,16 +1563,16 @@ static bool isRequirementOrWitness(const ConstraintLocatorBuilder &locator) {
1558
1563
1559
1564
AnyFunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency (
1560
1565
AnyFunctionType *fnType, ValueDecl *decl, DeclContext *dc,
1561
- unsigned numApplies, bool isMainDispatchQueue,
1562
- OpenedTypeMap &replacements ) {
1566
+ unsigned numApplies, bool isMainDispatchQueue, OpenedTypeMap &replacements,
1567
+ ConstraintLocatorBuilder locator ) {
1563
1568
return swift::adjustFunctionTypeForConcurrency (
1564
1569
fnType, decl, dc, numApplies, isMainDispatchQueue,
1565
1570
GetClosureType{*this }, ClosureIsolatedByPreconcurrency{*this },
1566
1571
[&](Type type) {
1567
1572
if (replacements.empty ())
1568
1573
return type;
1569
1574
1570
- return openType (type, replacements);
1575
+ return openType (type, replacements, locator );
1571
1576
});
1572
1577
}
1573
1578
@@ -1642,7 +1647,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1642
1647
if (!isRequirementOrWitness (locator)) {
1643
1648
unsigned numApplies = getNumApplications (value, false , functionRefKind);
1644
1649
openedType = cast<FunctionType>(adjustFunctionTypeForConcurrency (
1645
- origOpenedType, func, useDC, numApplies, false , replacements));
1650
+ origOpenedType, func, useDC, numApplies, false , replacements,
1651
+ locator));
1646
1652
}
1647
1653
1648
1654
// The reference implicitly binds 'self'.
@@ -1668,8 +1674,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1668
1674
unsigned numApplies = getNumApplications (
1669
1675
funcDecl, false , functionRefKind);
1670
1676
openedType = cast<FunctionType>(adjustFunctionTypeForConcurrency (
1671
- origOpenedType->castTo <FunctionType>(), funcDecl, useDC,
1672
- numApplies, false , replacements));
1677
+ origOpenedType->castTo <FunctionType>(), funcDecl, useDC, numApplies,
1678
+ false , replacements, locator ));
1673
1679
}
1674
1680
1675
1681
if (isForCodeCompletion () && openedType->hasError ()) {
@@ -1834,7 +1840,7 @@ void ConstraintSystem::openGeneric(
1834
1840
// Add the requirements as constraints.
1835
1841
openGenericRequirements (
1836
1842
outerDC, sig, /* skipProtocolSelfConstraint=*/ false , locator,
1837
- [&](Type type) { return openType (type, replacements); });
1843
+ [&](Type type) { return openType (type, replacements, locator ); });
1838
1844
}
1839
1845
1840
1846
void ConstraintSystem::openGenericParameters (DeclContext *outerDC,
@@ -2431,9 +2437,8 @@ ConstraintSystem::getTypeOfMemberReference(
2431
2437
openedType = value->getInterfaceType ()->castTo <AnyFunctionType>();
2432
2438
2433
2439
if (auto *genericFn = openedType->getAs <GenericFunctionType>()) {
2434
- openedType = genericFn->substGenericArgs ([&](Type type) {
2435
- return openType (type, replacements);
2436
- });
2440
+ openedType = genericFn->substGenericArgs (
2441
+ [&](Type type) { return openType (type, replacements, locator); });
2437
2442
}
2438
2443
} else {
2439
2444
// For a property, build a type (Self) -> PropType.
@@ -2477,8 +2482,8 @@ ConstraintSystem::getTypeOfMemberReference(
2477
2482
2478
2483
// If the storage is generic, open the self and ref types.
2479
2484
if (genericSig) {
2480
- selfTy = openType (selfTy, replacements);
2481
- refType = openType (refType, replacements);
2485
+ selfTy = openType (selfTy, replacements, locator );
2486
+ refType = openType (refType, replacements, locator );
2482
2487
}
2483
2488
FunctionType::Param selfParam (selfTy, Identifier (), selfFlags);
2484
2489
@@ -2506,7 +2511,7 @@ ConstraintSystem::getTypeOfMemberReference(
2506
2511
getConcreteReplacementForProtocolSelfType (value)) {
2507
2512
// Concrete type replacing `Self` could be generic, so we need
2508
2513
// to make sure that it's opened before use.
2509
- baseOpenedTy = openType (concreteSelf, replacements);
2514
+ baseOpenedTy = openType (concreteSelf, replacements, locator );
2510
2515
baseObjTy = baseOpenedTy;
2511
2516
}
2512
2517
}
@@ -2544,7 +2549,7 @@ ConstraintSystem::getTypeOfMemberReference(
2544
2549
openGenericRequirements (
2545
2550
outerDC, genericSig,
2546
2551
/* skipProtocolSelfConstraint=*/ true , locator,
2547
- [&](Type type) { return openType (type, replacements); });
2552
+ [&](Type type) { return openType (type, replacements, locator ); });
2548
2553
}
2549
2554
2550
2555
if (auto *funcDecl = dyn_cast<AbstractFunctionDecl>(value)) {
@@ -2569,11 +2574,11 @@ ConstraintSystem::getTypeOfMemberReference(
2569
2574
value, hasAppliedSelf, functionRefKind);
2570
2575
openedType = adjustFunctionTypeForConcurrency (
2571
2576
origOpenedType->castTo <AnyFunctionType>(), value, useDC, numApplies,
2572
- isMainDispatchQueueMember (locator), replacements);
2577
+ isMainDispatchQueueMember (locator), replacements, locator );
2573
2578
} else if (auto subscript = dyn_cast<SubscriptDecl>(value)) {
2574
2579
openedType = adjustFunctionTypeForConcurrency (
2575
2580
origOpenedType->castTo <AnyFunctionType>(), subscript, useDC,
2576
- /* numApplies=*/ 2 , /* isMainDispatchQueue=*/ false , replacements);
2581
+ /* numApplies=*/ 2 , /* isMainDispatchQueue=*/ false , replacements, locator );
2577
2582
} else if (auto var = dyn_cast<VarDecl>(value)) {
2578
2583
// Adjust the function's result type, since that's the Var's actual type.
2579
2584
auto origFnType = origOpenedType->castTo <AnyFunctionType>();
@@ -2700,9 +2705,9 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
2700
2705
// FIXME: Verify ExtInfo state is correct, not working by accident.
2701
2706
FunctionType::ExtInfo info;
2702
2707
type = adjustFunctionTypeForConcurrency (
2703
- FunctionType::get (indices, elementTy, info),
2704
- subscript, useDC, /* numApplies=*/ 1 , /* isMainDispatchQueue=*/ false ,
2705
- emptyReplacements );
2708
+ FunctionType::get (indices, elementTy, info), subscript, useDC,
2709
+ /* numApplies=*/ 1 , /* isMainDispatchQueue=*/ false , emptyReplacements ,
2710
+ locator );
2706
2711
} else if (auto var = dyn_cast<VarDecl>(decl)) {
2707
2712
type = var->getValueInterfaceType ();
2708
2713
if (doesStorageProduceLValue (var, overload.getBaseType (), useDC)) {
@@ -2748,10 +2753,9 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
2748
2753
decl, hasAppliedSelf, overload.getFunctionRefKind ());
2749
2754
2750
2755
type = adjustFunctionTypeForConcurrency (
2751
- type->castTo <FunctionType>(),
2752
- decl, useDC, numApplies, /* isMainDispatchQueue=*/ false ,
2753
- emptyReplacements)
2754
- ->getResult ();
2756
+ type->castTo <FunctionType>(), decl, useDC, numApplies,
2757
+ /* isMainDispatchQueue=*/ false , emptyReplacements, locator)
2758
+ ->getResult ();
2755
2759
}
2756
2760
}
2757
2761
0 commit comments