@@ -1557,11 +1557,11 @@ class DestructureInputs {
1557
1557
unsigned numEltTypes = params.size ();
1558
1558
1559
1559
bool hasSelf =
1560
- (extInfoBuilder.hasSelfParam () || Foreign.Self .isImportAsMember ());
1560
+ (extInfoBuilder.hasSelfParam () || Foreign.self .isImportAsMember ());
1561
1561
unsigned numNonSelfParams = (hasSelf ? numEltTypes - 1 : numEltTypes);
1562
1562
TopLevelOrigType = origType;
1563
1563
// If we have a foreign-self, install handleSelf as the handler.
1564
- if (Foreign.Self .isInstance ()) {
1564
+ if (Foreign.self .isInstance ()) {
1565
1565
assert (hasSelf && numEltTypes > 0 );
1566
1566
ForeignSelf = ForeignSelfInfo{origType.getFunctionParamType (numNonSelfParams),
1567
1567
params[numNonSelfParams]};
@@ -1582,7 +1582,7 @@ class DestructureInputs {
1582
1582
1583
1583
// Process the self parameter. Note that we implicitly drop self
1584
1584
// if this is a static foreign-self import.
1585
- if (hasSelf && !Foreign.Self .isImportAsMember ()) {
1585
+ if (hasSelf && !Foreign.self .isImportAsMember ()) {
1586
1586
auto selfParam = params[numNonSelfParams];
1587
1587
auto ty = selfParam.getParameterType ();
1588
1588
auto eltPattern = origType.getFunctionParamType (numNonSelfParams);
@@ -1670,12 +1670,13 @@ class DestructureInputs {
1670
1670
}
1671
1671
1672
1672
bool maybeAddForeignAsyncParameter () {
1673
- if (!Foreign.Async
1674
- || NextOrigParamIndex != Foreign.Async ->completionHandlerParamIndex ())
1673
+ if (!Foreign.async ||
1674
+ NextOrigParamIndex != Foreign.async ->completionHandlerParamIndex ())
1675
1675
return false ;
1676
-
1677
- CanType foreignCHTy = TopLevelOrigType
1678
- .getObjCMethodAsyncCompletionHandlerForeignType (Foreign.Async .getValue (), TC);
1676
+
1677
+ CanType foreignCHTy =
1678
+ TopLevelOrigType.getObjCMethodAsyncCompletionHandlerForeignType (
1679
+ Foreign.async .getValue (), TC);
1679
1680
auto completionHandlerOrigTy = TopLevelOrigType.getObjCMethodAsyncCompletionHandlerType (foreignCHTy);
1680
1681
auto completionHandlerTy = TC.getLoweredType (completionHandlerOrigTy,
1681
1682
foreignCHTy, expansion)
@@ -1687,17 +1688,12 @@ class DestructureInputs {
1687
1688
}
1688
1689
1689
1690
bool maybeAddForeignErrorParameter () {
1690
- // A foreign async convention absorbs any error parameter, making it into
1691
- // an argument to the callback.
1692
- if (Foreign.Async )
1693
- return false ;
1694
-
1695
- if (!Foreign.Error ||
1696
- NextOrigParamIndex != Foreign.Error ->getErrorParameterIndex ())
1691
+ if (!Foreign.error ||
1692
+ NextOrigParamIndex != Foreign.error ->getErrorParameterIndex ())
1697
1693
return false ;
1698
1694
1699
1695
auto foreignErrorTy = TC.getLoweredRValueType (
1700
- expansion, Foreign.Error ->getErrorParameterType ());
1696
+ expansion, Foreign.error ->getErrorParameterType ());
1701
1697
1702
1698
// Assume the error parameter doesn't have interesting lowering.
1703
1699
Inputs.push_back (SILParameterInfo (foreignErrorTy,
@@ -1707,8 +1703,8 @@ class DestructureInputs {
1707
1703
}
1708
1704
1709
1705
bool maybeAddForeignSelfParameter () {
1710
- if (!Foreign.Self .isInstance () ||
1711
- NextOrigParamIndex != Foreign.Self .getSelfIndex ())
1706
+ if (!Foreign.self .isInstance () ||
1707
+ NextOrigParamIndex != Foreign.self .getSelfIndex ())
1712
1708
return false ;
1713
1709
1714
1710
if (ForeignSelf) {
@@ -1759,27 +1755,27 @@ void updateResultTypeForForeignInfo(
1759
1755
const ForeignInfo &foreignInfo, CanGenericSignature genericSig,
1760
1756
AbstractionPattern &origResultType, CanType &substFormalResultType) {
1761
1757
// If there's no error or async convention, the return type is unchanged.
1762
- if (!foreignInfo.Async && !foreignInfo.Error ) {
1758
+ if (!foreignInfo.async && !foreignInfo.error ) {
1763
1759
return ;
1764
1760
}
1765
-
1766
- // A foreign async convention means our lowered return type is Void, since
1767
- // the imported semantic return and/or error type map to the completion
1768
- // callback's argument(s).
1769
- auto &C = substFormalResultType-> getASTContext ();
1770
- if ( auto async = foreignInfo. Async ) {
1761
+
1762
+ // A foreign async convention without an error convention means our lowered
1763
+ // return type is Void, since the imported semantic return map to the
1764
+ // completion callback's argument(s).
1765
+ if (!foreignInfo. error ) {
1766
+ auto &C = substFormalResultType-> getASTContext ();
1771
1767
substFormalResultType = TupleType::getEmpty (C);
1772
1768
origResultType = AbstractionPattern (genericSig, substFormalResultType);
1773
1769
return ;
1774
1770
}
1775
-
1771
+
1776
1772
// Otherwise, adjust the return type to match the foreign error convention.
1777
- auto convention = *foreignInfo.Error ;
1773
+ auto convention = *foreignInfo.error ;
1778
1774
switch (convention.getKind ()) {
1779
1775
// These conventions replace the result type.
1780
1776
case ForeignErrorConvention::ZeroResult:
1781
1777
case ForeignErrorConvention::NonZeroResult:
1782
- assert (substFormalResultType->isVoid ());
1778
+ assert (substFormalResultType->isVoid () || foreignInfo. async );
1783
1779
substFormalResultType = convention.getResultType ();
1784
1780
origResultType = AbstractionPattern (genericSig, substFormalResultType);
1785
1781
return ;
@@ -2086,27 +2082,25 @@ static CanSILFunctionType getSILFunctionType(
2086
2082
2087
2083
Optional<SILResultInfo> errorResult;
2088
2084
assert (
2089
- (!foreignInfo.Error || substFnInterfaceType->getExtInfo ().isThrowing ())
2090
- && " foreignError was set but function type does not throw?" );
2091
- assert (
2092
- (!foreignInfo.Async || substFnInterfaceType->getExtInfo ().isAsync ())
2093
- && " foreignAsync was set but function type is not async?" );
2085
+ (!foreignInfo.error || substFnInterfaceType->getExtInfo ().isThrowing ()) &&
2086
+ " foreignError was set but function type does not throw?" );
2087
+ assert ((!foreignInfo.async || substFnInterfaceType->getExtInfo ().isAsync ()) &&
2088
+ " foreignAsync was set but function type is not async?" );
2094
2089
2095
2090
// Map '@Sendable' to the appropriate `@Sendable` modifier.
2096
2091
bool isSendable = substFnInterfaceType->getExtInfo ().isSendable ();
2097
2092
2098
2093
// Map 'async' to the appropriate `@async` modifier.
2099
2094
bool isAsync = false ;
2100
- if (substFnInterfaceType->getExtInfo ().isAsync () && !foreignInfo.Async ) {
2095
+ if (substFnInterfaceType->getExtInfo ().isAsync () && !foreignInfo.async ) {
2101
2096
assert (!origType.isForeign ()
2102
2097
&& " using native Swift async for foreign type!" );
2103
2098
isAsync = true ;
2104
2099
}
2105
-
2100
+
2106
2101
// Map 'throws' to the appropriate error convention.
2107
- if (substFnInterfaceType->getExtInfo ().isThrowing ()
2108
- && !foreignInfo.Error
2109
- && !foreignInfo.Async ) {
2102
+ if (substFnInterfaceType->getExtInfo ().isThrowing () && !foreignInfo.error &&
2103
+ !foreignInfo.async ) {
2110
2104
assert (!origType.isForeign ()
2111
2105
&& " using native Swift error convention for foreign type!" );
2112
2106
SILType exnType = SILType::getExceptionType (TC.Context );
@@ -2892,20 +2886,21 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
2892
2886
SILExtInfoBuilder extInfoBuilder, const ForeignInfo &foreignInfo,
2893
2887
Optional<SILDeclRef> constant) {
2894
2888
if (auto method = dyn_cast<clang::ObjCMethodDecl>(clangDecl)) {
2895
- auto origPattern =
2896
- AbstractionPattern::getObjCMethod (origType, method,
2897
- foreignInfo.Error ,
2898
- foreignInfo.Async );
2889
+ auto origPattern = AbstractionPattern::getObjCMethod (
2890
+ origType, method, foreignInfo.error , foreignInfo.async );
2899
2891
return getSILFunctionType (
2900
2892
TC, TypeExpansionContext::minimal (), origPattern, substInterfaceType,
2901
2893
extInfoBuilder, ObjCMethodConventions (method), foreignInfo, constant,
2902
2894
constant, None, ProtocolConformanceRef ());
2903
2895
}
2904
2896
2905
2897
if (auto method = dyn_cast<clang::CXXMethodDecl>(clangDecl)) {
2906
- AbstractionPattern origPattern = method->isOverloadedOperator () ?
2907
- AbstractionPattern::getCXXOperatorMethod (origType, method, foreignInfo.Self ):
2908
- AbstractionPattern::getCXXMethod (origType, method, foreignInfo.Self );
2898
+ AbstractionPattern origPattern =
2899
+ method->isOverloadedOperator ()
2900
+ ? AbstractionPattern::getCXXOperatorMethod (origType, method,
2901
+ foreignInfo.self )
2902
+ : AbstractionPattern::getCXXMethod (origType, method,
2903
+ foreignInfo.self );
2909
2904
bool isMutating =
2910
2905
TC.Context .getClangModuleLoader ()->isCXXMethodMutating (method);
2911
2906
auto conventions = CXXMethodConventions (method, isMutating);
@@ -2918,10 +2913,10 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
2918
2913
if (auto func = dyn_cast<clang::FunctionDecl>(clangDecl)) {
2919
2914
auto clangType = func->getType ().getTypePtr ();
2920
2915
AbstractionPattern origPattern =
2921
- foreignInfo.Self .isImportAsMember ()
2922
- ? AbstractionPattern::getCFunctionAsMethod (origType, clangType,
2923
- foreignInfo.Self )
2924
- : AbstractionPattern (origType, clangType);
2916
+ foreignInfo.self .isImportAsMember ()
2917
+ ? AbstractionPattern::getCFunctionAsMethod (origType, clangType,
2918
+ foreignInfo.self )
2919
+ : AbstractionPattern (origType, clangType);
2925
2920
return getSILFunctionType (TC, TypeExpansionContext::minimal (), origPattern,
2926
2921
substInterfaceType, extInfoBuilder,
2927
2922
CFunctionConventions (func), foreignInfo, constant,
@@ -3214,10 +3209,10 @@ static CanSILFunctionType getUncachedSILFunctionTypeForConstant(
3214
3209
// import-as-member but do involve the same gymnastics with the
3215
3210
// formal type. That's all that SILFunctionType cares about, so
3216
3211
// pretend that it's import-as-member.
3217
- if (!foreignInfo.Self .isImportAsMember () &&
3212
+ if (!foreignInfo.self .isImportAsMember () &&
3218
3213
isImporterGeneratedAccessor (clangDecl, constant)) {
3219
3214
unsigned selfIndex = cast<AccessorDecl>(decl)->isSetter () ? 1 : 0 ;
3220
- foreignInfo.Self .setSelfIndex (selfIndex);
3215
+ foreignInfo.self .setSelfIndex (selfIndex);
3221
3216
}
3222
3217
3223
3218
return getSILFunctionTypeForClangDecl (
0 commit comments