Skip to content

Commit 1fcb294

Browse files
committed
[SILGen] Add metatype to keypath base type for static properties.
1 parent 3c47a58 commit 1fcb294

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
@@ -71,6 +71,8 @@ class SILProperty : public llvm::ilist_node<SILProperty>,
7171
return Component;
7272
}
7373

74+
CanType getBaseType() const;
75+
7476
void print(SILPrintContext &Ctx) const;
7577
void dump() const;
7678

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7348,24 +7348,39 @@ void SILFunction::verifySILUndefMap() const {
73487348
}
73497349
}
73507350

7351+
CanType SILProperty::getBaseType() const {
7352+
auto *decl = getDecl();
7353+
auto *dc = decl->getInnermostDeclContext();
7354+
7355+
// TODO: base type for global descriptors
7356+
auto sig = dc->getGenericSignatureOfContext();
7357+
auto baseTy =
7358+
dc->getInnermostTypeContext()->getSelfInterfaceType()->getReducedType(
7359+
sig);
7360+
if (decl->isStatic())
7361+
baseTy = CanMetatypeType::get(baseTy);
7362+
7363+
if (sig) {
7364+
auto env = dc->getGenericEnvironmentOfContext();
7365+
baseTy = env->mapTypeIntoContext(baseTy)->getCanonicalType();
7366+
}
7367+
7368+
return baseTy;
7369+
}
7370+
73517371
/// Verify that a property descriptor follows invariants.
73527372
void SILProperty::verify(const SILModule &M) const {
73537373
if (!verificationEnabled(M))
73547374
return;
73557375

73567376
auto *decl = getDecl();
7357-
auto *dc = decl->getInnermostDeclContext();
7358-
7359-
// TODO: base type for global/static descriptors
7360-
auto sig = dc->getGenericSignatureOfContext();
7361-
auto baseTy = dc->getInnermostTypeContext()->getSelfInterfaceType()
7362-
->getReducedType(sig);
7377+
auto sig = decl->getInnermostDeclContext()->getGenericSignatureOfContext();
73637378
auto leafTy = decl->getValueInterfaceType()->getReducedType(sig);
73647379
SubstitutionMap subs;
73657380
if (sig) {
7366-
auto env = dc->getGenericEnvironmentOfContext();
7381+
auto env =
7382+
decl->getInnermostDeclContext()->getGenericEnvironmentOfContext();
73677383
subs = env->getForwardingSubstitutionMap();
7368-
baseTy = env->mapTypeIntoContext(baseTy)->getCanonicalType();
73697384
leafTy = env->mapTypeIntoContext(leafTy)->getCanonicalType();
73707385
}
73717386
bool hasIndices = false;
@@ -7386,6 +7401,7 @@ void SILProperty::verify(const SILModule &M) const {
73867401
auto typeExpansionContext =
73877402
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
73887403
ResilienceExpansion::Maximal);
7404+
auto baseTy = getBaseType();
73897405
verifyKeyPathComponent(const_cast<SILModule&>(M),
73907406
typeExpansionContext,
73917407
getSerializedKind(),

lib/SILGen/SILGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,10 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
19781978
baseTy = decl->getDeclContext()->getSelfInterfaceType()
19791979
->getReducedType(decl->getInnermostDeclContext()
19801980
->getGenericSignatureOfContext());
1981+
1982+
if (decl->isStatic()) {
1983+
baseTy = MetatypeType::get(baseTy);
1984+
}
19811985
} else {
19821986
// TODO: Global variables should eventually be referenceable as
19831987
// key paths from (), viz. baseTy = TupleType::getEmpty(getASTContext());

0 commit comments

Comments
 (0)