@@ -1109,11 +1109,12 @@ recordFixIfNeededForPlaceholderInDecl(ConstraintSystem &cs, ValueDecl *D,
1109
1109
}
1110
1110
1111
1111
std::pair<Type, Type>
1112
- ConstraintSystem::getTypeOfReferenceImpl (ValueDecl *value,
1113
- FunctionRefInfo functionRefInfo,
1112
+ ConstraintSystem::getTypeOfReferenceImpl (OverloadChoice choice,
1114
1113
ConstraintLocatorBuilder locator,
1115
1114
DeclContext *useDC,
1116
1115
PreparedOverloadBuilder *preparedOverload) {
1116
+ auto *value = choice.getDecl ();
1117
+
1117
1118
ASSERT (!!preparedOverload == PreparingOverload);
1118
1119
1119
1120
recordFixIfNeededForPlaceholderInDecl (*this , value, locator);
@@ -1139,6 +1140,8 @@ ConstraintSystem::getTypeOfReferenceImpl(ValueDecl *value,
1139
1140
1140
1141
// Unqualified reference to a local or global function.
1141
1142
if (auto funcDecl = dyn_cast<AbstractFunctionDecl>(value)) {
1143
+ auto functionRefInfo = choice.getFunctionRefInfo ();
1144
+
1142
1145
SmallVector<OpenedType, 4 > replacements;
1143
1146
1144
1147
auto funcType = funcDecl->getInterfaceType ()->castTo <AnyFunctionType>();
@@ -1234,16 +1237,17 @@ ConstraintSystem::getTypeOfReferenceImpl(ValueDecl *value,
1234
1237
}
1235
1238
1236
1239
DeclReferenceType
1237
- ConstraintSystem::getTypeOfReference (ValueDecl *value,
1238
- FunctionRefInfo functionRefInfo,
1240
+ ConstraintSystem::getTypeOfReference (OverloadChoice choice,
1239
1241
ConstraintLocatorBuilder locator,
1240
1242
DeclContext *useDC,
1241
1243
PreparedOverloadBuilder *preparedOverload) {
1242
1244
ASSERT (!!preparedOverload == PreparingOverload);
1243
1245
1244
1246
Type openedType, thrownErrorType;
1245
1247
std::tie (openedType, thrownErrorType) = getTypeOfReferenceImpl (
1246
- value, functionRefInfo, locator, useDC, preparedOverload);
1248
+ choice, locator, useDC, preparedOverload);
1249
+
1250
+ auto *value = choice.getDecl ();
1247
1251
1248
1252
if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
1249
1253
auto *openedFnType = openedType->castTo <FunctionType>();
@@ -1252,6 +1256,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1252
1256
auto func = cast<FuncDecl>(value);
1253
1257
assert (func->isOperator () && " Lookup should only find operators" );
1254
1258
1259
+ auto functionRefInfo = choice.getFunctionRefInfo ();
1255
1260
1256
1261
auto origOpenedType = openedFnType;
1257
1262
if (!isRequirementOrWitness (locator)) {
@@ -1293,7 +1298,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1293
1298
auto origOpenedType = openedType;
1294
1299
if (!isRequirementOrWitness (locator)) {
1295
1300
unsigned numApplies = getNumApplications (/* hasAppliedSelf*/ false ,
1296
- functionRefInfo );
1301
+ choice. getFunctionRefInfo () );
1297
1302
openedType = adjustFunctionTypeForConcurrency (
1298
1303
origOpenedType->castTo <FunctionType>(), /* baseType=*/ Type (), funcDecl,
1299
1304
useDC, numApplies, /* isMainDispatchQueue=*/ false ,
@@ -1523,10 +1528,10 @@ void ConstraintSystem::openGenericRequirement(
1523
1528
preparedOverload);
1524
1529
}
1525
1530
1526
- DeclReferenceType ConstraintSystem::getTypeOfMemberTypeReference (
1531
+ Type ConstraintSystem::getTypeOfMemberTypeReference (
1527
1532
Type baseObjTy, TypeDecl *typeDecl, ConstraintLocator *locator,
1528
1533
PreparedOverloadBuilder *preparedOverload) {
1529
- assert (!isa<ModuleDecl>(typeDecl) && " Nested module?" );
1534
+ ASSERT (!isa<ModuleDecl>(typeDecl) && " Nested module?" );
1530
1535
1531
1536
auto memberTy = TypeChecker::substMemberTypeWithBase (typeDecl, baseObjTy);
1532
1537
@@ -1552,8 +1557,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberTypeReference(
1552
1557
}
1553
1558
1554
1559
FunctionType::Param baseObjParam (baseObjTy);
1555
- auto openedType = FunctionType::get ({baseObjParam}, memberTy);
1556
- return { openedType, openedType, memberTy, memberTy, Type () };
1560
+ return FunctionType::get ({baseObjParam}, memberTy);
1557
1561
}
1558
1562
1559
1563
std::pair<Type, Type> ConstraintSystem::getOpenedStorageType (
@@ -1853,18 +1857,30 @@ static FunctionType *applyOptionality(ValueDecl *value, FunctionType *fnTy) {
1853
1857
1854
1858
std::tuple<Type, Type, Type>
1855
1859
ConstraintSystem::getTypeOfMemberReferenceImpl (
1856
- Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup,
1857
- FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
1858
- SmallVectorImpl<OpenedType> *replacementsPtr,
1860
+ OverloadChoice choice, DeclContext *useDC,
1861
+ ConstraintLocator *locator, SmallVectorImpl<OpenedType> *replacementsPtr,
1859
1862
PreparedOverloadBuilder *preparedOverload) {
1860
- ASSERT (!isa<TypeDecl>(value));
1861
1863
ASSERT (!!preparedOverload == PreparingOverload);
1864
+
1865
+ auto *value = choice.getDecl ();
1866
+ auto functionRefInfo = choice.getFunctionRefInfo ();
1867
+
1862
1868
recordFixIfNeededForPlaceholderInDecl (*this , value, locator);
1863
1869
1864
1870
// Figure out the instance type used for the base.
1871
+ auto baseTy = choice.getBaseType ();
1865
1872
Type baseRValueTy = baseTy->getRValueType ();
1866
1873
auto baseObjTy = baseRValueTy->getMetatypeInstanceType ();
1867
1874
1875
+ Type openedType;
1876
+ Type thrownErrorType;
1877
+
1878
+ if (auto *typeDecl = dyn_cast<TypeDecl>(value)) {
1879
+ openedType = getTypeOfMemberTypeReference (baseObjTy, typeDecl,
1880
+ locator, preparedOverload);
1881
+ return {openedType, thrownErrorType, baseObjTy};
1882
+ }
1883
+
1868
1884
// Figure out the declaration context to use when opening this type.
1869
1885
DeclContext *innerDC = value->getInnermostDeclContext ();
1870
1886
DeclContext *outerDC = value->getDeclContext ();
@@ -1898,8 +1914,6 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
1898
1914
// strip it off later.
1899
1915
auto hasAppliedSelf = doesMemberRefApplyCurriedSelf (baseRValueTy, value);
1900
1916
1901
- Type openedType;
1902
- Type thrownErrorType;
1903
1917
if (isa<AbstractFunctionDecl>(value) ||
1904
1918
isa<EnumElementDecl>(value) ||
1905
1919
isa<MacroDecl>(value)) {
@@ -1987,7 +2001,7 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
1987
2001
addConstraint (ConstraintKind::Bind, baseOpenedTy, selfObjTy,
1988
2002
getConstraintLocator (locator), /* isFavored=*/ false ,
1989
2003
preparedOverload);
1990
- } else if (!isDynamicLookup ) {
2004
+ } else if (choice. getKind () != OverloadChoiceKind::DeclViaDynamic ) {
1991
2005
addSelfConstraint (*this , baseOpenedTy, selfObjTy, locator, preparedOverload);
1992
2006
}
1993
2007
@@ -2025,42 +2039,40 @@ ConstraintSystem::getTypeOfMemberReferenceImpl(
2025
2039
}
2026
2040
2027
2041
DeclReferenceType ConstraintSystem::getTypeOfMemberReference (
2028
- Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup,
2029
- FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
2042
+ OverloadChoice choice, DeclContext *useDC, ConstraintLocator *locator,
2030
2043
SmallVectorImpl<OpenedType> *replacementsPtr,
2031
2044
PreparedOverloadBuilder *preparedOverload) {
2032
2045
ASSERT (!!preparedOverload == PreparingOverload);
2033
2046
2047
+ auto *value = choice.getDecl ();
2048
+
2034
2049
// Figure out the instance type used for the base.
2035
- Type baseRValueTy = baseTy ;
2050
+ Type baseRValueTy = choice. getBaseType () ;
2036
2051
Type baseObjTy = baseRValueTy->getMetatypeInstanceType ();
2037
2052
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
- }
2053
+ // A reference to a module member is really unqualified, and should
2054
+ // be handled by the caller via getTypeOfReference().
2055
+ ASSERT (!baseObjTy->is <ModuleType>());
2048
2056
2049
2057
Type openedType, thrownErrorType;
2050
2058
std::tie (openedType, thrownErrorType, baseObjTy)
2051
- = getTypeOfMemberReferenceImpl (baseTy, value, useDC,
2052
- isDynamicLookup, functionRefInfo,
2053
- locator, replacementsPtr,
2059
+ = getTypeOfMemberReferenceImpl (choice, useDC, locator, replacementsPtr,
2054
2060
preparedOverload);
2055
2061
2062
+ if (isa<TypeDecl>(value)) {
2063
+ auto type = openedType->castTo <FunctionType>()->getResult ();
2064
+ return { openedType, openedType, type, type, Type () };
2065
+ }
2066
+
2056
2067
auto hasAppliedSelf = doesMemberRefApplyCurriedSelf (baseRValueTy, value);
2057
2068
2058
2069
// Adjust the opened type for concurrency.
2059
2070
Type origOpenedType = openedType;
2060
2071
if (isRequirementOrWitness (locator)) {
2061
2072
// Don't adjust when doing witness matching, because that can cause cycles.
2062
2073
} else if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
2063
- unsigned numApplies = getNumApplications (hasAppliedSelf, functionRefInfo);
2074
+ unsigned numApplies = getNumApplications (
2075
+ hasAppliedSelf, choice.getFunctionRefInfo ());
2064
2076
openedType = adjustFunctionTypeForConcurrency (
2065
2077
origOpenedType->castTo <FunctionType>(), baseObjTy, value, useDC,
2066
2078
numApplies, isMainDispatchQueueMember (locator),
@@ -2082,6 +2094,8 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
2082
2094
origFnType->getParams (), resultTy, origFnType->getExtInfo ());
2083
2095
}
2084
2096
2097
+ bool isDynamicLookup = (choice.getKind () == OverloadChoiceKind::DeclViaDynamic);
2098
+
2085
2099
// Check if we need to apply a layer of optionality to the type.
2086
2100
if (!isRequirementOrWitness (locator)) {
2087
2101
if (isDynamicLookup || value->getAttrs ().hasAttribute <OptionalAttr>()) {
@@ -2833,14 +2847,16 @@ ConstraintSystem::prepareOverloadImpl(ConstraintLocator *locator,
2833
2847
// Retrieve the type of a reference to the specific declaration choice.
2834
2848
assert (!baseTy->hasTypeParameter ());
2835
2849
2850
+ // If the base is a module type, it's an unqualified reference.
2851
+ if (baseTy->getMetatypeInstanceType ()->is <ModuleType>()) {
2852
+ return getTypeOfReference (choice, locator, useDC, preparedOverload);
2853
+ }
2854
+
2836
2855
return getTypeOfMemberReference (
2837
- baseTy, choice.getDecl (), useDC,
2838
- (choice.getKind () == OverloadChoiceKind::DeclViaDynamic),
2839
- choice.getFunctionRefInfo (), locator, nullptr , preparedOverload);
2856
+ choice, useDC, locator, /* replacements=*/ nullptr , preparedOverload);
2840
2857
} else {
2841
2858
return getTypeOfReference (
2842
- choice.getDecl (), choice.getFunctionRefInfo (), locator, useDC,
2843
- preparedOverload);
2859
+ choice, locator, useDC, preparedOverload);
2844
2860
}
2845
2861
}
2846
2862
0 commit comments