Skip to content

Commit f1e25ea

Browse files
committed
[SILGen] Generate IDs for static key path components.
1 parent feaa273 commit f1e25ea

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4008,9 +4008,30 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
40084008
AbstractStorageDecl *storage,
40094009
ResilienceExpansion expansion,
40104010
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+
40114027
switch (strategy.getKind()) {
40124028
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.
40144035
return cast<VarDecl>(storage);
40154036
case AccessStrategy::MaterializeToTemporary:
40164037
// Use the read strategy. But try to avoid turning e.g. an
@@ -4023,19 +4044,9 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
40234044
}
40244045
LLVM_FALLTHROUGH;
40254046
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());
40394050
}
40404051
case AccessStrategy::DispatchToAccessor: {
40414052
// Identify the property by its vtable or wtable slot.

0 commit comments

Comments
 (0)