Skip to content

Commit 36e166c

Browse files
jrose-appletkremenek
authored andcommitted
[Serialization] Distinguish between static and non-static vars. (#7176) (#7187)
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 6b19f27 commit 36e166c

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 = 308; // Last change: nested type table
57+
const uint16_t VERSION_MINOR = 309; // Last change: static/non-static values
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -1179,7 +1179,8 @@ namespace decls_block {
11791179
XREF_VALUE_PATH_PIECE,
11801180
TypeIDField, // type
11811181
IdentifierIDField, // name
1182-
BCFixed<1> // restrict to protocol extension
1182+
BCFixed<1>, // restrict to protocol extension
1183+
BCFixed<1> // static?
11831184
>;
11841185

11851186
using XRefInitializerPathPieceLayout = BCRecordLayout<

lib/Serialization/Deserialization.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ getActualCtorInitializerKind(uint8_t raw) {
12231223
/// from Clang can also appear in any module.
12241224
static void filterValues(Type expectedTy, ModuleDecl *expectedModule,
12251225
CanGenericSignature expectedGenericSig, bool isType,
1226-
bool inProtocolExt,
1226+
bool inProtocolExt, bool isStatic,
12271227
Optional<swift::CtorInitializerKind> ctorInit,
12281228
SmallVectorImpl<ValueDecl *> &values) {
12291229
CanType canTy;
@@ -1238,6 +1238,8 @@ static void filterValues(Type expectedTy, ModuleDecl *expectedModule,
12381238
return true;
12391239
if (canTy && value->getInterfaceType()->getCanonicalType() != canTy)
12401240
return true;
1241+
if (value->isStatic() != isStatic)
1242+
return true;
12411243
// FIXME: Should be able to move a value from an extension in a derived
12421244
// module to the original definition in a base module.
12431245
if (expectedModule && !value->hasClangNode() &&
@@ -1309,10 +1311,12 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
13091311
bool isType = (recordID == XREF_TYPE_PATH_PIECE);
13101312
bool onlyInNominal = false;
13111313
bool inProtocolExt = false;
1314+
bool isStatic = false;
13121315
if (isType)
13131316
XRefTypePathPieceLayout::readRecord(scratch, IID, onlyInNominal);
13141317
else
1315-
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt);
1318+
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt,
1319+
isStatic);
13161320

13171321
Identifier name = getIdentifier(IID);
13181322
pathTrace.addValue(name);
@@ -1327,8 +1331,8 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
13271331
M->lookupQualified(ModuleType::get(M), name,
13281332
NL_QualifiedDefault | NL_KnownNoDependency,
13291333
/*typeResolver=*/nullptr, values);
1330-
filterValues(filterTy, nullptr, nullptr, isType, inProtocolExt, None,
1331-
values);
1334+
filterValues(filterTy, nullptr, nullptr, isType, inProtocolExt, isStatic,
1335+
None, values);
13321336

13331337
// HACK HACK HACK: Omit-needless-words hack to try to cope with
13341338
// the "NS" prefix being added/removed. No "real" compiler mode
@@ -1484,6 +1488,7 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
14841488
bool isType = false;
14851489
bool onlyInNominal = false;
14861490
bool inProtocolExt = false;
1491+
bool isStatic = false;
14871492
switch (recordID) {
14881493
case XREF_TYPE_PATH_PIECE: {
14891494
IdentifierID IID;
@@ -1495,7 +1500,8 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
14951500

14961501
case XREF_VALUE_PATH_PIECE: {
14971502
IdentifierID IID;
1498-
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt);
1503+
XRefValuePathPieceLayout::readRecord(scratch, TID, IID, inProtocolExt,
1504+
isStatic);
14991505
memberName = getIdentifier(IID);
15001506
break;
15011507
}
@@ -1534,8 +1540,8 @@ Decl *ModuleFile::resolveCrossReference(ModuleDecl *M, uint32_t pathLen) {
15341540

15351541
auto members = nominal->lookupDirect(memberName, onlyInNominal);
15361542
values.append(members.begin(), members.end());
1537-
filterValues(filterTy, M, genericSig, isType, inProtocolExt, ctorInit,
1538-
values);
1543+
filterValues(filterTy, M, genericSig, isType, inProtocolExt, isStatic,
1544+
ctorInit, values);
15391545
break;
15401546
}
15411547

lib/Serialization/Serialization.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
16221622
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
16231623
addTypeRef(ty),
16241624
addIdentifierRef(SD->getName()),
1625-
isProtocolExt);
1625+
isProtocolExt,
1626+
SD->isStatic());
16261627
break;
16271628
}
16281629

@@ -1637,7 +1638,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
16371638
abbrCode = DeclTypeAbbrCodes[XRefValuePathPieceLayout::Code];
16381639
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
16391640
addTypeRef(ty), nameID,
1640-
isProtocolExt);
1641+
isProtocolExt,
1642+
storage->isStatic());
16411643

16421644
abbrCode =
16431645
DeclTypeAbbrCodes[XRefOperatorOrAccessorPathPieceLayout::Code];
@@ -1671,7 +1673,8 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
16711673
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
16721674
addTypeRef(ty),
16731675
addIdentifierRef(fn->getName()),
1674-
isProtocolExt);
1676+
isProtocolExt,
1677+
fn->isStatic());
16751678

16761679
if (fn->isOperator()) {
16771680
// Encode the fixity as a filter on the func decls, to distinguish prefix
@@ -1752,7 +1755,8 @@ void Serializer::writeCrossReference(const Decl *D) {
17521755
XRefValuePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
17531756
addTypeRef(ty),
17541757
addIdentifierRef(val->getName()),
1755-
isProtocolExt);
1758+
isProtocolExt,
1759+
val->isStatic());
17561760
}
17571761

17581762
/// 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)