Skip to content

Commit 6f63c77

Browse files
authored
[Serialization] Distinguish between static and non-static vars. (#7176)
Every other declaration kind gets this for free in its interface type, but properties don't. Just add a bit, it's simple enough. rdar://problem/30289803
1 parent 3d3fdec commit 6f63c77

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

include/swift/Serialization/ModuleFormat.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 309; // Last change: remove enum argument type
57+
const uint16_t VERSION_MINOR = 310; // Last change: static/non-static values
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -1199,7 +1199,8 @@ namespace decls_block {
11991199
XREF_VALUE_PATH_PIECE,
12001200
TypeIDField, // type
12011201
IdentifierIDField, // name
1202-
BCFixed<1> // restrict to protocol extension
1202+
BCFixed<1>, // restrict to protocol extension
1203+
BCFixed<1> // static?
12031204
>;
12041205

12051206
using XRefInitializerPathPieceLayout = BCRecordLayout<

lib/Serialization/Deserialization.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ getActualCtorInitializerKind(uint8_t raw) {
12701270
/// from Clang can also appear in any module.
12711271
static void filterValues(Type expectedTy, ModuleDecl *expectedModule,
12721272
CanGenericSignature expectedGenericSig, bool isType,
1273-
bool inProtocolExt,
1273+
bool inProtocolExt, bool isStatic,
12741274
Optional<swift::CtorInitializerKind> ctorInit,
12751275
SmallVectorImpl<ValueDecl *> &values) {
12761276
CanType canTy;
@@ -1285,6 +1285,8 @@ static void filterValues(Type expectedTy, ModuleDecl *expectedModule,
12851285
return true;
12861286
if (canTy && value->getInterfaceType()->getCanonicalType() != canTy)
12871287
return true;
1288+
if (value->isStatic() != isStatic)
1289+
return true;
12881290
// FIXME: Should be able to move a value from an extension in a derived
12891291
// module to the original definition in a base module.
12901292
if (expectedModule && !value->hasClangNode() &&
@@ -1356,10 +1358,12 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
13561358
bool isType = (recordID == XREF_TYPE_PATH_PIECE);
13571359
bool onlyInNominal = false;
13581360
bool inProtocolExt = false;
1361+
bool isStatic = false;
13591362
if (isType)
13601363
XRefTypePathPieceLayout::readRecord(scratch, IID, onlyInNominal);
13611364
else
1362-
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt);
1365+
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt,
1366+
isStatic);
13631367

13641368
Identifier name = getIdentifier(IID);
13651369
pathTrace.addValue(name);
@@ -1374,8 +1378,8 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
13741378
M->lookupQualified(ModuleType::get(M), name,
13751379
NL_QualifiedDefault | NL_KnownNoDependency,
13761380
/*typeResolver=*/nullptr, values);
1377-
filterValues(filterTy, nullptr, nullptr, isType, inProtocolExt, None,
1378-
values);
1381+
filterValues(filterTy, nullptr, nullptr, isType, inProtocolExt, isStatic,
1382+
None, values);
13791383

13801384
// HACK HACK HACK: Omit-needless-words hack to try to cope with
13811385
// the "NS" prefix being added/removed. No "real" compiler mode
@@ -1531,6 +1535,7 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
15311535
bool isType = false;
15321536
bool onlyInNominal = false;
15331537
bool inProtocolExt = false;
1538+
bool isStatic = false;
15341539
switch (recordID) {
15351540
case XREF_TYPE_PATH_PIECE: {
15361541
IdentifierID IID;
@@ -1542,7 +1547,8 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
15421547

15431548
case XREF_VALUE_PATH_PIECE: {
15441549
IdentifierID IID;
1545-
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt);
1550+
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt,
1551+
isStatic);
15461552
memberName = getIdentifier(IID);
15471553
break;
15481554
}
@@ -1581,8 +1587,8 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
15811587

15821588
auto members = nominal->lookupDirect(memberName, onlyInNominal);
15831589
values.append(members.begin(), members.end());
1584-
filterValues(filterTy, M, genericSig, isType, inProtocolExt, ctorInit,
1585-
values);
1590+
filterValues(filterTy, M, genericSig, isType, inProtocolExt, isStatic,
1591+
ctorInit, values);
15861592
break;
15871593
}
15881594

lib/Serialization/Serialization.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
16351635
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
16361636
addTypeRef(ty),
16371637
addIdentifierRef(SD->getName()),
1638-
isProtocolExt);
1638+
isProtocolExt,
1639+
SD->isStatic());
16391640
break;
16401641
}
16411642

@@ -1650,7 +1651,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
16501651
abbrCode = DeclTypeAbbrCodes[XRefValuePathPieceLayout::Code];
16511652
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
16521653
addTypeRef(ty), nameID,
1653-
isProtocolExt);
1654+
isProtocolExt,
1655+
storage->isStatic());
16541656

16551657
abbrCode =
16561658
DeclTypeAbbrCodes[XRefOperatorOrAccessorPathPieceLayout::Code];
@@ -1684,7 +1686,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
16841686
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
16851687
addTypeRef(ty),
16861688
addIdentifierRef(fn->getName()),
1687-
isProtocolExt);
1689+
isProtocolExt,
1690+
fn->isStatic());
16881691

16891692
if (fn->isOperator()) {
16901693
// Encode the fixity as a filter on the func decls, to distinguish prefix
@@ -1765,7 +1768,8 @@ void Serializer::writeCrossReference(const Decl *D) {
17651768
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
17661769
addTypeRef(ty),
17671770
addIdentifierRef(val->getName()),
1768-
isProtocolExt);
1771+
isProtocolExt,
1772+
val->isStatic());
17691773
}
17701774

17711775
/// Translate from the AST associativity enum to the Serialization enum

test/Serialization/Inputs/multi-file-2.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Do not put any classes in this file. It's part of the test that no classes
2-
// get serialized here.
1+
// Do not put any protocols in this file. It's part of the test that no
2+
// protocols get serialized here.
33

44
enum TheEnum {
55
case A, B, C(MyClass)
@@ -28,3 +28,8 @@ public func hasLocal() {
2828
useEquatable(LocalEnum.A)
2929
useEquatable(Wrapper.LocalEnum.A)
3030
}
31+
32+
class Base {
33+
class var conflict: Int { return 0 }
34+
var conflict: Int { return 1 }
35+
}

test/Serialization/multi-file.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func bar() {
2424
foo(EquatableEnum.A)
2525
}
2626

27-
// THIS-FILE-DAG: CLASS_DECL
28-
// OTHER-FILE-NEG-NOT: CLASS_DECL
27+
// THIS-FILE-DAG: PROTOCOL_DECL
28+
// OTHER-FILE-NEG-NOT: PROTOCOL_DECL
2929
// OTHER-FILE-DAG: ENUM_DECL
3030
// THIS-FILE-NEG-NOT: ENUM_DECL
3131

@@ -54,3 +54,8 @@ private protocol SomeProto {
5454
private struct Generic<T> {
5555
// THIS-FILE-DAG: GENERIC_TYPE_PARAM_DECL
5656
}
57+
58+
class Sub: Base {
59+
override class var conflict: Int { return 100 }
60+
override var conflict: Int { return 200 }
61+
}

0 commit comments

Comments
 (0)