Skip to content

Commit 14ef485

Browse files
authored
Merge pull request #30799 from jckarter/keypath-import-as-member
SILGen: Use the original function address as the ID for key paths to import-as-member properties.
2 parents b78ed53 + e5b0ffc commit 14ef485

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,11 +3352,15 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
33523352
// Identify the property using its (unthunked) getter. For a
33533353
// computed property, this should be stable ABI; for a resilient public
33543354
// property, this should also be stable ABI across modules.
3355+
auto representativeDecl = getRepresentativeAccessorForKeyPath(storage);
3356+
// If the property came from an import-as-member function defined in C,
3357+
// use the original C function as the key.
3358+
bool isForeign = representativeDecl->isImportAsMember();
3359+
auto getterRef = SILDeclRef(representativeDecl,
3360+
SILDeclRef::Kind::Func, isForeign);
33553361
// TODO: If the getter has shared linkage (say it's synthesized for a
33563362
// Clang-imported thing), we'll need some other sort of
33573363
// stable identifier.
3358-
auto getterRef = SILDeclRef(getRepresentativeAccessorForKeyPath(storage),
3359-
SILDeclRef::Kind::Func);
33603364
return SGM.getFunction(getterRef, NotForDefinition);
33613365
}
33623366
case AccessStrategy::DispatchToAccessor: {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
typedef struct Butt { } Butt;
3+
4+
extern int ButtSize(const Butt *butt)
5+
__attribute__((swift_name("getter:Butt.size(self:)")));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-emit-silgen %s -import-objc-header %S/Inputs/keypaths_import_as_member.h | %FileCheck %s
2+
3+
// CHECK-LABEL: sil {{.*}} @$s{{.*}}23keyPathToImportedMember
4+
func keyPathToImportedMember() {
5+
// CHECK: keypath $KeyPath<Butt, Int32>, (root $Butt; gettable_property $Int32, id @ButtSize
6+
_ = \Butt.size
7+
}

0 commit comments

Comments
 (0)