Skip to content

Commit 6c108c2

Browse files
committed
[SILGen] Remove duplicated code between computing the lowered
interface type for the two different kinds of property wrapper generator functions.
1 parent 7a35c47 commit 6c108c2

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,37 +2447,20 @@ static CanAnyFunctionType getStoredPropertyInitializerInterfaceType(
24472447
/// (property-type) -> backing-type.
24482448
static CanAnyFunctionType getPropertyWrapperBackingInitializerInterfaceType(
24492449
TypeConverter &TC,
2450-
VarDecl *VD) {
2450+
VarDecl *VD,
2451+
bool fromWrappedValue) {
24512452
CanType resultType =
24522453
VD->getPropertyWrapperBackingPropertyType()->getCanonicalType();
24532454

24542455
auto *DC = VD->getInnermostDeclContext();
2455-
CanType inputType =
2456-
VD->getPropertyWrapperInitValueInterfaceType()->getCanonicalType();
2457-
2458-
auto sig = DC->getGenericSignatureOfContext();
2459-
2460-
AnyFunctionType::Param param(
2461-
inputType, Identifier(),
2462-
ParameterTypeFlags().withValueOwnership(ValueOwnership::Owned));
2463-
// FIXME: Verify ExtInfo state is correct, not working by accident.
2464-
CanAnyFunctionType::ExtInfo info;
2465-
return CanAnyFunctionType::get(getCanonicalSignatureOrNull(sig), {param},
2466-
resultType, info);
2467-
}
2468-
2469-
static CanAnyFunctionType getPropertyWrapperInitFromProjectedValueInterfaceType(TypeConverter &TC,
2470-
VarDecl *VD) {
2471-
CanType resultType =
2472-
VD->getPropertyWrapperBackingPropertyType()->getCanonicalType();
2473-
2474-
Type interfaceType = VD->getPropertyWrapperProjectionVar()->getInterfaceType();
2475-
if (interfaceType->hasArchetype())
2476-
interfaceType = interfaceType->mapTypeOutOfContext();
2477-
2478-
CanType inputType = interfaceType->getCanonicalType();
2456+
CanType inputType;
2457+
if (fromWrappedValue) {
2458+
inputType = VD->getPropertyWrapperInitValueInterfaceType()->getCanonicalType();
2459+
} else {
2460+
Type interfaceType = VD->getPropertyWrapperProjectionVar()->getInterfaceType();
2461+
inputType = interfaceType->getCanonicalType();
2462+
}
24792463

2480-
auto *DC = VD->getInnermostDeclContext();
24812464
auto sig = DC->getGenericSignatureOfContext();
24822465

24832466
AnyFunctionType::Param param(
@@ -2682,11 +2665,9 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
26822665
case SILDeclRef::Kind::StoredPropertyInitializer:
26832666
return getStoredPropertyInitializerInterfaceType(cast<VarDecl>(vd));
26842667
case SILDeclRef::Kind::PropertyWrapperBackingInitializer:
2685-
return getPropertyWrapperBackingInitializerInterfaceType(*this,
2686-
cast<VarDecl>(vd));
26872668
case SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue:
2688-
return getPropertyWrapperInitFromProjectedValueInterfaceType(*this,
2689-
cast<VarDecl>(vd));
2669+
return getPropertyWrapperBackingInitializerInterfaceType(
2670+
*this, cast<VarDecl>(vd), c.kind == SILDeclRef::Kind::PropertyWrapperBackingInitializer);
26902671
case SILDeclRef::Kind::IVarInitializer:
26912672
return getIVarInitDestroyerInterfaceType(cast<ClassDecl>(vd),
26922673
c.isForeign, false);

0 commit comments

Comments
 (0)