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