Skip to content

Commit 182c384

Browse files
committed
Sema: Remove replacementsPtr parameter from getTypeOfMemberReference()
1 parent 4ea2f17 commit 182c384

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,8 +4462,7 @@ class ConstraintSystem {
44624462
/// \returns the opened type and the thrown error type.
44634463
std::pair<Type, Type> getTypeOfMemberReferenceImpl(
44644464
OverloadChoice choice, DeclContext *useDC, ConstraintLocator *locator,
4465-
SmallVectorImpl<OpenedType> *replacements = nullptr,
4466-
PreparedOverloadBuilder *preparedOverload = nullptr);
4465+
PreparedOverloadBuilder *preparedOverload);
44674466

44684467
/// Retrieve the type of a reference to the given value declaration,
44694468
/// as a member with a base of the given type.
@@ -4475,8 +4474,7 @@ class ConstraintSystem {
44754474
/// \returns a description of the type of this declaration reference.
44764475
DeclReferenceType getTypeOfMemberReference(
44774476
OverloadChoice choice, DeclContext *useDC, ConstraintLocator *locator,
4478-
SmallVectorImpl<OpenedType> *replacements = nullptr,
4479-
PreparedOverloadBuilder *preparedOverload = nullptr);
4477+
PreparedOverloadBuilder *preparedOverload);
44804478

44814479
/// Retrieve a list of generic parameter types solver has "opened" (replaced
44824480
/// with a type variable) at the given location.

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,21 +1168,21 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
11681168
Type selfTy = proto->getSelfInterfaceType().subst(reqSubMap);
11691169

11701170
// Open up the type of the requirement.
1171-
SmallVector<OpenedType, 4> reqReplacements;
1172-
11731171
reqLocator =
11741172
cs->getConstraintLocator(req, ConstraintLocator::ProtocolRequirement);
11751173
OverloadChoice reqChoice(selfTy, req, FunctionRefInfo::doubleBaseNameApply());
11761174
auto reqTypeInfo =
1177-
cs->getTypeOfMemberReference(reqChoice, dc, reqLocator, &reqReplacements);
1175+
cs->getTypeOfMemberReference(reqChoice, dc, reqLocator,
1176+
/*preparedOverload=*/nullptr);
1177+
11781178
reqType = reqTypeInfo.adjustedReferenceType;
11791179
reqType = reqType->getRValueType();
11801180

11811181
Type reqThrownError = reqTypeInfo.thrownErrorTypeOnAccess;
11821182

