Skip to content

Commit ee7c94d

Browse files
committed
[Serialization] InitAccessors: Serialization for @storageRestrictions attribute
(cherry picked from commit 387bcf3)
1 parent bca2aa7 commit ee7c94d

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5399,6 +5399,30 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
53995399
break;
54005400
}
54015401

5402+
case decls_block::StorageRestrictions_DECL_ATTR: {
5403+
unsigned numInitializesProperties;
5404+
ArrayRef<uint64_t> rawPropertyIDs;
5405+
serialization::decls_block::StorageRestrictionsDeclAttrLayout::
5406+
readRecord(scratch, numInitializesProperties, rawPropertyIDs);
5407+
5408+
SmallVector<Identifier> initializes;
5409+
SmallVector<Identifier> accesses;
5410+
5411+
for (unsigned i = 0, n = rawPropertyIDs.size(); i != n; ++i) {
5412+
auto propertyName = MF.getIdentifier(rawPropertyIDs[i]);
5413+
5414+
if (i < numInitializesProperties) {
5415+
initializes.push_back(propertyName);
5416+
} else {
5417+
accesses.push_back(propertyName);
5418+
}
5419+
}
5420+
5421+
Attr = StorageRestrictionsAttr::create(ctx, SourceLoc(), SourceRange(),
5422+
initializes, accesses);
5423+
break;
5424+
}
5425+
54025426
case decls_block::DynamicReplacement_DECL_ATTR: {
54035427
bool isImplicit;
54045428
uint64_t numArgs;

lib/Serialization/ModuleFormat.h

Lines changed: 7 additions & 1 deletion
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 = 789; // extension macros
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 795; // @storageRestrictions attribute
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -2230,6 +2230,12 @@ namespace decls_block {
22302230
BCArray<IdentifierIDField> // initialized properties
22312231
>;
22322232

2233+
using StorageRestrictionsDeclAttrLayout = BCRecordLayout<
2234+
StorageRestrictions_DECL_ATTR,
2235+
BCVBR<16>, // num "initializes" properties
2236+
BCArray<IdentifierIDField> // properties
2237+
>;
2238+
22332239
using DifferentiableDeclAttrLayout = BCRecordLayout<
22342240
Differentiable_DECL_ATTR,
22352241
BCFixed<1>, // Implicit flag.

lib/Serialization/Serialization.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,30 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
29532953
return;
29542954
}
29552955

2956+
case DAK_StorageRestrictions: {
2957+
auto abbrCode = S.DeclTypeAbbrCodes[AccessesDeclAttrLayout::Code];
2958+
auto attr = cast<StorageRestrictionsAttr>(DA);
2959+
2960+
SmallVector<IdentifierID, 4> properties;
2961+
2962+
llvm::transform(attr->getInitializesNames(),
2963+
std::back_inserter(properties),
2964+
[&](Identifier propertyName) {
2965+
return S.addDeclBaseNameRef(propertyName);
2966+
});
2967+
2968+
llvm::transform(attr->getAccessesNames(),
2969+
std::back_inserter(properties),
2970+
[&](Identifier propertyName) {
2971+
return S.addDeclBaseNameRef(propertyName);
2972+
});
2973+
2974+
StorageRestrictionsDeclAttrLayout::emitRecord(
2975+
S.Out, S.ScratchRecord, abbrCode, attr->getNumInitializesProperties(),
2976+
properties);
2977+
return;
2978+
}
2979+
29562980
case DAK_DynamicReplacement: {
29572981
auto abbrCode =
29582982
S.DeclTypeAbbrCodes[DynamicReplacementDeclAttrLayout::Code];

0 commit comments

Comments
 (0)