Skip to content

Commit c1087b9

Browse files
committed
[ConstraintSystem] Remove boolean flags from openGeneric/openFunctionType
1 parent ae68558 commit c1087b9

File tree

4 files changed

+26
-41
lines changed

4 files changed

+26
-41
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ static bool isProtocolExtensionAsSpecializedAs(TypeChecker &tc,
341341
// the second protocol extension.
342342
ConstraintSystem cs(tc, dc1, None);
343343
OpenedTypeMap replacements;
344-
cs.openGeneric(dc2, sig2,
345-
/*skipProtocolSelfConstraint=*/false,
346-
ConstraintLocatorBuilder(nullptr), replacements);
344+
cs.openGeneric(dc2, sig2, ConstraintLocatorBuilder(nullptr), replacements);
347345

348346
// Bind the 'Self' type from the first extension to the type parameter from
349347
// opening 'Self' of the second extension.
@@ -511,13 +509,11 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
511509
OpenedTypeMap &replacements,
512510
ConstraintLocator *locator) -> Type {
513511
if (auto *funcType = type->getAs<AnyFunctionType>()) {
514-
return cs.openFunctionType(funcType, locator, replacements, outerDC,
515-
/*skipProtocolSelfConstraint=*/false);
512+
return cs.openFunctionType(funcType, locator, replacements, outerDC);
516513
}
517514

518515
cs.openGeneric(outerDC, innerDC->getGenericSignatureOfContext(),
519-
/*skipProtocolSelfConstraint=*/false, locator,
520-
replacements);
516+
locator, replacements);
521517

