Skip to content

Commit 7e6fcc8

Browse files
committed
Runtime: Fix _swift_buildDemanglingForMetadata() for explicit AnyObject
1 parent d9df0ea commit 7e6fcc8

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

stdlib/public/runtime/Demangle.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -149,43 +149,16 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
149149
}
150150
case MetadataKind::Existential: {
151151
auto exis = static_cast<const ExistentialTypeMetadata *>(type);
152-
NodePointer proto_list;
153152

154153
std::vector<const ProtocolDescriptor *> protocols;
155154
protocols.reserve(exis->Protocols.NumProtocols);
156155
for (unsigned i = 0, e = exis->Protocols.NumProtocols; i < e; ++i)
157156
protocols.push_back(exis->Protocols[i]);
158157

159-
if (exis->getSuperclassConstraint()) {
160-
// If there is a superclass constraint, we mangle it specially.
161-
proto_list = Dem.createNode(Node::Kind::ProtocolListWithClass);
162-
} else if (exis->isClassBounded()) {
163-
// Check if the class constraint is implied by any of our
164-
// protocols.
165-
bool requiresClassImplicit = false;
166-
167-
for (auto *protocol : protocols) {
168-
if (protocol->Flags.getClassConstraint()
169-
== ProtocolClassConstraint::Class)
170-
requiresClassImplicit = true;
171-
}
172-
173-
// If it was implied, we don't do anything special.
174-
if (requiresClassImplicit)
175-
proto_list = Dem.createNode(Node::Kind::ProtocolList);
176-
// If the existential type has an explicit AnyObject constraint,
177-
// we must mangle it as such.
178-
else
179-
proto_list = Dem.createNode(Node::Kind::ProtocolListWithAnyObject);
180-
} else {
181-
// Just a simple composition of protocols.
182-
proto_list = Dem.createNode(Node::Kind::ProtocolList);
183-
}
184-
185-
NodePointer type_list = Dem.createNode(Node::Kind::TypeList);
186-
158+
auto type_list = Dem.createNode(Node::Kind::TypeList);
159+
auto proto_list = Dem.createNode(Node::Kind::ProtocolList);
187160
proto_list->addChild(type_list, Dem);
188-
161+
189162
// Sort the protocols by their mangled names.
190163
// The ordering in the existential type metadata is by metadata pointer,
191164
// which isn't necessarily stable across invocations.
@@ -226,11 +199,39 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
226199
type_list->addChild(protocolNode, Dem);
227200
}
228201

229-
if (auto *superclass = exis->getSuperclassConstraint()) {
202+
if (auto superclass = exis->getSuperclassConstraint()) {
203+
// If there is a superclass constraint, we mangle it specially.
204+
auto result = Dem.createNode(Node::Kind::ProtocolListWithClass);
230205
auto superclassNode = _swift_buildDemanglingForMetadata(superclass, Dem);
231-
proto_list->addChild(superclassNode, Dem);
206+
207+
result->addChild(proto_list, Dem);
208+
result->addChild(superclassNode, Dem);
209+
return result;
210+
}
211+
212+
if (exis->isClassBounded()) {
213+
// Check if the class constraint is implied by any of our
214+
// protocols.
215+
bool requiresClassImplicit = false;
216+
217+
for (auto *protocol : protocols) {
218+
if (protocol->Flags.getClassConstraint()
219+
== ProtocolClassConstraint::Class)
220+
requiresClassImplicit = true;
221+
}
222+
223+
// If it was implied, we don't do anything special.
224+
if (requiresClassImplicit)
225+
return proto_list;
226+
227+
// If the existential type has an explicit AnyObject constraint,
228+
// we must mangle it as such.
229+
auto result = Dem.createNode(Node::Kind::ProtocolListWithAnyObject);
230+
result->addChild(proto_list, Dem);
231+
return result;
232232
}
233233

234+
// Just a simple composition of protocols.
234235
return proto_list;
235236
}
236237
case MetadataKind::ExistentialMetatype: {

0 commit comments

Comments
 (0)