@@ -1216,6 +1216,26 @@ class RemoteASTContextConcreteImpl final : public RemoteASTContextImpl {
1216
1216
std::move (valueAddress));
1217
1217
}
1218
1218
1219
+ Result<std::pair<Type, RemoteAddress>>
1220
+ getDynamicTypeAndAddressExistentialMetatype (RemoteAddress object) {
1221
+ // The value of the address is just the input address.
1222
+ // The type is obtained through the following sequence of steps:
1223
+ // 1) Loading a pointer from the input address
1224
+ // 2) Reading it as metadata and resolving the type
1225
+ // 3) Wrapping the resolved type in an existential metatype.
1226
+ auto pointed = Reader.readPointedValue (object.getAddressData ());
1227
+ if (!pointed)
1228
+ return getFailure<std::pair<Type, RemoteAddress>>();
1229
+ auto typeResult = Reader.readTypeFromMetadata (*pointed);
1230
+ if (!typeResult)
1231
+ return getFailure<std::pair<Type, RemoteAddress>>();
1232
+ auto wrappedType = ExistentialMetatypeType::get (typeResult);
1233
+ if (!wrappedType)
1234
+ return getFailure<std::pair<Type, RemoteAddress>>();
1235
+ return std::make_pair<Type, RemoteAddress>(std::move (wrappedType),
1236
+ std::move (object));
1237
+ }
1238
+
1219
1239
// / Resolve the dynamic type and the value address of an existential,
1220
1240
// / given its address and its static type. For class and error existentials,
1221
1241
// / this API takes a pointer to the instance reference rather than the
@@ -1227,9 +1247,9 @@ class RemoteASTContextConcreteImpl final : public RemoteASTContextImpl {
1227
1247
if (!staticType->isAnyExistentialType ())
1228
1248
return getFailure<std::pair<Type, RemoteAddress>>();
1229
1249
1230
- // TODO: implement support for ExistentialMetaTypes .
1250
+ // Handle the case where this is an ExistentialMetatype .
1231
1251
if (!staticType->isExistentialType ())
1232
- return getFailure<std::pair<Type, RemoteAddress>>( );
1252
+ return getDynamicTypeAndAddressExistentialMetatype (object );
1233
1253
1234
1254
// This should be an existential type at this point.
1235
1255
auto layout = staticType->getExistentialLayout ();
0 commit comments