522518
return cs.openType(type, replacements);
523519
};

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4883,8 +4883,7 @@ ConstraintSystem::simplifyOpaqueUnderlyingTypeConstraint(Type type1, Type type2,
48834883
// corresponding to the underlying type should be the constraints on the
48844884
// underlying return type.
48854885
OpenedTypeMap replacements;
4886-
openGeneric(DC, opaque2->getBoundSignature(),
4887-
/*skip self*/ false, locator, replacements);
4886+
openGeneric(DC, opaque2->getBoundSignature(), locator, replacements);
48884887

48894888
auto underlyingTyVar = openType(opaque2->getInterfaceType(),
48904889
replacements);

lib/Sema/ConstraintSystem.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ Type ConstraintSystem::openUnboundGenericType(UnboundGenericType *unbound,
466466

467467
// Open up the generic type.
468468
openGeneric(unboundDecl->getDeclContext(), unboundDecl->getGenericSignature(),
469-
/*skipProtocolSelfConstraint=*/false, locator, replacements);
469+
locator, replacements);
470470

471471
if (parentTy) {
472472
auto subs = parentTy->getContextSubstitutions(
@@ -633,19 +633,15 @@ FunctionType *ConstraintSystem::openFunctionType(
633633
AnyFunctionType *funcType,
634634
ConstraintLocatorBuilder locator,
635635
OpenedTypeMap &replacements,
636-
DeclContext *outerDC,
637-
bool skipProtocolSelfConstraint,
638-
bool skipGenericRequirements) {
636+
DeclContext *outerDC) {
639637
if (auto *genericFn = funcType->getAs<GenericFunctionType>()) {
640638
auto *signature = genericFn->getGenericSignature();
641639

642640
openGenericParameters(outerDC, signature, replacements, locator);
643641

644-
if (!skipGenericRequirements) {
645-
openGenericRequirements(
646-
outerDC, signature, skipProtocolSelfConstraint, locator,
647-
[&](Type type) -> Type { return openType(type, replacements); });
648-
}
642+
openGenericRequirements(
643+
outerDC, signature, /*skipProtocolSelfConstraint=*/false, locator,
644+
[&](Type type) -> Type { return openType(type, replacements); });
649645

650646
funcType = genericFn->substGenericArgs(
651647
[&](Type type) { return openType(type, replacements); });
@@ -914,11 +910,9 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
914910

915911
OpenedTypeMap replacements;
916912

917-
auto openedType = openFunctionType(
918-
func->getInterfaceType()->castTo<AnyFunctionType>(),
919-
locator, replacements,
920-
func->getDeclContext(),
921-
/*skipProtocolSelfConstraint=*/false);
913+
auto openedType =
914+
openFunctionType(func->getInterfaceType()->castTo<AnyFunctionType>(),
915+
locator, replacements, func->getDeclContext());
922916

923917
// If we opened up any type variables, record the replacements.
924918
recordOpenedTypes(locator, replacements);
@@ -951,8 +945,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
951945
/*isCurriedInstanceReference=*/false, functionRefKind);
952946

953947
auto openedType = openFunctionType(funcType, locator, replacements,
954-
funcDecl->getDeclContext(),
955-
/*skipProtocolSelfConstraint=*/false)
948+
funcDecl->getDeclContext())
956949
->removeArgumentLabels(numLabelsToRemove);
957950

958951
// If we opened up any type variables, record the replacements.
@@ -1079,7 +1072,6 @@ static void bindArchetypesFromContext(
10791072
void ConstraintSystem::openGeneric(
10801073
DeclContext *outerDC,
10811074
GenericSignature *sig,
1082-
bool skipProtocolSelfConstraint,
10831075
ConstraintLocatorBuilder locator,
10841076
OpenedTypeMap &replacements) {
10851077
if (sig == nullptr)
@@ -1089,7 +1081,7 @@ void ConstraintSystem::openGeneric(
10891081

10901082
// Add the requirements as constraints.
10911083
openGenericRequirements(
1092-
outerDC, sig, skipProtocolSelfConstraint, locator,
1084+
outerDC, sig, /*skipProtocolSelfConstraint=*/false, locator,
10931085
[&](Type type) { return openType(type, replacements); });
10941086
}
10951087

@@ -1304,10 +1296,17 @@ ConstraintSystem::getTypeOfMemberReference(
13041296

13051297
// While opening member function type, let's delay opening requirements
13061298
// to allow contextual types to affect the situation.
1307-
openedType = openFunctionType(funcType, locator, replacements, outerDC,
1308-
/*skipProtocolSelfConstraint=*/true,
1309-
/*skipGenericRequirements=*/true)
1310-
->removeArgumentLabels(numRemovedArgumentLabels);
1299+
if (auto *genericFn = funcType->getAs<GenericFunctionType>()) {
1300+
openGenericParameters(outerDC, genericFn->getGenericSignature(),
1301+
replacements, locator);
1302+
1303+
openedType = genericFn->substGenericArgs(
1304+
[&](Type type) { return openType(type, replacements); });
1305+
} else {
1306+
openedType = funcType;
1307+
}
1308+
1309+
openedType = openedType->removeArgumentLabels(numRemovedArgumentLabels);
13111310

13121311
if (!outerDC->getSelfProtocolDecl()) {
13131312
// Class methods returning Self as well as constructors get the

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,25 +2371,16 @@ class ConstraintSystem {
23712371
///
23722372
/// \param outerDC The generic context containing the declaration.
23732373
///
2374-
/// \param skipProtocolSelfConstraint Whether to skip the constraint on a
2375-
/// protocol's 'Self' type.
2376-
///
2377-
/// \param skipGenericRequirements Whether to skip opening generic
2378-
/// requirements asscoiated with given function type.
2379-
///
23802374
/// \returns The opened type, or \c type if there are no archetypes in it.
23812375
FunctionType *openFunctionType(AnyFunctionType *funcType,
23822376
ConstraintLocatorBuilder locator,
23832377
OpenedTypeMap &replacements,
2384-
DeclContext *outerDC,
2385-
bool skipProtocolSelfConstraint,
2386-
bool skipGenericRequirements = false);
2378+
DeclContext *outerDC);
23872379

23882380
/// Open the generic parameter list and its requirements,
23892381
/// creating type variables for each of the type parameters.
23902382
void openGeneric(DeclContext *outerDC,
23912383
GenericSignature *signature,
2392-
bool skipProtocolSelfConstraint,
23932384
ConstraintLocatorBuilder locator,
23942385
OpenedTypeMap &replacements);
23952386

0 commit comments

Comments
 (0)