Skip to content

[NFC] Refactor getNativeSILFunctionType to use a lambda. #33440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions lib/SIL/IR/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,12 @@ static CanSILFunctionType getNativeSILFunctionType(
Optional<SubstitutionMap> reqtSubs,
ProtocolConformanceRef witnessMethodConformance) {
assert(bool(origConstant) == bool(constant));
auto getSILFunctionTypeForConventions =
[&](const Conventions &convs) -> CanSILFunctionType {
return getSILFunctionType(TC, context, origType, substInterfaceType,
extInfo, convs, ForeignInfo(), origConstant,
constant, reqtSubs, witnessMethodConformance);
};
switch (extInfo.getSILRepresentation()) {
case SILFunctionType::Representation::Block:
case SILFunctionType::Representation::CFunctionPointer:
Expand All @@ -2377,42 +2383,29 @@ static CanSILFunctionType getNativeSILFunctionType(
switch (constant ? constant->kind : SILDeclRef::Kind::Func) {
case SILDeclRef::Kind::Initializer:
case SILDeclRef::Kind::EnumElement:
return getSILFunctionType(TC, context, origType, substInterfaceType,
extInfo, DefaultInitializerConventions(),
ForeignInfo(), origConstant, constant, reqtSubs,
witnessMethodConformance);
return getSILFunctionTypeForConventions(DefaultInitializerConventions());
case SILDeclRef::Kind::Allocator:
return getSILFunctionType(TC, context, origType, substInterfaceType,
extInfo, DefaultAllocatorConventions(),
ForeignInfo(), origConstant, constant, reqtSubs,
witnessMethodConformance);
case SILDeclRef::Kind::Func:
return getSILFunctionTypeForConventions(DefaultAllocatorConventions());
case SILDeclRef::Kind::Func: {
// If we have a setter, use the special setter convention. This ensures
// that we take normal parameters at +1.
if (constant && constant->isSetter()) {
return getSILFunctionType(TC, context, origType, substInterfaceType,
extInfo, DefaultSetterConventions(),
ForeignInfo(), origConstant, constant,
reqtSubs, witnessMethodConformance);
return getSILFunctionTypeForConventions(DefaultSetterConventions());
}
LLVM_FALLTHROUGH;
return getSILFunctionTypeForConventions(
DefaultConventions(NormalParameterConvention::Guaranteed));
}
case SILDeclRef::Kind::Destroyer:
case SILDeclRef::Kind::GlobalAccessor:
case SILDeclRef::Kind::DefaultArgGenerator:
case SILDeclRef::Kind::StoredPropertyInitializer:
case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
case SILDeclRef::Kind::IVarInitializer:
case SILDeclRef::Kind::IVarDestroyer: {
auto conv = DefaultConventions(NormalParameterConvention::Guaranteed);
return getSILFunctionType(TC, context, origType, substInterfaceType,
extInfo, conv, ForeignInfo(), origConstant,
constant, reqtSubs, witnessMethodConformance);
}
case SILDeclRef::Kind::IVarDestroyer:
return getSILFunctionTypeForConventions(
DefaultConventions(NormalParameterConvention::Guaranteed));
case SILDeclRef::Kind::Deallocator:
return getSILFunctionType(TC, context, origType, substInterfaceType,
extInfo, DeallocatorConventions(),
ForeignInfo(), origConstant, constant, reqtSubs,
witnessMethodConformance);
return getSILFunctionTypeForConventions(DeallocatorConventions());
}
}
}
Expand Down