Skip to content

Commit d6c59cc

Browse files
committed
SILGen: Fix emission of keypath getter/setter when generic signature has only concrete parameters
We used to crash when creating a function type with a generic signature that has only concrete parameters.
1 parent 65d4199 commit d6c59cc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,10 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
26722672
auto genericSig = genericEnv
26732673
? genericEnv->getGenericSignature()->getCanonicalSignature()
26742674
: nullptr;
2675+
if (genericSig && genericSig->areAllParamsConcrete()) {
2676+
genericSig = nullptr;
2677+
genericEnv = nullptr;
2678+
}
26752679

26762680
// Build the signature of the thunk as expected by the keypath runtime.
26772681
CanType loweredBaseTy, loweredPropTy;
@@ -2801,6 +2805,11 @@ static SILFunction *getOrCreateKeyPathSetter(SILGenModule &SGM,
28012805
? genericEnv->getGenericSignature()->getCanonicalSignature()
28022806
: nullptr;
28032807

2808+
if (genericSig && genericSig->areAllParamsConcrete()) {
2809+
genericSig = nullptr;
2810+
genericEnv = nullptr;
2811+
}
2812+
28042813
// Build the signature of the thunk as expected by the keypath runtime.
28052814
CanType loweredBaseTy, loweredPropTy;
28062815
{
@@ -2957,6 +2966,11 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
29572966
? genericEnv->getGenericSignature()->getCanonicalSignature()
29582967
: nullptr;
29592968

2969+
if (genericSig && genericSig->areAllParamsConcrete()) {
2970+
genericSig = nullptr;
2971+
genericEnv = nullptr;
2972+
}
2973+
29602974
auto &C = SGM.getASTContext();
29612975
auto unsafeRawPointerTy = C.getUnsafeRawPointerDecl()->getDeclaredType()
29622976
->getCanonicalType();

test/SILGen/keypath_property_descriptors.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,17 @@ public struct FixedLayout {
154154
// RESILIENT-LABEL: sil_property #FixedLayout.c (stored_property
155155
public var c: Int
156156
}
157+
158+
public class Foo {}
159+
extension Array where Element == Foo {
160+
public class Bar {
161+
// NONRESILIENT-LABEL: sil_property #Array.Bar.dontCrash<τ_0_0 where τ_0_0 == Foo> (settable_property $Int
162+
public private(set) var dontCrash : Int {
163+
get {
164+
return 10
165+
}
166+
set {
167+
}
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)