Skip to content

Commit a6f86c4

Browse files
committed
[ConstraintSystem] NFC: Extract opening of individual generic parameters into a method
1 parent cdf352d commit a6f86c4

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4173,6 +4173,13 @@ class ConstraintSystem {
41734173
OpenedTypeMap &replacements,
41744174
ConstraintLocatorBuilder locator);
41754175

4176+
/// Open a generic parameter into a type variable and record
4177+
/// it in \c replacements.
4178+
TypeVariableType *openGenericParameter(DeclContext *outerDC,
4179+
GenericTypeParamType *parameter,
4180+
OpenedTypeMap &replacements,
4181+
ConstraintLocatorBuilder locator);
4182+
41764183
/// Given generic signature open its generic requirements,
41774184
/// using substitution function, and record them in the
41784185
/// constraint system for further processing.

lib/Sema/ConstraintSystem.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,16 +1591,7 @@ void ConstraintSystem::openGenericParameters(DeclContext *outerDC,
15911591

15921592
// Create the type variables for the generic parameters.
15931593
for (auto gp : sig.getGenericParams()) {
1594-
auto *paramLocator = getConstraintLocator(
1595-
locator.withPathElement(LocatorPathElt::GenericParameter(gp)));
1596-
1597-
auto typeVar = createTypeVariable(paramLocator, TVO_PrefersSubtypeBinding |
1598-
TVO_CanBindToHole);
1599-
auto result = replacements.insert(std::make_pair(
1600-
cast<GenericTypeParamType>(gp->getCanonicalType()), typeVar));
1601-
1602-
assert(result.second);
1603-
(void)result;
1594+
(void)openGenericParameter(outerDC, gp, replacements, locator);
16041595
}
16051596

16061597
auto *baseLocator = getConstraintLocator(
@@ -1609,6 +1600,23 @@ void ConstraintSystem::openGenericParameters(DeclContext *outerDC,
16091600
bindArchetypesFromContext(*this, outerDC, baseLocator, replacements);
16101601
}
16111602

1603+
TypeVariableType *ConstraintSystem::openGenericParameter(
1604+
DeclContext *outerDC, GenericTypeParamType *parameter,
1605+
OpenedTypeMap &replacements, ConstraintLocatorBuilder locator) {
1606+
auto *paramLocator = getConstraintLocator(
1607+
locator.withPathElement(LocatorPathElt::GenericParameter(parameter)));
1608+
1609+
auto typeVar = createTypeVariable(paramLocator, TVO_PrefersSubtypeBinding |
1610+
TVO_CanBindToHole);
1611+
auto result = replacements.insert(std::make_pair(
1612+
cast<GenericTypeParamType>(parameter->getCanonicalType()), typeVar));
1613+
1614+
assert(result.second);
1615+
(void)result;
1616+
1617+
return typeVar;
1618+
}
1619+
16121620
void ConstraintSystem::openGenericRequirements(
16131621
DeclContext *outerDC, GenericSignature signature,
16141622
bool skipProtocolSelfConstraint, ConstraintLocatorBuilder locator,

0 commit comments

Comments
 (0)