Skip to content

Commit 5232bfe

Browse files
committed
[SILGen] Generate IDs for static key path components.
1 parent 1fcb294 commit 5232bfe

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
@@ -4016,9 +4016,30 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
40164016
AbstractStorageDecl *storage,
40174017
ResilienceExpansion expansion,
40184018
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+
40194035
switch (strategy.getKind()) {
40204036
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.
40224043
return cast<VarDecl>(storage);
40234044
case AccessStrategy::MaterializeToTemporary:
40244045
// Use the read strategy. But try to avoid turning e.g. an
@@ -4031,19 +4052,9 @@ getIdForKeyPathComponentComputedProperty(SILGenModule &SGM,
40314052
}
40324053
LLVM_FALLTHROUGH;
40334054
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());
40474058
}
40484059
case AccessStrategy::DispatchToAccessor: {
40494060
// Identify the property by its vtable or wtable slot.

0 commit comments

Comments
 (0)