mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Parse and serialize @abi attribute
This attribute will allow you to specify an alternate version of the declaration used for mangling. It will allow minor adjustments to be made to declarations so long as they’re still compatible at the calling convention level, such as refining isolation or sendability, renaming without breaking ABI, etc. The attribute is behind the experimental feature flag `ABIAttribute`.
This commit is contained in:
@@ -2885,6 +2885,15 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
}
|
||||
#include "swift/AST/DeclAttr.def"
|
||||
|
||||
case DeclAttrKind::ABI: {
|
||||
auto *theAttr = cast<ABIAttr>(DA);
|
||||
auto abbrCode = S.DeclTypeAbbrCodes[ABIDeclAttrLayout::Code];
|
||||
auto abiDeclID = S.addDeclRef(theAttr->abiDecl);
|
||||
ABIDeclAttrLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
|
||||
theAttr->isImplicit(), abiDeclID);
|
||||
return;
|
||||
}
|
||||
|
||||
case DeclAttrKind::SILGenName: {
|
||||
auto *theAttr = cast<SILGenNameAttr>(DA);
|
||||
auto abbrCode = S.DeclTypeAbbrCodes[SILGenNameDeclAttrLayout::Code];
|
||||
@@ -4011,6 +4020,10 @@ public:
|
||||
|
||||
writeDeserializationSafety(D);
|
||||
|
||||
auto abiRole = ABIRoleInfo(D);
|
||||
if (!abiRole.providesAPI())
|
||||
writeABIOnlyCounterpart(abiRole.getCounterpartUnchecked());
|
||||
|
||||
// Emit attributes (if any).
|
||||
for (auto Attr : D->getAttrs())
|
||||
writeDeclAttribute(D, Attr);
|
||||
@@ -4031,6 +4044,13 @@ public:
|
||||
ErrorFlagLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode);
|
||||
}
|
||||
|
||||
void writeABIOnlyCounterpart(const Decl *counterpart) {
|
||||
using namespace decls_block;
|
||||
unsigned abbrCode = S.DeclTypeAbbrCodes[ABIOnlyCounterpartLayout::Code];
|
||||
ABIOnlyCounterpartLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
|
||||
S.addDeclRef(counterpart));
|
||||
}
|
||||
|
||||
void noteUseOfExportedPrespecialization(const AbstractFunctionDecl *afd) {
|
||||
bool hasNoted = false;
|
||||
for (auto *A : afd->getAttrs().getAttributes<SpecializeAttr>()) {
|
||||
@@ -6211,6 +6231,7 @@ void Serializer::writeAllDeclsAndTypes() {
|
||||
|
||||
registerDeclTypeAbbr<ErrorFlagLayout>();
|
||||
registerDeclTypeAbbr<ErrorTypeLayout>();
|
||||
registerDeclTypeAbbr<ABIOnlyCounterpartLayout>();
|
||||
|
||||
registerDeclTypeAbbr<ClangTypeLayout>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user