Skip to content

Commit a20c31a

Browse files
author
Harlan Haskins
committed
[Serialization] Add @_hasStorage and private(set) while deserializing
1 parent 1345310 commit a20c31a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 468; // Last change: SelfProtocolConformance
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 469; // @_hasStorage
5656

5757
using DeclIDField = BCFixed<31>;
5858

lib/Serialization/Deserialization.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,21 +3019,29 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
30193019

30203020
configureStorage(var, opaqueReadOwnership,
30213021
readImpl, writeImpl, readWriteImpl, accessors);
3022-
3023-
if (auto accessLevel = getActualAccessLevel(rawAccessLevel)) {
3024-
var->setAccess(*accessLevel);
3025-
} else {
3022+
auto accessLevel = getActualAccessLevel(rawAccessLevel);
3023+
if (!accessLevel) {
30263024
error();
30273025
return nullptr;
30283026
}
30293027

3028+
var->setAccess(*accessLevel);
3029+
30303030
if (var->isSettable(nullptr)) {
3031-
if (auto setterAccess = getActualAccessLevel(rawSetterAccessLevel)) {
3032-
var->setSetterAccess(*setterAccess);
3033-
} else {
3031+
auto setterAccess = getActualAccessLevel(rawSetterAccessLevel);
3032+
if (!setterAccess) {
30343033
error();
30353034
return nullptr;
30363035
}
3036+
var->setSetterAccess(*setterAccess);
3037+
3038+
// If we have a less-accessible setter, honor that by adding the
3039+
// setter access attribute.
3040+
if (*setterAccess < *accessLevel) {
3041+
AddAttribute(
3042+
new (ctx) SetterAccessAttr(SourceLoc(), SourceLoc(),
3043+
*setterAccess, /*implicit*/true));
3044+
}
30373045
}
30383046

30393047
if (isImplicit)
@@ -3044,6 +3052,10 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
30443052
if (var->getOverriddenDecl())
30453053
AddAttribute(new (ctx) OverrideAttr(SourceLoc()));
30463054

3055+
// Add the @_hasStorage attribute if this var has storage.
3056+
if (var->hasStorage())
3057+
AddAttribute(new (ctx) HasStorageAttr(/*isImplicit:*/true));
3058+
30473059
break;
30483060
}
30493061

0 commit comments

Comments
 (0)