Skip to content

Commit 2b73347

Browse files
committed
[NCGenerics] fix serialization of PCT
resolves rdar://118947007 update serialization for escapable
1 parent 14e3bc0 commit 2b73347

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6920,11 +6920,16 @@ DESERIALIZE_TYPE(GENERIC_TYPE_PARAM_TYPE)(
69206920

69216921
Expected<Type> DESERIALIZE_TYPE(PROTOCOL_COMPOSITION_TYPE)(
69226922
ModuleFile &MF, SmallVectorImpl<uint64_t> &scratch, StringRef blobData) {
6923-
bool hasExplicitAnyObject;
6923+
bool hasExplicitAnyObject, hasInverseCopyable, hasInverseEscapable;
69246924
ArrayRef<uint64_t> rawProtocolIDs;
69256925

69266926
decls_block::ProtocolCompositionTypeLayout::readRecord(
6927-
scratch, hasExplicitAnyObject, rawProtocolIDs);
6927+
scratch,
6928+
hasExplicitAnyObject,
6929+
hasInverseCopyable,
6930+
hasInverseEscapable,
6931+
rawProtocolIDs);
6932+
69286933
SmallVector<Type, 4> protocols;
69296934
for (TypeID protoID : rawProtocolIDs) {
69306935
auto protoTy = MF.getTypeChecked(protoID);
@@ -6933,7 +6938,13 @@ Expected<Type> DESERIALIZE_TYPE(PROTOCOL_COMPOSITION_TYPE)(
69336938
protocols.push_back(protoTy.get());
69346939
}
69356940

6936-
return ProtocolCompositionType::get(MF.getContext(), protocols,
6941+
InvertibleProtocolSet inverses;
6942+
if (hasInverseCopyable)
6943+
inverses.insert(InvertibleProtocolKind::Copyable);
6944+
if (hasInverseEscapable)
6945+
inverses.insert(InvertibleProtocolKind::Escapable);
6946+
6947+
return ProtocolCompositionType::get(MF.getContext(), protocols, inverses,
69376948
hasExplicitAnyObject);
69386949
}
69396950

lib/Serialization/ModuleFormat.h

Lines changed: 3 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 = 826; // alloc_vector, vector instructions
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 827; // ~Copyable/~Escapable serialization
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -1271,6 +1271,8 @@ namespace decls_block {
12711271
TYPE_LAYOUT(ProtocolCompositionTypeLayout,
12721272
PROTOCOL_COMPOSITION_TYPE,
12731273
BCFixed<1>, // has AnyObject constraint
1274+
BCFixed<1>, // has ~Copyable
1275+
BCFixed<1>, // has ~Escapable
12741276
BCArray<TypeIDField> // protocols
12751277
);
12761278

lib/Serialization/Serialization.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5574,11 +5574,25 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
55745574
for (auto proto : composition->getMembers())
55755575
protocols.push_back(S.addTypeRef(proto));
55765576

5577+
bool inverseCopyable = false, inverseEscapable = false;
5578+
for (auto ip : composition->getInverses()) {
5579+
switch (ip) {
5580+
case InvertibleProtocolKind::Copyable:
5581+
inverseCopyable = true;
5582+
break;
5583+
case InvertibleProtocolKind::Escapable:
5584+
inverseEscapable = true;
5585+
break;
5586+
};
5587+
}
5588+
55775589
unsigned abbrCode =
55785590
S.DeclTypeAbbrCodes[ProtocolCompositionTypeLayout::Code];
55795591
ProtocolCompositionTypeLayout::emitRecord(
55805592
S.Out, S.ScratchRecord, abbrCode,
55815593
composition->hasExplicitAnyObject(),
5594+
inverseCopyable,
5595+
inverseEscapable,
55825596
protocols);
55835597
}
55845598

0 commit comments

Comments
 (0)