Skip to content

SILGen: Fix emission of keypath getter/setter when generic signature has only concrete parameters #23467

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
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2672,6 +2672,10 @@ static SILFunction *getOrCreateKeyPathGetter(SILGenModule &SGM,
auto genericSig = genericEnv
? genericEnv->getGenericSignature()->getCanonicalSignature()
: nullptr;
if (genericSig && genericSig->areAllParamsConcrete()) {
genericSig = nullptr;
genericEnv = nullptr;
}

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

if (genericSig && genericSig->areAllParamsConcrete()) {
genericSig = nullptr;
genericEnv = nullptr;
}

// Build the signature of the thunk as expected by the keypath runtime.
CanType loweredBaseTy, loweredPropTy;
{
Expand Down Expand Up @@ -2957,6 +2966,11 @@ getOrCreateKeyPathEqualsAndHash(SILGenModule &SGM,
? genericEnv->getGenericSignature()->getCanonicalSignature()
: nullptr;

if (genericSig && genericSig->areAllParamsConcrete()) {
genericSig = nullptr;
genericEnv = nullptr;
}

auto &C = SGM.getASTContext();
auto unsafeRawPointerTy = C.getUnsafeRawPointerDecl()->getDeclaredType()
->getCanonicalType();
Expand Down
14 changes: 14 additions & 0 deletions test/SILGen/keypath_property_descriptors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,17 @@ public struct FixedLayout {
// RESILIENT-LABEL: sil_property #FixedLayout.c (stored_property
public var c: Int
}

public class Foo {}
extension Array where Element == Foo {
public class Bar {
// NONRESILIENT-LABEL: sil_property #Array.Bar.dontCrash<τ_0_0 where τ_0_0 == Foo> (settable_property $Int
public private(set) var dontCrash : Int {
get {
return 10
}
set {
}
}
}
}