Skip to content

Commit 2fde4a5

Browse files
committed
Sema: Split off getTypeOfMemberReferenceImpl() from getTypeOfMemberReference()
1 parent 8397c08 commit 2fde4a5

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4463,6 +4463,13 @@ class ConstraintSystem {
44634463
DeclContext *useDC,
44644464
PreparedOverloadBuilder *preparedOverload);
44654465

4466+
/// \returns the opened type, the thrown error type, and the base object type.
4467+
std::tuple<Type, Type, Type> getTypeOfMemberReferenceImpl(
4468+
Type baseTy, ValueDecl *decl, DeclContext *useDC, bool isDynamicLookup,
4469+
FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
4470+
SmallVectorImpl<OpenedType> *replacements = nullptr,
4471+
PreparedOverloadBuilder *preparedOverload = nullptr);
4472+
44664473
/// Retrieve the type of a reference to the given value declaration,
44674474
/// as a member with a base of the given type.
44684475
///

lib/Sema/TypeOfReference.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,29 +1851,20 @@ static FunctionType *applyOptionality(ValueDecl *value, FunctionType *fnTy) {
18511851
fnTy->getExtInfo());
18521852
}
18531853

1854-
DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
1854+
std::tuple<Type, Type, Type>
1855+
ConstraintSystem::getTypeOfMemberReferenceImpl(
18551856
Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup,
18561857
FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
18571858
SmallVectorImpl<OpenedType> *replacementsPtr,
18581859
PreparedOverloadBuilder *preparedOverload) {
1860+
ASSERT(!isa<TypeDecl>(value));
18591861
ASSERT(!!preparedOverload == PreparingOverload);
18601862
recordFixIfNeededForPlaceholderInDecl(*this, value, locator);
18611863

18621864
// Figure out the instance type used for the base.
18631865
Type baseRValueTy = baseTy->getRValueType();
18641866
auto baseObjTy = baseRValueTy->getMetatypeInstanceType();
18651867

1866-
// If the base is a module type, just use the type of the decl.
1867-
if (baseObjTy->is<ModuleType>()) {
1868-
return getTypeOfReference(value, functionRefInfo, locator, useDC,
1869-
preparedOverload);
1870-
}
1871-
1872-
if (auto *typeDecl = dyn_cast<TypeDecl>(value)) {
1873-
return getTypeOfMemberTypeReference(baseObjTy, typeDecl,
1874-
locator, preparedOverload);
1875-
}
1876-
18771868
// Figure out the declaration context to use when opening this type.
18781869
DeclContext *innerDC = value->getInnermostDeclContext();
18791870
DeclContext *outerDC = value->getDeclContext();
@@ -1914,7 +1905,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
19141905
isa<MacroDecl>(value)) {
19151906
auto interfaceType = value->getInterfaceType();
19161907
if (interfaceType->is<ErrorType>() || isa<MacroDecl>(value))
1917-
return { interfaceType, interfaceType, interfaceType, interfaceType, Type() };
1908+
return { interfaceType, Type(), baseObjTy };
19181909

19191910
if (outerDC->getSelfClassDecl()) {
19201911
if (isa<ConstructorDecl>(value)) {
@@ -2030,6 +2021,40 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
20302021
}
20312022
}
20322023

2024+
return { openedType, thrownErrorType, baseObjTy };
2025+
}
2026+
2027+
DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
2028+
Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup,
2029+
FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
2030+
SmallVectorImpl<OpenedType> *replacementsPtr,
2031+
PreparedOverloadBuilder *preparedOverload) {
2032+
ASSERT(!!preparedOverload == PreparingOverload);
2033+
2034+
// Figure out the instance type used for the base.
2035+
Type baseRValueTy = baseTy;
2036+
Type baseObjTy = baseRValueTy->getMetatypeInstanceType();
2037+
2038+
// If the base is a module type, just use the type of the decl.
2039+
if (baseObjTy->getMetatypeInstanceType()->is<ModuleType>()) {
2040+
return getTypeOfReference(value, functionRefInfo, locator, useDC,
2041+
preparedOverload);
2042+
}
2043+
2044+
if (auto *typeDecl = dyn_cast<TypeDecl>(value)) {
2045+
return getTypeOfMemberTypeReference(baseObjTy, typeDecl,
2046+
locator, preparedOverload);
2047+
}
2048+
2049+
Type openedType, thrownErrorType;
2050+
std::tie(openedType, thrownErrorType, baseObjTy)
2051+
= getTypeOfMemberReferenceImpl(baseTy, value, useDC,
2052+
isDynamicLookup, functionRefInfo,
2053+
locator, replacementsPtr,
2054+
preparedOverload);
2055+
2056+
auto hasAppliedSelf = doesMemberRefApplyCurriedSelf(baseRValueTy, value);
2057+
20332058
// Adjust the opened type for concurrency.
20342059
Type origOpenedType = openedType;
20352060
if (isRequirementOrWitness(locator)) {

0 commit comments

Comments
 (0)