Skip to content

Commit afe83fe

Browse files
committed
Simple refactors to getSILFunctionTypeForInitAccessor
1 parent 66b38a6 commit afe83fe

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,16 +2868,7 @@ static CanSILFunctionType getSILFunctionTypeForInitAccessor(
28682868
AbstractionPattern origType, CanAnyFunctionType substAccessorType,
28692869
SILExtInfoBuilder extInfoBuilder, const Conventions &conventions,
28702870
SILDeclRef constant) {
2871-
AccessorDecl *accessor = nullptr;
2872-
VarDecl *varDecl = nullptr;
2873-
if (auto *accessorTmp = dyn_cast<AccessorDecl>(constant.getDecl())) {
2874-
accessor = accessorTmp;
2875-
} else {
2876-
varDecl = cast<VarDecl>(constant.getDecl());
2877-
}
2878-
auto declContext =
2879-
accessor ? accessor->getDeclContext() : varDecl->getDeclContext();
2880-
2871+
auto *declContext = constant.getInnermostDeclContext();
28812872
CanGenericSignature genericSig = substAccessorType.getOptGenericSignature();
28822873

28832874
std::optional<TypeConverter::GenericContextRAII> contextRAII;
@@ -2920,7 +2911,7 @@ static CanSILFunctionType getSILFunctionTypeForInitAccessor(
29202911

29212912
// accessed properties appear as `inout` parameters because they could be
29222913
// read from and modified.
2923-
if (accessor) {
2914+
if (auto *accessor = dyn_cast<AccessorDecl>(constant.getDecl())) {
29242915
for (auto *property : accessor->getAccessedProperties()) {
29252916
inputs.push_back(SILParameterInfo(getLoweredTypeOfProperty(property),
29262917
ParameterConvention::Indirect_Inout));
@@ -2929,8 +2920,6 @@ static CanSILFunctionType getSILFunctionTypeForInitAccessor(
29292920

29302921
// Make a new 'self' parameter.
29312922
if (!declContext->isLocalContext()) {
2932-
auto declContext =
2933-
accessor ? accessor->getDeclContext() : varDecl->getDeclContext();
29342923
auto selfInterfaceType =
29352924
MetatypeType::get(declContext->getSelfInterfaceType());
29362925
AbstractionPattern origSelfType(genericSig,
@@ -2945,12 +2934,13 @@ static CanSILFunctionType getSILFunctionTypeForInitAccessor(
29452934

29462935
// initialized properties appear as `@out` results because they are
29472936
// initialized by the accessor.
2948-
if (accessor) {
2937+
if (auto *accessor = dyn_cast<AccessorDecl>(constant.getDecl())) {
29492938
for (auto *property : accessor->getInitializedProperties()) {
29502939
results.push_back(SILResultInfo(getLoweredTypeOfProperty(property),
29512940
ResultConvention::Indirect));
29522941
}
29532942
} else {
2943+
auto *varDecl = dyn_cast<VarDecl>(constant.getDecl());
29542944
auto backingStorage = varDecl->getPropertyWrapperBackingProperty();
29552945
results.push_back(SILResultInfo(getLoweredTypeOfProperty(backingStorage),
29562946
ResultConvention::Indirect));

0 commit comments

Comments
 (0)