Skip to content

Commit 3ad67ab

Browse files
committed
[NFC] Used ForeignInfo for CalleeTypeInfo::ForeignInfo.
The two were identical and had identical fields except that ForeignInfo still used initial capitalization for its field names. The type nested within CalleeTypeInfo is removed and the leading caps are removed from the top level ForeignInfo type.
1 parent a51b650 commit 3ad67ab

File tree

4 files changed

+78
-96
lines changed

4 files changed

+78
-96
lines changed

include/swift/AST/ForeignInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
namespace swift {
2727

2828
struct ForeignInfo {
29-
ImportAsMemberStatus Self;
30-
Optional<ForeignErrorConvention> Error;
31-
Optional<ForeignAsyncConvention> Async;
29+
ImportAsMemberStatus self;
30+
Optional<ForeignErrorConvention> error;
31+
Optional<ForeignAsyncConvention> async;
3232
};
3333

3434
} // end namespace swift

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,11 +1557,11 @@ class DestructureInputs {
15571557
unsigned numEltTypes = params.size();
15581558

15591559
bool hasSelf =
1560-
(extInfoBuilder.hasSelfParam() || Foreign.Self.isImportAsMember());
1560+
(extInfoBuilder.hasSelfParam() || Foreign.self.isImportAsMember());
15611561
unsigned numNonSelfParams = (hasSelf ? numEltTypes - 1 : numEltTypes);
15621562
TopLevelOrigType = origType;
15631563
// If we have a foreign-self, install handleSelf as the handler.
1564-
if (Foreign.Self.isInstance()) {
1564+
if (Foreign.self.isInstance()) {
15651565
assert(hasSelf && numEltTypes > 0);
15661566
ForeignSelf = ForeignSelfInfo{origType.getFunctionParamType(numNonSelfParams),
15671567
params[numNonSelfParams]};
@@ -1582,7 +1582,7 @@ class DestructureInputs {
15821582

15831583
// Process the self parameter. Note that we implicitly drop self
15841584
// if this is a static foreign-self import.
1585-
if (hasSelf && !Foreign.Self.isImportAsMember()) {
1585+
if (hasSelf && !Foreign.self.isImportAsMember()) {
15861586
auto selfParam = params[numNonSelfParams];
15871587
auto ty = selfParam.getParameterType();
15881588
auto eltPattern = origType.getFunctionParamType(numNonSelfParams);
@@ -1670,12 +1670,13 @@ class DestructureInputs {
16701670
}
16711671

16721672
bool maybeAddForeignAsyncParameter() {
1673-
if (!Foreign.Async
1674-
|| NextOrigParamIndex != Foreign.Async->completionHandlerParamIndex())
1673+
if (!Foreign.async ||
1674+
NextOrigParamIndex != Foreign.async->completionHandlerParamIndex())
16751675
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);
16791680
auto completionHandlerOrigTy = TopLevelOrigType.getObjCMethodAsyncCompletionHandlerType(foreignCHTy);
16801681
auto completionHandlerTy = TC.getLoweredType(completionHandlerOrigTy,
16811682
foreignCHTy, expansion)
@@ -1689,15 +1690,15 @@ class DestructureInputs {
16891690
bool maybeAddForeignErrorParameter() {
16901691
// A foreign async convention absorbs any error parameter, making it into
16911692
// an argument to the callback.
1692-
if (Foreign.Async)
1693+
if (Foreign.async)
16931694
return false;
1694-
1695-
if (!Foreign.Error ||
1696-
NextOrigParamIndex != Foreign.Error->getErrorParameterIndex())
1695+
1696+
if (!Foreign.error ||
1697+
NextOrigParamIndex != Foreign.error->getErrorParameterIndex())
16971698
return false;
16981699

16991700
auto foreignErrorTy = TC.getLoweredRValueType(
1700-
expansion, Foreign.Error->getErrorParameterType());
1701+
expansion, Foreign.error->getErrorParameterType());
17011702

17021703
// Assume the error parameter doesn't have interesting lowering.
17031704
Inputs.push_back(SILParameterInfo(foreignErrorTy,
@@ -1707,8 +1708,8 @@ class DestructureInputs {
17071708
}
17081709

17091710
bool maybeAddForeignSelfParameter() {
1710-
if (!Foreign.Self.isInstance() ||
1711-
NextOrigParamIndex != Foreign.Self.getSelfIndex())
1711+
if (!Foreign.self.isInstance() ||
1712+
NextOrigParamIndex != Foreign.self.getSelfIndex())
17121713
return false;
17131714

17141715
if (ForeignSelf) {
@@ -1759,22 +1760,22 @@ void updateResultTypeForForeignInfo(
17591760
const ForeignInfo &foreignInfo, CanGenericSignature genericSig,
17601761
AbstractionPattern &origResultType, CanType &substFormalResultType) {
17611762
// If there's no error or async convention, the return type is unchanged.
1762-
if (!foreignInfo.Async && !foreignInfo.Error) {
1763+
if (!foreignInfo.async && !foreignInfo.error) {
17631764
return;
17641765
}
1765-
1766+
17661767
// A foreign async convention means our lowered return type is Void, since
17671768
// the imported semantic return and/or error type map to the completion
17681769
// callback's argument(s).
17691770
auto &C = substFormalResultType->getASTContext();
1770-
if (auto async = foreignInfo.Async) {
1771+
if (auto async = foreignInfo.async) {
17711772
substFormalResultType = TupleType::getEmpty(C);
17721773
origResultType = AbstractionPattern(genericSig, substFormalResultType);
17731774
return;
17741775
}
1775-
1776+
17761777
// Otherwise, adjust the return type to match the foreign error convention.
1777-
auto convention = *foreignInfo.Error;
1778+
auto convention = *foreignInfo.error;
17781779
switch (convention.getKind()) {
17791780
// These conventions replace the result type.
17801781
case ForeignErrorConvention::ZeroResult:
@@ -2086,27 +2087,25 @@ static CanSILFunctionType getSILFunctionType(
20862087

20872088
Optional<SILResultInfo> errorResult;
20882089
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?");
2090+
(!foreignInfo.error || substFnInterfaceType->getExtInfo().isThrowing()) &&
2091+
"foreignError was set but function type does not throw?");
2092+
assert((!foreignInfo.async || substFnInterfaceType->getExtInfo().isAsync()) &&
2093+
"foreignAsync was set but function type is not async?");
20942094

20952095
// Map '@Sendable' to the appropriate `@Sendable` modifier.
20962096
bool isSendable = substFnInterfaceType->getExtInfo().isSendable();
20972097

20982098
// Map 'async' to the appropriate `@async` modifier.
20992099
bool isAsync = false;
2100-
if (substFnInterfaceType->getExtInfo().isAsync() && !foreignInfo.Async) {
2100+
if (substFnInterfaceType->getExtInfo().isAsync() && !foreignInfo.async) {
21012101
assert(!origType.isForeign()
21022102
&& "using native Swift async for foreign type!");
21032103
isAsync = true;
21042104
}
2105-
2105+
21062106
// Map 'throws' to the appropriate error convention.
2107-
if (substFnInterfaceType->getExtInfo().isThrowing()
2108-
&& !foreignInfo.Error
2109-
&& !foreignInfo.Async) {
2107+
if (substFnInterfaceType->getExtInfo().isThrowing() && !foreignInfo.error &&
2108+
!foreignInfo.async) {
21102109
assert(!origType.isForeign()
21112110
&& "using native Swift error convention for foreign type!");
21122111
SILType exnType = SILType::getExceptionType(TC.Context);
@@ -2892,20 +2891,21 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
28922891
SILExtInfoBuilder extInfoBuilder, const ForeignInfo &foreignInfo,
28932892
Optional<SILDeclRef> constant) {
28942893
if (auto method = dyn_cast<clang::ObjCMethodDecl>(clangDecl)) {
2895-
auto origPattern =
2896-
AbstractionPattern::getObjCMethod(origType, method,
2897-
foreignInfo.Error,
2898-
foreignInfo.Async);
2894+
auto origPattern = AbstractionPattern::getObjCMethod(
2895+
origType, method, foreignInfo.error, foreignInfo.async);
28992896
return getSILFunctionType(
29002897
TC, TypeExpansionContext::minimal(), origPattern, substInterfaceType,
29012898
extInfoBuilder, ObjCMethodConventions(method), foreignInfo, constant,
29022899
constant, None, ProtocolConformanceRef());
29032900
}
29042901

29052902
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);
2903+
AbstractionPattern origPattern =
2904+
method->isOverloadedOperator()
2905+
? AbstractionPattern::getCXXOperatorMethod(origType, method,
2906+
foreignInfo.self)
2907+
: AbstractionPattern::getCXXMethod(origType, method,
2908+
foreignInfo.self);
29092909
bool isMutating =
29102910
TC.Context.getClangModuleLoader()->isCXXMethodMutating(method);
29112911
auto conventions = CXXMethodConventions(method, isMutating);
@@ -2918,10 +2918,10 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
29182918
if (auto func = dyn_cast<clang::FunctionDecl>(clangDecl)) {
29192919
auto clangType = func->getType().getTypePtr();
29202920
AbstractionPattern origPattern =
2921-
foreignInfo.Self.isImportAsMember()
2922-
? AbstractionPattern::getCFunctionAsMethod(origType, clangType,
2923-
foreignInfo.Self)
2924-
: AbstractionPattern(origType, clangType);
2921+
foreignInfo.self.isImportAsMember()
2922+
? AbstractionPattern::getCFunctionAsMethod(origType, clangType,
2923+
foreignInfo.self)
2924+
: AbstractionPattern(origType, clangType);
29252925
return getSILFunctionType(TC, TypeExpansionContext::minimal(), origPattern,
29262926
substInterfaceType, extInfoBuilder,
29272927
CFunctionConventions(func), foreignInfo, constant,
@@ -3214,10 +3214,10 @@ static CanSILFunctionType getUncachedSILFunctionTypeForConstant(
32143214
// import-as-member but do involve the same gymnastics with the
32153215
// formal type. That's all that SILFunctionType cares about, so
32163216
// pretend that it's import-as-member.
3217-
if (!foreignInfo.Self.isImportAsMember() &&
3217+
if (!foreignInfo.self.isImportAsMember() &&
32183218
isImporterGeneratedAccessor(clangDecl, constant)) {
32193219
unsigned selfIndex = cast<AccessorDecl>(decl)->isSetter() ? 1 : 0;
3220-
foreignInfo.Self.setSelfIndex(selfIndex);
3220+
foreignInfo.self.setSelfIndex(selfIndex);
32213221
}
32223222

32233223
return getSILFunctionTypeForClangDecl(

lib/SILGen/Callee.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/AST/ForeignAsyncConvention.h"
1717
#include "swift/AST/ForeignErrorConvention.h"
18+
#include "swift/AST/ForeignInfo.h"
1819
#include "swift/AST/Types.h"
1920
#include "swift/SIL/AbstractionPattern.h"
2021

@@ -27,11 +28,6 @@ class CalleeTypeInfo {
2728
CanSILFunctionType substFnType;
2829
Optional<AbstractionPattern> origResultType;
2930
CanType substResultType;
30-
struct ForeignInfo {
31-
Optional<ForeignErrorConvention> error;
32-
Optional<ForeignAsyncConvention> async;
33-
ImportAsMemberStatus self;
34-
};
3531
ForeignInfo foreign;
3632

3733
private:
@@ -48,8 +44,8 @@ class CalleeTypeInfo {
4844
Optional<SILFunctionTypeRepresentation> overrideRep = None)
4945
: origFormalType(llvm::None), substFnType(substFnType),
5046
origResultType(origResultType),
51-
substResultType(substResultType), foreign{foreignError, foreignAsync,
52-
foreignSelf},
47+
substResultType(substResultType), foreign{foreignSelf, foreignError,
48+
foreignAsync},
5349
overrideRep(overrideRep) {}
5450

5551
CalleeTypeInfo(CanSILFunctionType substFnType,

0 commit comments

Comments
 (0)