@@ -60,12 +60,6 @@ - (id)debugQuickLookObject;
60
60
~AnyReturn () { }
61
61
};
62
62
63
- // / A _Reflectable witness table.
64
- struct _ReflectableWitnessTable {
65
- // / func _getMirror() -> Mirror
66
- Mirror (*getMirror)(OpaqueValue *self, const Metadata *Self);
67
- };
68
-
69
63
struct MagicMirrorData ;
70
64
71
65
struct String ;
@@ -116,10 +110,7 @@ explicit String(NSString *s)
116
110
117
111
// / A Mirror witness table for use by MagicMirror.
118
112
struct MirrorWitnessTable ;
119
-
120
- // / The protocol descriptor for _Reflectable from the stdlib.
121
- extern " C" const ProtocolDescriptor _TMps12_Reflectable;
122
-
113
+
123
114
// This structure needs to mirror _MagicMirrorData in the stdlib.
124
115
struct MagicMirrorData {
125
116
// / The owner pointer for the buffer the value lives in. For class values
@@ -313,8 +304,7 @@ void swift_MagicMirrorData_summary(const Metadata *T, String *result) {
313
304
return swift_getObjCClassMetadata (isa);
314
305
}
315
306
316
- static std::tuple<const _ReflectableWitnessTable *, const Metadata *,
317
- const OpaqueValue *>
307
+ static std::tuple<const Metadata *, const OpaqueValue *>
318
308
getReflectableConformance (const Metadata *T, const OpaqueValue *Value) {
319
309
recur:
320
310
// If the value is an existential container, look through it to reflect the
@@ -335,24 +325,8 @@ void swift_MagicMirrorData_summary(const Metadata *T, String *result) {
335
325
case MetadataKind::Existential: {
336
326
auto existential
337
327
= static_cast <const ExistentialTypeMetadata *>(T);
338
-
339
- // If the existential happens to include the _Reflectable protocol, use
340
- // the witness table from the container.
341
- unsigned wtOffset = 0 ;
342
- for (unsigned i = 0 ; i < existential->Protocols .NumProtocols ; ++i) {
343
- if (existential->Protocols [i] == &_TMps12_Reflectable) {
344
- return std::make_tuple (
345
- reinterpret_cast <const _ReflectableWitnessTable*>(
346
- existential->getWitnessTable (Value, wtOffset)),
347
- existential->getDynamicType (Value),
348
- existential->projectValue (Value));
349
- }
350
- if (existential->Protocols [i]->Flags .needsWitnessTable ())
351
- ++wtOffset;
352
- }
353
-
354
- // Otherwise, unwrap the existential container and do a runtime lookup on
355
- // its contained value as usual.
328
+
329
+ // Unwrap the existential container.
356
330
T = existential->getDynamicType (Value);
357
331
Value = existential->projectValue (Value);
358
332
@@ -372,12 +346,8 @@ void swift_MagicMirrorData_summary(const Metadata *T, String *result) {
372
346
case MetadataKind::ErrorObject:
373
347
swift::crash (" Swift mirror lookup failure" );
374
348
}
375
-
376
- return std::make_tuple (
377
- reinterpret_cast <const _ReflectableWitnessTable*>(
378
- swift_conformsToProtocol (T, &_TMps12_Reflectable)),
379
- T,
380
- Value);
349
+
350
+ return std::make_tuple (T, Value);
381
351
}
382
352
383
353
// / Produce a mirror for any value, like swift_reflectAny, but do not consume
@@ -389,20 +359,11 @@ void swift_MagicMirrorData_summary(const Metadata *T, String *result) {
389
359
static Mirror reflect (HeapObject *owner,
390
360
const OpaqueValue *value,
391
361
const Metadata *T) {
392
- const _ReflectableWitnessTable *witness;
393
362
const Metadata *mirrorType;
394
363
const OpaqueValue *mirrorValue;
395
- std::tie (witness, mirrorType, mirrorValue)
396
- = getReflectableConformance (T, value);
397
-
398
- // Use the _Reflectable conformance if the object has one.
399
- if (witness) {
400
- auto result =
401
- witness->getMirror (const_cast <OpaqueValue*>(mirrorValue), mirrorType);
402
- swift_release (owner);
403
- return MirrorReturn (result);
404
- }
405
- // Otherwise, fall back to MagicMirror.
364
+ std::tie (mirrorType, mirrorValue) = getReflectableConformance (T, value);
365
+
366
+ // Use MagicMirror.
406
367
// Consumes 'owner'.
407
368
Mirror result;
408
369
::new (&result) MagicMirror (owner, mirrorValue, mirrorType);
@@ -572,20 +533,15 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
572
533
extern "C"
573
534
const char *swift_EnumCaseName(OpaqueValue *value, const Metadata *type) {
574
535
// Build a magic mirror. Unconditionally destroy the value at the end.
575
- const _ReflectableWitnessTable *witness;
576
536
const Metadata *mirrorType;
577
537
const OpaqueValue *cMirrorValue;
578
- std::tie (witness, mirrorType, cMirrorValue) = getReflectableConformance (type, value);
579
-
538
+ std::tie (mirrorType, cMirrorValue) = getReflectableConformance (type, value);
539
+
580
540
OpaqueValue *mirrorValue = const_cast <OpaqueValue*>(cMirrorValue);
581
541
Mirror mirror;
582
542
583
- if (witness) {
584
- mirror = witness->getMirror (mirrorValue, mirrorType);
585
- } else {
586
- bool take = mirrorValue == value;
587
- ::new (&mirror) MagicMirror (mirrorValue, mirrorType, take);
588
- }
543
+ bool take = mirrorValue == value;
544
+ ::new (&mirror) MagicMirror (mirrorValue, mirrorType, take);
589
545
590
546
MagicMirror *theMirror = reinterpret_cast <MagicMirror *>(&mirror);
591
547
MagicMirrorData data = theMirror->Data ;
@@ -1158,31 +1114,19 @@ static Mirror ObjC_getMirrorForSuperclass(Class sup,
1158
1114
1159
1115
// / func reflect<T>(x: T) -> Mirror
1160
1116
// /
1161
- // / Produce a mirror for any value. If the value's type conforms to _Reflectable,
1162
- // / invoke its _getMirror() method; otherwise, fall back to an implementation
1163
- // / in the runtime that structurally reflects values of any type.
1117
+ // / Produce a mirror for any value. The runtime produces a mirror that
1118
+ // / structurally reflects values of any type.
1164
1119
// /
1165
1120
// / This function consumes 'value', following Swift's +1 convention for "in"
1166
1121
// / arguments.
1167
1122
MirrorReturn swift::swift_reflectAny (OpaqueValue *value, const Metadata *T) {
1168
- const _ReflectableWitnessTable *witness;
1169
1123
const Metadata *mirrorType;
1170
1124
const OpaqueValue *cMirrorValue;
1171
- std::tie (witness, mirrorType, cMirrorValue)
1172
- = getReflectableConformance (T, value);
1173
-
1125
+ std::tie (mirrorType, cMirrorValue) = getReflectableConformance (T, value);
1126
+
1174
1127
OpaqueValue *mirrorValue = const_cast <OpaqueValue*>(cMirrorValue);
1175
-
1176
- // Use the _Reflectable conformance if the object has one.
1177
- if (witness) {
1178
- auto result = witness->getMirror (mirrorValue, mirrorType);
1179
- // 'self' of witnesses is passed at +0, so we still need to consume the
1180
- // value.
1181
- T->vw_destroy (value);
1182
- return MirrorReturn (result);
1183
- }
1184
-
1185
- // Otherwise, fall back to MagicMirror.
1128
+
1129
+ // Use MagicMirror.
1186
1130
Mirror result;
1187
1131
// Take the value, unless we projected a subvalue from it. We don't want to
1188
1132
// deal with partial value deinitialization.
0 commit comments