Skip to content

Commit feaa273

Browse files
committed
[SILGen] Add metatype to keypath base type for static properties.
1 parent fc9035a commit feaa273

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

include/swift/SIL/SILProperty.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class SILProperty : public llvm::ilist_node<SILProperty>,
6565
return Component;
6666
}
6767

68+
CanType getBaseType() const;
69+
6870
void print(SILPrintContext &Ctx) const;
6971
void dump() const;
7072

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7180,24 +7180,39 @@ void SILFunction::verifySILUndefMap() const {
71807180
}
71817181
}
71827182

7183+
CanType SILProperty::getBaseType() const {
7184+
auto *decl = getDecl();
7185+
auto *dc = decl->getInnermostDeclContext();
7186+
7187+
// TODO: base type for global descriptors
7188+
auto sig = dc->getGenericSignatureOfContext();
7189+
auto baseTy =
7190+
dc->getInnermostTypeContext()->getSelfInterfaceType()->getReducedType(
7191+
sig);
7192+
if (decl->isStatic())
7193+
baseTy = CanMetatypeType::get(baseTy);
7194+
7195+
if (sig) {
7196+
auto env = dc->getGenericEnvironmentOfContext();
7197+
baseTy = env->mapTypeIntoContext(baseTy)->getCanonicalType();
7198+
}
7199+
7200+
return baseTy;
7201+
}
7202+
71837203
/// Verify that a property descriptor follows invariants.
71847204
void SILProperty::verify(const SILModule &M) const {
71857205
if (!verificationEnabled(M))
71867206
return;
71877207

71887208
auto *decl = getDecl();
7189-
auto *dc = decl->getInnermostDeclContext();
7190-
7191-
// TODO: base type for global/static descriptors
7192-
auto sig = dc->getGenericSignatureOfContext();
7193-
auto baseTy = dc->getInnermostTypeContext()->getSelfInterfaceType()
7194-
->getReducedType(sig);
7209+
auto sig = decl->getInnermostDeclContext()->getGenericSignatureOfContext();
71957210
auto leafTy = decl->getValueInterfaceType()->getReducedType(sig);
71967211
SubstitutionMap subs;
71977212
if (sig) {
7198-
auto env = dc->getGenericEnvironmentOfContext();
7213+
auto env =
7214+
decl->getInnermostDeclContext()->getGenericEnvironmentOfContext();
71997215
subs = env->getForwardingSubstitutionMap();
7200-
baseTy = env->mapTypeIntoContext(baseTy)->getCanonicalType();
72017216
leafTy = env->mapTypeIntoContext(leafTy)->getCanonicalType();
72027217
}
72037218
bool hasIndices = false;
@@ -7218,6 +7233,7 @@ void SILProperty::verify(const SILModule &M) const {
72187233
auto typeExpansionContext =
72197234
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
72207235
ResilienceExpansion::Maximal);
7236+
auto baseTy = getBaseType();
72217237
verifyKeyPathComponent(const_cast<SILModule&>(M),
72227238
typeExpansionContext,
72237239
require,

lib/SILGen/SILGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,10 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
19611961
baseTy = decl->getDeclContext()->getSelfInterfaceType()
19621962
->getReducedType(decl->getInnermostDeclContext()
19631963
->getGenericSignatureOfContext());
1964+
1965+
if (decl->isStatic()) {
1966+
baseTy = MetatypeType::get(baseTy);
1967+
}
19641968
} else {
19651969
// TODO: Global variables should eventually be referenceable as
19661970
// key paths from (), viz. baseTy = TupleType::getEmpty(getASTContext());

0 commit comments

Comments
 (0)