@@ -759,22 +759,27 @@ namespace {
759
759
new (ctx) DeclRefExpr (ref, loc, implicit, semantics, fullType);
760
760
cs.cacheType (declRefExpr);
761
761
declRefExpr->setFunctionRefKind (choice.getFunctionRefKind ());
762
- Expr *result = adjustTypeForDeclReference (
763
- declRefExpr, fullType, adjustedFullType, locator);
764
- // If we have to load, do so now.
765
- if (loadImmediately)
766
- result = cs.addImplicitLoadExpr (result);
767
762
768
- result = forceUnwrapIfExpected (result , locator);
763
+ Expr * result = forceUnwrapIfExpected (declRefExpr , locator);
769
764
770
765
if (auto *fnDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
771
766
if (AnyFunctionRef (fnDecl).hasExternalPropertyWrapperParameters () &&
772
767
(declRefExpr->getFunctionRefKind () == FunctionRefKind::Compound ||
773
768
declRefExpr->getFunctionRefKind () == FunctionRefKind::Unapplied)) {
774
- result = buildSingleCurryThunk (result, fnDecl, locator);
769
+ // We don't need to do any further adjustment once we've built the
770
+ // curry thunk.
771
+ return buildSingleCurryThunk (result, fnDecl,
772
+ adjustedFullType->castTo <FunctionType>(),
773
+ locator);
775
774
}
776
775
}
777
776
777
+ result = adjustTypeForDeclReference (result, fullType, adjustedFullType,
778
+ locator);
779
+ // If we have to load, do so now.
780
+ if (loadImmediately)
781
+ result = cs.addImplicitLoadExpr (result);
782
+
778
783
return result;
779
784
}
780
785
@@ -1406,41 +1411,20 @@ namespace {
1406
1411
// / parameters.
1407
1412
// / \param declOrClosure The underlying function-like declaration or
1408
1413
// / closure we're going to call.
1414
+ // / \param thunkTy The type of the resulting thunk. This should be the
1415
+ // / type of the \c fnExpr, with any potential adjustments for things like
1416
+ // / concurrency.
1409
1417
// / \param locator The locator pinned on the function reference carried
1410
1418
// / by \p fnExpr. If the function has associated applied property wrappers,
1411
1419
// / the locator is used to pull them in.
1412
1420
AutoClosureExpr *buildSingleCurryThunk (Expr *fnExpr,
1413
1421
DeclContext *declOrClosure,
1422
+ FunctionType *thunkTy,
1414
1423
ConstraintLocatorBuilder locator) {
1415
- auto *const thunkTy = cs.getType (fnExpr)->castTo <FunctionType>();
1416
-
1417
1424
return buildSingleCurryThunk (/* baseExpr=*/ nullptr , fnExpr, declOrClosure,
1418
1425
thunkTy, locator);
1419
1426
}
1420
1427
1421
- // / Build a "{ args in base.fn(args) }" single-expression curry thunk.
1422
- // /
1423
- // / \param baseExpr The base expression to be captured.
1424
- // / \param fnExpr The expression to be called by consecutively applying
1425
- // / the \p baseExpr and thunk parameters.
1426
- // / \param declOrClosure The underlying function-like declaration or
1427
- // / closure we're going to call.
1428
- // / \param locator The locator pinned on the function reference carried
1429
- // / by \p fnExpr. If the function has associated applied property wrappers,
1430
- // / the locator is used to pull them in.
1431
- AutoClosureExpr *buildSingleCurryThunk (Expr *baseExpr, Expr *fnExpr,
1432
- DeclContext *declOrClosure,
1433
- ConstraintLocatorBuilder locator) {
1434
- assert (baseExpr);
1435
- auto *const thunkTy = cs.getType (fnExpr)
1436
- ->castTo <FunctionType>()
1437
- ->getResult ()
1438
- ->castTo <FunctionType>();
1439
-
1440
- return buildSingleCurryThunk (baseExpr, fnExpr, declOrClosure, thunkTy,
1441
- locator);
1442
- }
1443
-
1444
1428
// / Build a "{ self in { args in self.fn(args) } }" nested curry thunk.
1445
1429
// /
1446
1430
// / \param memberRef The expression to be called in the inner thunk by
@@ -1577,8 +1561,8 @@ namespace {
1577
1561
ConstraintLocatorBuilder memberLocator, bool Implicit,
1578
1562
AccessSemantics semantics) {
1579
1563
const auto &choice = overload.choice ;
1580
- const auto openedType = overload.openedType ;
1581
- const auto adjustedOpenedType = overload.adjustedOpenedType ;
1564
+ const auto openedType = simplifyType ( overload.openedType ) ;
1565
+ const auto adjustedOpenedType = simplifyType ( overload.adjustedOpenedType ) ;
1582
1566
1583
1567
ValueDecl *member = choice.getDecl ();
1584
1568
@@ -1639,7 +1623,7 @@ namespace {
1639
1623
// If we're referring to a member type, it's just a type
1640
1624
// reference.
1641
1625
if (auto *TD = dyn_cast<TypeDecl>(member)) {
1642
- Type refType = simplifyType ( adjustedOpenedType) ;
1626
+ Type refType = adjustedOpenedType;
1643
1627
auto ref = TypeExpr::createForDecl (memberLoc, TD, dc);
1644
1628
cs.setType (ref, refType);
1645
1629
auto *result = new (context) DotSyntaxBaseIgnoredExpr (
@@ -1770,10 +1754,8 @@ namespace {
1770
1754
ref->setImplicit (Implicit);
1771
1755
// FIXME: FunctionRefKind
1772
1756
1773
- auto computeRefType = [&](Type openedType) {
1774
- // Compute the type of the reference.
1775
- Type refType = simplifyType (openedType);
1776
-
1757
+ // Compute the type of the reference.
1758
+ auto computeRefType = [&](Type refType) {
1777
1759
// If the base was an opened existential, erase the opened
1778
1760
// existential.
1779
1761
if (openedExistential) {
@@ -1859,7 +1841,7 @@ namespace {
1859
1841
// type having 'Self' swapped for the appropriate replacement
1860
1842
// type -- usually the base object type.
1861
1843
if (hasDynamicSelf) {
1862
- const auto conversionTy = simplifyType ( adjustedOpenedType) ;
1844
+ const auto conversionTy = adjustedOpenedType;
1863
1845
if (!containerTy->isEqual (conversionTy)) {
1864
1846
result = cs.cacheType (new (context) CovariantReturnConversionExpr (
1865
1847
result, conversionTy));
@@ -1911,9 +1893,10 @@ namespace {
1911
1893
// have side effects, instead of abstracting out a 'self' parameter.
1912
1894
const auto isSuperPartialApplication = needsCurryThunk && isSuper;
1913
1895
if (isSuperPartialApplication) {
1914
- ref = buildSingleCurryThunk (base, declRefExpr,
1915
- cast<AbstractFunctionDecl>(member),
1916
- memberLocator);
1896
+ ref = buildSingleCurryThunk (
1897
+ base, declRefExpr, cast<AbstractFunctionDecl>(member),
1898
+ adjustedOpenedType->castTo <FunctionType>(),
1899
+ memberLocator);
1917
1900
} else if (needsCurryThunk) {
1918
1901
// Another case where we want to build a single closure is when
1919
1902
// we have a partial application of a static member. It is better
@@ -1929,14 +1912,13 @@ namespace {
1929
1912
cs.getType (base));
1930
1913
cs.setType (base, base->getType ());
1931
1914
1932
- auto *closure = buildSingleCurryThunk (
1933
- base, declRefExpr, cast<AbstractFunctionDecl>(member),
1934
- memberLocator);
1935
-
1936
1915
// Skip the code below -- we're not building an extra level of
1937
1916
// call by applying the metatype; instead, the closure we just
1938
1917
// built is the curried reference.
1939
- return closure;
1918
+ return buildSingleCurryThunk (
1919
+ base, declRefExpr, cast<AbstractFunctionDecl>(member),
1920
+ adjustedOpenedType->castTo <FunctionType>(),
1921
+ memberLocator);
1940
1922
} else {
1941
1923
// Add a useless ".self" to avoid downstream diagnostics, in case
1942
1924
// the type ref is still a TypeExpr.
@@ -1967,7 +1949,7 @@ namespace {
1967
1949
1968
1950
auto *closure = buildSingleCurryThunk (
1969
1951
baseRef, declRefExpr, cast<AbstractFunctionDecl>(member),
1970
- simplifyType ( adjustedOpenedType) ->castTo <FunctionType>(),
1952
+ adjustedOpenedType->castTo <FunctionType>(),
1971
1953
memberLocator);
1972
1954
1973
1955
// Wrap the closure in a capture list.
@@ -1994,7 +1976,7 @@ namespace {
1994
1976
// must be downcast to the opened archetype before being erased to the
1995
1977
// subclass existential to cope with the expectations placed
1996
1978
// on 'CovariantReturnConversionExpr'.
1997
- curryThunkTy = simplifyType ( adjustedOpenedType) ->castTo <FunctionType>();
1979
+ curryThunkTy = adjustedOpenedType->castTo <FunctionType>();
1998
1980
} else {
1999
1981
curryThunkTy = adjustedRefTy->castTo <FunctionType>();
2000
1982
@@ -2060,7 +2042,7 @@ namespace {
2060
2042
apply = ConstructorRefCallExpr::create (context, ref, base);
2061
2043
} else if (isUnboundInstanceMember) {
2062
2044
ref = adjustTypeForDeclReference (
2063
- ref, cs.getType (ref), cs. simplifyType ( adjustedOpenedType) ,
2045
+ ref, cs.getType (ref), adjustedOpenedType,
2064
2046
locator);
2065
2047
2066
2048
// Reference to an unbound instance method.
@@ -8876,8 +8858,10 @@ namespace {
8876
8858
rewriteFunction (closure);
8877
8859
8878
8860
if (AnyFunctionRef (closure).hasExternalPropertyWrapperParameters ()) {
8861
+ auto *thunkTy = Rewriter.cs .getType (closure)->castTo <FunctionType>();
8879
8862
return Action::SkipNode (Rewriter.buildSingleCurryThunk (
8880
- closure, closure, Rewriter.cs .getConstraintLocator (closure)));
8863
+ closure, closure, thunkTy,
8864
+ Rewriter.cs .getConstraintLocator (closure)));
8881
8865
}
8882
8866
8883
8867
return Action::SkipNode (closure);
0 commit comments