Skip to content

Commit 698a99e

Browse files
committed
Start serializing @_implements attribute
@_implements is in this odd state where it is dropped from serialization, but persists everywhere else. Keep it in the serialized modules.
1 parent ece521c commit 698a99e

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ SIMPLE_DECL_ATTR(GKInspectable, GKInspectable,
235235
OnVar | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
236236
66)
237237
DECL_ATTR(_implements, Implements,
238-
OnFunc | OnAccessor | OnVar | OnSubscript | OnTypeAlias | UserInaccessible | NotSerialized | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
238+
OnFunc | OnAccessor | OnVar | OnSubscript | OnTypeAlias | UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
239239
67)
240240
DECL_ATTR(_objcRuntimeName, ObjCRuntimeName,
241241
OnClass | UserInaccessible | NotSerialized | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,

lib/Serialization/Deserialization.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,6 +5440,47 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
54405440
break;
54415441
}
54425442

5443+
case decls_block::Implements_DECL_ATTR: {
5444+
bool isImplicit;
5445+
DeclContextID contextID;
5446+
DeclID protocolID;
5447+
unsigned numNameComponentsBiased;
5448+
ArrayRef<uint64_t> nameIDs;
5449+
serialization::decls_block::ImplementsDeclAttrLayout::readRecord(
5450+
scratch, isImplicit, contextID, protocolID, numNameComponentsBiased,
5451+
nameIDs);
5452+
5453+
// Resolve the context.
5454+
auto dcOrError = MF.getDeclContextChecked(contextID);
5455+
if (!dcOrError)
5456+
return dcOrError.takeError();
5457+
DeclContext *dc = dcOrError.get();
5458+
5459+
// Resolve the member name.
5460+
DeclName memberName;
5461+
Identifier baseName = MF.getIdentifier(nameIDs.front());
5462+
if (numNameComponentsBiased != 0) {
5463+
SmallVector<Identifier, 2> names;
5464+
for (auto nameID : nameIDs.slice(1, numNameComponentsBiased-1)) {
5465+
names.push_back(MF.getIdentifier(nameID));
5466+
}
5467+
memberName = DeclName(ctx, baseName, names);
5468+
} else {
5469+
memberName = baseName;
5470+
}
5471+
5472+
Expected<Decl *> protocolOrError = MF.getDeclChecked(protocolID);
5473+
ProtocolDecl *protocol;
5474+
if (protocolOrError) {
5475+
protocol = cast<ProtocolDecl>(protocolOrError.get());
5476+
} else {
5477+
return protocolOrError.takeError();
5478+
}
5479+
5480+
Attr = ImplementsAttr::create(dc, protocol, memberName);
5481+
break;
5482+
}
5483+
54435484
case decls_block::CDecl_DECL_ATTR: {
54445485
bool isImplicit;
54455486
serialization::decls_block::CDeclDeclAttrLayout::readRecord(

lib/Serialization/ModuleFormat.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 838; // transferring param
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 839; // @_implements
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -2087,6 +2087,16 @@ namespace decls_block {
20872087
BCBlob // _silgen_name
20882088
>;
20892089

2090+
using ImplementsDeclAttrLayout = BCRecordLayout<
2091+
Implements_DECL_ATTR,
2092+
BCFixed<1>, // implicit flag
2093+
DeclContextIDField,// context decl
2094+
DeclIDField, // protocol
2095+
BCVBR<5>, // 0 for a simple name, otherwise the number of parameter name
2096+
// components plus one
2097+
BCArray<IdentifierIDField> // name components
2098+
>;
2099+
20902100
using SPIAccessControlDeclAttrLayout = BCRecordLayout<
20912101
SPIAccessControl_DECL_ATTR,
20922102
BCArray<IdentifierIDField> // SPI names
@@ -2183,7 +2193,6 @@ namespace decls_block {
21832193
using ObjCBridgedDeclAttrLayout = BCRecordLayout<ObjCBridged_DECL_ATTR>;
21842194
using SynthesizedProtocolDeclAttrLayout
21852195
= BCRecordLayout<SynthesizedProtocol_DECL_ATTR>;
2186-
using ImplementsDeclAttrLayout = BCRecordLayout<Implements_DECL_ATTR>;
21872196
using ObjCRuntimeNameDeclAttrLayout
21882197
= BCRecordLayout<ObjCRuntimeName_DECL_ATTR>;
21892198
using RestatedObjCConformanceDeclAttrLayout

lib/Serialization/Serialization.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,6 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
26812681
case DAK_SetterAccess:
26822682
case DAK_ObjCBridged:
26832683
case DAK_SynthesizedProtocol:
2684-
case DAK_Implements:
26852684
case DAK_ObjCRuntimeName:
26862685
case DAK_RestatedObjCConformance:
26872686
case DAK_ClangImporterSynthesizedType:
@@ -2709,6 +2708,29 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
27092708
return;
27102709
}
27112710

2711+
case DAK_Implements: {
2712+
auto *theAttr = cast<ImplementsAttr>(DA);
2713+
auto abbrCode = S.DeclTypeAbbrCodes[ImplementsDeclAttrLayout::Code];
2714+
2715+
DeclName memberName = theAttr->getMemberName();
2716+
SmallVector<IdentifierID, 4> nameComponents;
2717+
nameComponents.push_back(
2718+
S.addDeclBaseNameRef(memberName.getBaseName()));
2719+
for (auto argName : memberName.getArgumentNames())
2720+
nameComponents.push_back(S.addDeclBaseNameRef(argName));
2721+
2722+
auto dc = D->getDeclContext();
2723+
ImplementsDeclAttrLayout::emitRecord(
2724+
S.Out, S.ScratchRecord, abbrCode,
2725+
theAttr->isImplicit(),
2726+
S.addDeclContextRef(dc).getOpaqueValue(),
2727+
S.addDeclRef(theAttr->getProtocol(dc)),
2728+
memberName.getArgumentNames().size() +
2729+
memberName.isCompoundName(),
2730+
nameComponents);
2731+
return;
2732+
}
2733+
27122734
case DAK_CDecl: {
27132735
auto *theAttr = cast<CDeclAttr>(DA);
27142736
auto abbrCode = S.DeclTypeAbbrCodes[CDeclDeclAttrLayout::Code];

0 commit comments

Comments
 (0)