@@ -4008,9 +4008,30 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
4008
4008
AbstractStorageDecl *storage,
4009
4009
ResilienceExpansion expansion,
4010
4010
AccessStrategy strategy) {
4011
+ auto getAccessorFunction = [&SGM](AbstractStorageDecl *storage,
4012
+ bool isForeign) -> SILFunction * {
4013
+ // Identify the property using its (unthunked) getter. For a
4014
+ // computed property, this should be stable ABI; for a resilient public
4015
+ // property, this should also be stable ABI across modules.
4016
+ auto representativeDecl = getRepresentativeAccessorForKeyPath (storage);
4017
+ // If the property came from an import-as-member function defined in C,
4018
+ // use the original C function as the key.
4019
+ auto ref =
4020
+ SILDeclRef (representativeDecl, SILDeclRef::Kind::Func, isForeign);
4021
+ // TODO: If the getter has shared linkage (say it's synthesized for a
4022
+ // Clang-imported thing), we'll need some other sort of
4023
+ // stable identifier.
4024
+ return SGM.getFunction (ref, NotForDefinition);
4025
+ };
4026
+
4011
4027
switch (strategy.getKind ()) {
4012
4028
case AccessStrategy::Storage:
4013
- // Identify reabstracted stored properties by the property itself.
4029
+ if (auto decl = cast<VarDecl>(storage); decl->isStatic ()) {
4030
+ // For metatype keypaths, identify property via accessors.
4031
+ return getAccessorFunction (storage, /* isForeign=*/ false );
4032
+ }
4033
+ // Otherwise, identify reabstracted stored properties by the property
4034
+ // itself.
4014
4035
return cast<VarDecl>(storage);
4015
4036
case AccessStrategy::MaterializeToTemporary:
4016
4037
// Use the read strategy. But try to avoid turning e.g. an
@@ -4023,19 +4044,9 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
4023
4044
}
4024
4045
LLVM_FALLTHROUGH;
4025
4046
case AccessStrategy::DirectToAccessor: {
4026
- // Identify the property using its (unthunked) getter. For a
4027
- // computed property, this should be stable ABI; for a resilient public
4028
- // property, this should also be stable ABI across modules.
4029
- auto representativeDecl = getRepresentativeAccessorForKeyPath (storage);
4030
- // If the property came from an import-as-member function defined in C,
4031
- // use the original C function as the key.
4032
- bool isForeign = representativeDecl->isImportAsMember ();
4033
- auto getterRef = SILDeclRef (representativeDecl,
4034
- SILDeclRef::Kind::Func, isForeign);
4035
- // TODO: If the getter has shared linkage (say it's synthesized for a
4036
- // Clang-imported thing), we'll need some other sort of
4037
- // stable identifier.
4038
- return SGM.getFunction (getterRef, NotForDefinition);
4047
+ return getAccessorFunction (
4048
+ storage,
4049
+ getRepresentativeAccessorForKeyPath (storage)->isImportAsMember ());
4039
4050
}
4040
4051
case AccessStrategy::DispatchToAccessor: {
4041
4052
// Identify the property by its vtable or wtable slot.
0 commit comments