Skip to content

Commit acac328

Browse files
committed
stdlib: remove _Reflectable
1 parent 7b1a8dc commit acac328

File tree

5 files changed

+26
-99
lines changed

5 files changed

+26
-99
lines changed

include/swift/Runtime/Reflection.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ struct MirrorReturn {
4444

4545
/// func reflect<T>(x: T) -> Mirror
4646
///
47-
/// Produce a mirror for any value. If the value's type conforms to _Reflectable,
48-
/// invoke its _getMirror() method; otherwise, fall back to an implementation
49-
/// in the runtime that structurally reflects values of any type.
47+
/// Produce a mirror for any value. The runtime produces a mirror that
48+
/// structurally reflects values of any type.
5049
SWIFT_RUNTIME_EXPORT
5150
extern "C" MirrorReturn
5251
swift_reflectAny(OpaqueValue *value, const Metadata *T);

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,8 +3090,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
30903090
return false;
30913091
}
30923092

3093-
// Ignore the internal members of Optional, like getLogicValue() and
3094-
// _getMirror().
3093+
// Ignore the members of Optional, like getLogicValue(), map(), and
3094+
// flatMap().
3095+
//
30953096
// These are not commonly used and cause noise and confusion when showing
30963097
// among the members of the underlying type. If someone really wants to
30973098
// use them they can write them directly.

stdlib/public/core/Reflection.swift

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// Customizes the result of `_reflect(x)`, where `x` is a conforming
14-
/// type.
15-
public protocol _Reflectable {
16-
// The runtime has inappropriate knowledge of this protocol and how its
17-
// witness tables are laid out. Changing this protocol requires a
18-
// corresponding change to Reflection.cpp.
19-
20-
/// Returns a mirror that reflects `self`.
21-
func _getMirror() -> _Mirror
22-
}
23-
2413
/// A unique identifier for a class instance or metatype.
2514
///
2615
/// In Swift, only class instances and metatypes have unique identities. There
@@ -137,10 +126,8 @@ func _getSummary<T>(_ out: UnsafeMutablePointer<String>, x: T) {
137126
out.initialize(with: String(reflecting: x))
138127
}
139128

140-
/// Produce a mirror for any value. If the value's type conforms to
141-
/// `_Reflectable`, invoke its `_getMirror()` method; otherwise, fall back
142-
/// to an implementation in the runtime that structurally reflects values
143-
/// of any type.
129+
/// Produce a mirror for any value. The runtime produces a mirror that
130+
/// structurally reflects values of any type.
144131
@_silgen_name("swift_reflectAny")
145132
internal func _reflect<T>(_ x: T) -> _Mirror
146133

stdlib/public/core/StaticString.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ public struct StaticString
251251
public var debugDescription: String {
252252
return self.description.debugDescription
253253
}
254-
255-
public func _getMirror() -> _Mirror {
256-
return _reflect(self.description)
257-
}
258254
}
259255

260256
extension StaticString {

stdlib/public/runtime/Reflection.mm

Lines changed: 19 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ - (id)debugQuickLookObject;
6060
~AnyReturn() { }
6161
};
6262

63-
/// A _Reflectable witness table.
64-
struct _ReflectableWitnessTable {
65-
/// func _getMirror() -> Mirror
66-
Mirror (*getMirror)(OpaqueValue *self, const Metadata *Self);
67-
};
68-
6963
struct MagicMirrorData;
7064

7165
struct String;
@@ -116,10 +110,7 @@ explicit String(NSString *s)
116110

117111
/// A Mirror witness table for use by MagicMirror.
118112
struct MirrorWitnessTable;
119-
120-
/// The protocol descriptor for _Reflectable from the stdlib.
121-
extern "C" const ProtocolDescriptor _TMps12_Reflectable;
122-
113+
123114
// This structure needs to mirror _MagicMirrorData in the stdlib.
124115
struct MagicMirrorData {
125116
/// 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) {
313304
return swift_getObjCClassMetadata(isa);
314305
}
315306

316-
static std::tuple<const _ReflectableWitnessTable *, const Metadata *,
317-
const OpaqueValue *>
307+
static std::tuple<const Metadata *, const OpaqueValue *>
318308
getReflectableConformance(const Metadata *T, const OpaqueValue *Value) {
319309
recur:
320310
// 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) {
335325
case MetadataKind::Existential: {
336326
auto existential
337327
= 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.
356330
T = existential->getDynamicType(Value);
357331
Value = existential->projectValue(Value);
358332

@@ -372,12 +346,8 @@ void swift_MagicMirrorData_summary(const Metadata *T, String *result) {
372346
case MetadataKind::ErrorObject:
373347
swift::crash("Swift mirror lookup failure");
374348
}
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);
381351
}
382352

383353
/// 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) {
389359
static Mirror reflect(HeapObject *owner,
390360
const OpaqueValue *value,
391361
const Metadata *T) {
392-
const _ReflectableWitnessTable *witness;
393362
const Metadata *mirrorType;
394363
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.
406367
// Consumes 'owner'.
407368
Mirror result;
408369
::new (&result) MagicMirror(owner, mirrorValue, mirrorType);
@@ -572,20 +533,15 @@ static void getEnumMirrorInfo(const OpaqueValue *value,
572533
extern "C"
573534
const char *swift_EnumCaseName(OpaqueValue *value, const Metadata *type) {
574535
// Build a magic mirror. Unconditionally destroy the value at the end.
575-
const _ReflectableWitnessTable *witness;
576536
const Metadata *mirrorType;
577537
const OpaqueValue *cMirrorValue;
578-
std::tie(witness, mirrorType, cMirrorValue) = getReflectableConformance(type, value);
579-
538+
std::tie(mirrorType, cMirrorValue) = getReflectableConformance(type, value);
539+
580540
OpaqueValue *mirrorValue = const_cast<OpaqueValue*>(cMirrorValue);
581541
Mirror mirror;
582542

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);
589545

590546
MagicMirror *theMirror = reinterpret_cast<MagicMirror *>(&mirror);
591547
MagicMirrorData data = theMirror->Data;
@@ -1158,31 +1114,19 @@ static Mirror ObjC_getMirrorForSuperclass(Class sup,
11581114

11591115
/// func reflect<T>(x: T) -> Mirror
11601116
///
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.
11641119
///
11651120
/// This function consumes 'value', following Swift's +1 convention for "in"
11661121
/// arguments.
11671122
MirrorReturn swift::swift_reflectAny(OpaqueValue *value, const Metadata *T) {
1168-
const _ReflectableWitnessTable *witness;
11691123
const Metadata *mirrorType;
11701124
const OpaqueValue *cMirrorValue;
1171-
std::tie(witness, mirrorType, cMirrorValue)
1172-
= getReflectableConformance(T, value);
1173-
1125+
std::tie(mirrorType, cMirrorValue) = getReflectableConformance(T, value);
1126+
11741127
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.
11861130
Mirror result;
11871131
// Take the value, unless we projected a subvalue from it. We don't want to
11881132
// deal with partial value deinitialization.

0 commit comments

Comments
 (0)