[SILDeclRef] RuntimeMetadata: Add a special kind for runtime attribute generator

A new `RuntimeAttributeGenerator` is used to reference runtime
attribute generator functions synthesized by SILGen.
`#function` magic literal points to the declaration that declaration
attribute is attached to.
This commit is contained in:
Pavel Yaskevich
2022-12-01 16:19:45 -08:00
parent 91042d77aa
commit b83b0943b5
11 changed files with 106 additions and 20 deletions

View File

@@ -1135,6 +1135,21 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
postEmitFunction(constant, f);
return;
}
case SILDeclRef::Kind::RuntimeAttributeGenerator: {
auto *decl = constant.getDecl();
auto *attr = constant.pointer.get<CustomAttr *>();
auto *DC = decl->getDeclContext()->getParentSourceFile();
Expr *generator = decl->getRuntimeDiscoverableAttributeGenerator(attr);
auto loc = RegularLocation::getAutoGeneratedLocation(generator);
preEmitFunction(constant, f, loc);
PrettyStackTraceSILFunction X("silgen emitRuntimeAttributeGenerator ", f);
SILGenFunction SGF(*this, *f, DC);
SGF.emitGeneratorFunction(constant, generator);
postEmitFunction(constant, f);
break;
}
}
}
@@ -2210,9 +2225,9 @@ public:
for (auto *D : sf->getDeclsWithRuntimeDiscoverableAttrs()) {
for (auto *attr : D->getRuntimeDiscoverableAttrs()) {
auto *generator = D->getRuntimeDiscoverableAttributeGenerator(attr);
assert(generator);
emitSILFunctionDefinition(SILDeclRef(generator).asRuntimeAccessible());
emitSILFunctionDefinition(
SILDeclRef::getRuntimeAttributeGenerator(attr, D)
.asRuntimeAccessible());
}
}