@@ -121,9 +121,7 @@ public struct Mirror {
121
121
if case let customized as CustomReflectable = subject {
122
122
self = customized. customMirror
123
123
} else {
124
- self = Mirror (
125
- legacy: _reflect ( subject) ,
126
- subjectType: type ( of: subject) )
124
+ self = Mirror ( internalReflecting: subject)
127
125
}
128
126
}
129
127
@@ -164,29 +162,6 @@ public struct Mirror {
164
162
@_versioned // FIXME(sil-serialize-all)
165
163
internal static func _noSuperclassMirror( ) -> Mirror ? { return nil }
166
164
167
- /// Returns the legacy mirror representing the part of `subject`
168
- /// corresponding to the superclass of `staticSubclass`.
169
- @_inlineable // FIXME(sil-serialize-all)
170
- @_versioned // FIXME(sil-serialize-all)
171
- internal static func _legacyMirror(
172
- _ subject: AnyObject , asClass targetSuperclass: AnyClass ) -> _Mirror ? {
173
-
174
- // get a legacy mirror and the most-derived type
175
- var cls : AnyClass = type ( of: subject)
176
- var clsMirror = _reflect ( subject)
177
-
178
- // Walk up the chain of mirrors/classes until we find staticSubclass
179
- while let superclass: AnyClass = _getSuperclass ( cls) {
180
- guard let superclassMirror = clsMirror. _superMirror ( ) else { break }
181
-
182
- if superclass == targetSuperclass { return superclassMirror }
183
-
184
- clsMirror = superclassMirror
185
- cls = superclass
186
- }
187
- return nil
188
- }
189
-
190
165
@_semantics ( " optimize.sil.specialize.generic.never " )
191
166
@inline ( never)
192
167
@_inlineable // FIXME(sil-serialize-all)
@@ -201,14 +176,19 @@ public struct Mirror {
201
176
switch ancestorRepresentation {
202
177
case . generated:
203
178
return {
204
- self . _legacyMirror ( _unsafeDowncastToAnyObject ( fromAny: subject) , asClass: superclass) . map {
205
- Mirror ( legacy: $0, subjectType: superclass)
206
- }
179
+ Mirror ( internalReflecting: subject, subjectType: superclass)
207
180
}
208
181
case . customized( let makeAncestor) :
209
182
return {
210
- Mirror ( _unsafeDowncastToAnyObject ( fromAny: subject) , subjectClass: superclass,
211
- ancestor: makeAncestor ( ) )
183
+ let ancestor = makeAncestor ( )
184
+ if superclass == ancestor. subjectType
185
+ || ancestor. _defaultDescendantRepresentation == . suppressed {
186
+ return ancestor
187
+ } else {
188
+ return Mirror ( internalReflecting: subject,
189
+ subjectType: superclass,
190
+ customAncestor: ancestor)
191
+ }
212
192
}
213
193
case . suppressed:
214
194
break
@@ -503,161 +483,6 @@ extension Mirror {
503
483
}
504
484
}
505
485
506
- //===--- Legacy _Mirror Support -------------------------------------------===//
507
- extension Mirror . DisplayStyle {
508
- /// Construct from a legacy `_MirrorDisposition`
509
- @_inlineable // FIXME(sil-serialize-all)
510
- @_versioned // FIXME(sil-serialize-all)
511
- internal init ? ( legacy: _MirrorDisposition ) {
512
- switch legacy {
513
- case . `struct`: self = . `struct`
514
- case . `class`: self = . `class`
515
- case . `enum`: self = . `enum`
516
- case . tuple: self = . tuple
517
- case . aggregate: return nil
518
- case . indexContainer: self = . collection
519
- case . keyContainer: self = . dictionary
520
- case . membershipContainer: self = . `set`
521
- case . container: preconditionFailure ( " unused! " )
522
- case . optional: self = . optional
523
- case . objCObject: self = . `class`
524
- }
525
- }
526
- }
527
-
528
- @_inlineable // FIXME(sil-serialize-all)
529
- @_versioned // FIXME(sil-serialize-all)
530
- internal func _isClassSuperMirror( _ t: Any . Type ) -> Bool {
531
- #if _runtime(_ObjC)
532
- return t == _ClassSuperMirror. self || t == _ObjCSuperMirror. self
533
- #else
534
- return t == _ClassSuperMirror. self
535
- #endif
536
- }
537
-
538
- extension _Mirror {
539
- @_inlineable // FIXME(sil-serialize-all)
540
- @_versioned // FIXME(sil-serialize-all)
541
- internal func _superMirror( ) -> _Mirror ? {
542
- if self . count > 0 {
543
- let childMirror = self [ 0 ] . 1
544
- if _isClassSuperMirror ( type ( of: childMirror) ) {
545
- return childMirror
546
- }
547
- }
548
- return nil
549
- }
550
- }
551
-
552
- /// When constructed using the legacy reflection infrastructure, the
553
- /// resulting `Mirror`'s `children` collection will always be
554
- /// upgradable to `AnyRandomAccessCollection` even if it doesn't
555
- /// exhibit appropriate performance. To avoid this pitfall, convert
556
- /// mirrors to use the new style, which only present forward
557
- /// traversal in general.
558
- internal extension Mirror {
559
- /// An adapter that represents a legacy `_Mirror`'s children as
560
- /// a `Collection` with integer `Index`. Note that the performance
561
- /// characteristics of the underlying `_Mirror` may not be
562
- /// appropriate for random access! To avoid this pitfall, convert
563
- /// mirrors to use the new style, which only present forward
564
- /// traversal in general.
565
- @_fixed_layout // FIXME(sil-serialize-all)
566
- @_versioned // FIXME(sil-serialize-all)
567
- internal struct LegacyChildren : RandomAccessCollection {
568
- internal typealias Indices = Range < Int >
569
-
570
- @_inlineable // FIXME(sil-serialize-all)
571
- @_versioned // FIXME(sil-serialize-all)
572
- internal init ( _ oldMirror: _Mirror ) {
573
- self . _oldMirror = oldMirror
574
- }
575
-
576
- @_inlineable // FIXME(sil-serialize-all)
577
- @_versioned // FIXME(sil-serialize-all)
578
- internal var startIndex : Int {
579
- return _oldMirror. _superMirror ( ) == nil ? 0 : 1
580
- }
581
-
582
- @_inlineable // FIXME(sil-serialize-all)
583
- @_versioned // FIXME(sil-serialize-all)
584
- internal var endIndex : Int { return _oldMirror. count }
585
-
586
- @_inlineable // FIXME(sil-serialize-all)
587
- @_versioned // FIXME(sil-serialize-all)
588
- internal subscript( position: Int ) -> Child {
589
- let ( label, childMirror) = _oldMirror [ position]
590
- return ( label: label, value: childMirror. value)
591
- }
592
-
593
- @_versioned // FIXME(sil-serialize-all)
594
- internal let _oldMirror : _Mirror
595
- }
596
-
597
- /// Initialize for a view of `subject` as `subjectClass`.
598
- ///
599
- /// - parameter ancestor: A Mirror for a (non-strict) ancestor of
600
- /// `subjectClass`, to be injected into the resulting hierarchy.
601
- ///
602
- /// - parameter legacy: Either `nil`, or a legacy mirror for `subject`
603
- /// as `subjectClass`.
604
- @_inlineable // FIXME(sil-serialize-all)
605
- @_versioned // FIXME(sil-serialize-all)
606
- internal init (
607
- _ subject: AnyObject ,
608
- subjectClass: AnyClass ,
609
- ancestor: Mirror ,
610
- legacy legacyMirror: _Mirror ? = nil
611
- ) {
612
- if ancestor. subjectType == subjectClass
613
- || ancestor. _defaultDescendantRepresentation == . suppressed {
614
- self = ancestor
615
- }
616
- else {
617
- let legacyMirror = legacyMirror ?? Mirror . _legacyMirror (
618
- subject, asClass: subjectClass) !
619
-
620
- self = Mirror (
621
- legacy: legacyMirror,
622
- subjectType: subjectClass,
623
- makeSuperclassMirror: {
624
- _getSuperclass ( subjectClass) . map {
625
- Mirror (
626
- subject,
627
- subjectClass: $0,
628
- ancestor: ancestor,
629
- legacy: legacyMirror. _superMirror ( ) )
630
- }
631
- } )
632
- }
633
- }
634
-
635
- @_inlineable // FIXME(sil-serialize-all)
636
- @_versioned // FIXME(sil-serialize-all)
637
- internal init (
638
- legacy legacyMirror: _Mirror ,
639
- subjectType: Any . Type ,
640
- makeSuperclassMirror: ( ( ) -> Mirror ? ) ? = nil
641
- ) {
642
- if let makeSuperclassMirror = makeSuperclassMirror {
643
- self . _makeSuperclassMirror = makeSuperclassMirror
644
- }
645
- else if let subjectSuperclass = _getSuperclass ( subjectType) {
646
- self . _makeSuperclassMirror = {
647
- legacyMirror. _superMirror ( ) . map {
648
- Mirror ( legacy: $0, subjectType: subjectSuperclass) }
649
- }
650
- }
651
- else {
652
- self . _makeSuperclassMirror = Mirror . _noSuperclassMirror
653
- }
654
- self . subjectType = subjectType
655
- self . children = Children ( LegacyChildren ( legacyMirror) )
656
- self . displayStyle = DisplayStyle ( legacy: legacyMirror. disposition)
657
- self . _defaultDescendantRepresentation = . generated
658
- }
659
- }
660
-
661
486
//===--- QuickLooks -------------------------------------------------------===//
662
487
663
488
/// The sum of types that can be used as a Quick Look representation.
@@ -769,7 +594,7 @@ extension PlaygroundQuickLook {
769
594
self = customized. _defaultCustomPlaygroundQuickLook
770
595
}
771
596
else {
772
- if let q = _reflect ( subject) . quickLookObject {
597
+ if let q = Mirror . quickLookObject ( subject) {
773
598
self = q
774
599
}
775
600
else {
0 commit comments