Skip to content

Commit 5fa934c

Browse files
committed
[NCGenerics] fix serialization of PCT
resolves rdar://118947007 update serialization for escapable
1 parent a4a6c69 commit 5fa934c

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 = 825; // TrivialStride
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 826; // ~Copyable
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
@@ -5567,11 +5567,25 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
55675567
for (auto proto : composition->getMembers())
55685568
protocols.push_back(S.addTypeRef(proto));
55695569

5570+
bool inverseCopyable = false, inverseEscapable = false;
5571+
for (auto ip : composition->getInverses()) {
5572+
switch (ip) {
5573+
case InvertibleProtocolKind::Copyable:
5574+
inverseCopyable = true;
5575+
break;
5576+
case InvertibleProtocolKind::Escapable:
5577+
inverseEscapable = true;
5578+
break;
5579+
};
5580+
}
5581+
55705582
unsigned abbrCode =
55715583
S.DeclTypeAbbrCodes[ProtocolCompositionTypeLayout::Code];
55725584
ProtocolCompositionTypeLayout::emitRecord(
55735585
S.Out, S.ScratchRecord, abbrCode,
55745586
composition->hasExplicitAnyObject(),
5587+
inverseCopyable,
5588+
inverseEscapable,
55755589
protocols);
55765590
}
55775591

0 commit comments

Comments
 (0)