11831183
// For any type parameters we replaced in the witness, map them
11841184
// to the corresponding archetypes in the witness's context.
1185-
for (const auto &replacement : reqReplacements) {
1185+
for (const auto &replacement : cs->getOpenedTypes(reqLocator)) {
11861186
auto replacedInReq = Type(replacement.first).subst(reqSubMap);
11871187

11881188
// If substitution failed, skip the requirement. This only occurs in
@@ -1210,7 +1210,6 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
12101210
openWitnessTypeInfo =
12111211
cs->getTypeOfMemberReference(witnessChoice, dc,
12121212
witnessLocator,
1213-
/*replacements=*/nullptr,
12141213
/*preparedOverload=*/nullptr);
12151214
} else {
12161215
OverloadChoice witnessChoice(Type(), witness, FunctionRefInfo::doubleBaseNameApply());

lib/Sema/TypeOfReference.cpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ static FunctionType *applyOptionality(ValueDecl *value, FunctionType *fnTy) {
18581858
std::pair<Type, Type>
18591859
ConstraintSystem::getTypeOfMemberReferenceImpl(
18601860
OverloadChoice choice, DeclContext *useDC,
1861-
ConstraintLocator *locator, SmallVectorImpl<OpenedType> *replacementsPtr,
1861+
ConstraintLocator *locator,
18621862
PreparedOverloadBuilder *preparedOverload) {
18631863
ASSERT(!!preparedOverload == PreparingOverload);
18641864

@@ -1888,28 +1888,23 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
18881888
auto genericSig = innerDC->getGenericSignatureOfContext();
18891889

18901890
// Open the type of the generic function or member of a generic type.
1891-
ArrayRef<OpenedType> replacements;
1892-
SmallVector<OpenedType, 4> localReplacements;
1893-
{
1894-
auto &_replacements = replacementsPtr ? *replacementsPtr : localReplacements;
1895-
1896-
// If we have a generic signature, open the parameters. We delay opening
1897-
// requirements to allow contextual types to affect the situation.
1898-
if (genericSig) {
1899-
openGenericParameters(outerDC, genericSig, _replacements, locator,
1900-
preparedOverload);
1901-
}
1891+
SmallVector<OpenedType, 4> replacements;
19021892

1903-
// If we opened up any type variables, record the replacements. We do this
1904-
// up-front to allow requirement fix coalescing logic to work correctly with
1905-
// requirements imposed on base type (since that relies on being able to
1906-
// find the recorded opened type). We then make the array immutable for the
1907-
// following logic to ensure they don't attempt to add any additional opened
1908-
// types.
1909-
recordOpenedTypes(locator, _replacements, preparedOverload);
1910-
replacements = _replacements;
1893+
// If we have a generic signature, open the parameters. We delay opening
1894+
// requirements to allow contextual types to affect the situation.
1895+
if (genericSig) {
1896+
openGenericParameters(outerDC, genericSig, replacements, locator,
1897+
preparedOverload);
19111898
}
19121899

1900+
// If we opened up any type variables, record the replacements. We do this
1901+
// up-front to allow requirement fix coalescing logic to work correctly with
1902+
// requirements imposed on base type (since that relies on being able to
1903+
// find the recorded opened type). We then make the array immutable for the
1904+
// following logic to ensure they don't attempt to add any additional opened
1905+
// types.
1906+
recordOpenedTypes(locator, replacements, preparedOverload);
1907+
19131908
// Check to see if the self parameter is applied, in which case we'll want to
19141909
// strip it off later.
19151910
auto hasAppliedSelf = doesMemberRefApplyCurriedSelf(baseRValueTy, value);
@@ -2039,7 +2034,6 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
20392034

20402035
DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
20412036
OverloadChoice choice, DeclContext *useDC, ConstraintLocator *locator,
2042-
SmallVectorImpl<OpenedType> *replacementsPtr,
20432037
PreparedOverloadBuilder *preparedOverload) {
20442038
ASSERT(!!preparedOverload == PreparingOverload);
20452039

@@ -2056,8 +2050,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
20562050

20572051
Type openedType, thrownErrorType;
20582052
std::tie(openedType, thrownErrorType)
2059-
= getTypeOfMemberReferenceImpl(choice, useDC, locator, replacementsPtr,
2060-
preparedOverload);
2053+
= getTypeOfMemberReferenceImpl(choice, useDC, locator, preparedOverload);
20612054

20622055
if (isa<TypeDecl>(value)) {
20632056
auto type = openedType->castTo<FunctionType>()->getResult();
@@ -2852,11 +2845,9 @@ ConstraintSystem::prepareOverloadImpl(ConstraintLocator *locator,
28522845
return getTypeOfReference(choice, locator, useDC, preparedOverload);
28532846
}
28542847

2855-
return getTypeOfMemberReference(
2856-
choice, useDC, locator, /*replacements=*/nullptr, preparedOverload);
2848+
return getTypeOfMemberReference(choice, useDC, locator, preparedOverload);
28572849
} else {
2858-
return getTypeOfReference(
2859-
choice, locator, useDC, preparedOverload);
2850+
return getTypeOfReference(choice, locator, useDC, preparedOverload);
28602851
}
28612852
}
28622853

0 commit comments

Comments
 (0)