Skip to content

Commit 8917eb0

Browse files
committed
Revert "[Runtime][StdLib] Migrate mirrors to use CustomReflectable API, rewrite dump()"
This reverts commit 9798dfd because it broke the stdlib build.
1 parent d72d808 commit 8917eb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1511
-882
lines changed

stdlib/public/SDK/AppKit/AppKit.swift

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,94 @@
1313
import Foundation
1414
@_exported import AppKit
1515

16-
extension NSCursor : CustomPlaygroundQuickLookable {
17-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
18-
return .Image(image)
16+
struct _NSCursorMirror : _MirrorType {
17+
var _value: NSCursor
18+
19+
init(_ v: NSCursor) { _value = v }
20+
21+
var value: Any { return _value }
22+
23+
var valueType: Any.Type { return (_value as Any).dynamicType }
24+
25+
var objectIdentifier: ObjectIdentifier? { return .None }
26+
27+
var count: Int { return 0 }
28+
29+
subscript(_: Int) -> (String, _MirrorType) {
30+
_preconditionFailure("_MirrorType access out of bounds")
1931
}
32+
33+
var summary: String { return "" }
34+
35+
var quickLookObject: PlaygroundQuickLook? {
36+
return .Some(.Image(_value.image))
37+
}
38+
39+
var disposition : _MirrorDisposition { return .Aggregate }
2040
}
2141

22-
internal struct _NSViewQuickLookState {
23-
static var views = Set<NSView>()
42+
extension NSCursor : _Reflectable {
43+
public func _getMirror() -> _MirrorType {
44+
return _NSCursorMirror(self)
45+
}
2446
}
2547

26-
extension NSView : CustomPlaygroundQuickLookable {
27-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
48+
struct _NSViewMirror : _MirrorType {
49+
static var _views = Set<NSView>()
50+
51+
var _v : NSView
52+
53+
init(_ v : NSView) { _v = v }
54+
55+
var value: Any { return _v }
56+
57+
var valueType: Any.Type { return (_v as Any).dynamicType }
58+
59+
var objectIdentifier: ObjectIdentifier? { return .None }
60+
61+
var count: Int { return 0 }
62+
63+
subscript(_: Int) -> (String, _MirrorType) {
64+
_preconditionFailure("_MirrorType access out of bounds")
65+
}
66+
67+
var summary: String { return "" }
68+
69+
var quickLookObject: PlaygroundQuickLook? {
70+
// adapted from the Xcode QuickLooks implementation
71+
72+
var result: PlaygroundQuickLook? = nil
73+
2874
// if you set NSView.needsDisplay, you can get yourself in a recursive scenario where the same view
2975
// could need to draw itself in order to get a QLObject for itself, which in turn if your code was
3076
// instrumented to log on-draw, would cause yourself to get back here and so on and so forth
3177
// until you run out of stack and crash
3278
// This code checks that we aren't trying to log the same view recursively - and if so just returns
33-
// an empty view, which is probably a safer option than crashing
79+
// nil, which is probably a safer option than crashing
3480
// FIXME: is there a way to say "cacheDisplayInRect butDoNotRedrawEvenIfISaidSo"?
35-
if _NSViewQuickLookState.views.contains(self) {
36-
return .View(NSImage())
37-
} else {
38-
_NSViewQuickLookState.views.insert(self)
39-
let result : PlaygroundQuickLook
40-
if let b = bitmapImageRepForCachingDisplayInRect(bounds) {
41-
cacheDisplayInRect(bounds, toBitmapImageRep: b)
42-
result = .View(b)
43-
} else {
44-
result = .View(NSImage())
81+
if !_NSViewMirror._views.contains(_v) {
82+
_NSViewMirror._views.insert(_v)
83+
84+
let bounds = _v.bounds
85+
if let b = _v.bitmapImageRepForCachingDisplayInRect(bounds) {
86+
_v.cacheDisplayInRect(bounds, toBitmapImageRep: b)
87+
result = .Some(.View(b))
4588
}
46-
_NSViewQuickLookState.views.remove(self)
47-
return result
89+
90+
_NSViewMirror._views.remove(_v)
4891
}
92+
93+
return result
94+
95+
}
96+
97+
var disposition : _MirrorDisposition { return .Aggregate }
98+
}
99+
100+
extension NSView : _Reflectable {
101+
/// Returns a mirror that reflects `self`.
102+
public func _getMirror() -> _MirrorType {
103+
return _NSViewMirror(self)
49104
}
50105
}
51106

stdlib/public/SDK/CoreGraphics/CGFloat.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ public var CGFLOAT_MAX: CGFloat {
145145
fatalError("can't retrieve unavailable property")
146146
}
147147

148-
extension CGFloat : CustomReflectable {
148+
extension CGFloat : _Reflectable {
149149
/// Returns a mirror that reflects `self`.
150-
public func customMirror() -> Mirror {
151-
return Mirror(reflecting: native)
150+
public func _getMirror() -> _MirrorType {
151+
return _reflect(native)
152152
}
153153
}
154154

stdlib/public/SDK/CoreGraphics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_swift_library(swiftCoreGraphics IS_SDK_OVERLAY
22
CoreGraphics.swift
33
CGFloat.swift.gyb
4+
CoreGraphicsMirrors.swift.gyb
45
# rdar://problem/20891746
56
# SWIFT_COMPILE_FLAGS -Xfrontend -sil-serialize-all
67
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin

stdlib/public/SDK/CoreGraphics/CoreGraphics.swift

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,6 @@ public extension CGPoint {
3939
}
4040
}
4141

42-
extension CGPoint : CustomReflectable, CustomPlaygroundQuickLookable {
43-
public func customMirror() -> Mirror {
44-
return Mirror(self, children: ["x": x, "y": y], displayStyle: .Struct)
45-
}
46-
47-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
48-
return .Point(Double(x), Double(y))
49-
}
50-
}
51-
52-
extension CGPoint : CustomDebugStringConvertible {
53-
public var debugDescription : String {
54-
return "(\(x), \(y))"
55-
}
56-
}
57-
5842
extension CGPoint : Equatable {}
5943
@_transparent // @fragile
6044
@warn_unused_result
@@ -84,22 +68,6 @@ public extension CGSize {
8468
}
8569
}
8670

87-
extension CGSize : CustomReflectable, CustomPlaygroundQuickLookable {
88-
public func customMirror() -> Mirror {
89-
return Mirror(self, children: ["width": width, "height": height], displayStyle: .Struct)
90-
}
91-
92-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
93-
return .Size(Double(width), Double(height))
94-
}
95-
}
96-
97-
extension CGSize : CustomDebugStringConvertible {
98-
public var debugDescription : String {
99-
return "(\(width), \(height))"
100-
}
101-
}
102-
10371
extension CGSize : Equatable {}
10472
@_transparent // @fragile
10573
@warn_unused_result
@@ -389,22 +357,6 @@ public extension CGRect {
389357
}
390358
}
391359

392-
extension CGRect : CustomReflectable, CustomPlaygroundQuickLookable {
393-
public func customMirror() -> Mirror {
394-
return Mirror(self, children: ["origin": origin, "size": size], displayStyle: .Struct)
395-
}
396-
397-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
398-
return .Rectangle(Double(origin.x), Double(origin.y), Double(size.width), Double(size.height))
399-
}
400-
}
401-
402-
extension CGRect : CustomDebugStringConvertible {
403-
public var debugDescription : String {
404-
return "(\(origin.x), \(origin.y), \(size.width), \(size.height))"
405-
}
406-
}
407-
408360
extension CGRect : Equatable {}
409361
@_transparent // @fragile
410362
@warn_unused_result
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
%import gyb
14+
%TMirrorDecl = gyb.parseTemplate("../../common/MirrorDecl.gyb")
15+
%TMirrorConformance = gyb.parseTemplate("../../common/MirrorConformance.gyb")
16+
%TMirrorBoilerplate = gyb.parseTemplate("../../common/MirrorBoilerplate.gyb")
17+
18+
% for Type in [['CGPoint',['x','y'],'Point',['x','y']],
19+
% ['CGSize',['width','height'],'Size',['width','height']],
20+
% ['CGRect',['origin','size'],'Rectangle',['origin.x','origin.y','size.width','size.height']]]:
21+
% Self = Type[0]
22+
% Children = Type[1]
23+
% QLTag = Type[2]
24+
% QLArgs = Type[3]
25+
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,introspecteeType=Self,disposition='Struct')
26+
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,introspecteeType=Self,disposition='Struct')
27+
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,introspecteeType=Self,disposition='Struct')
28+
% QLArgFirst = True
29+
% QLArgString = ''
30+
% SummaryString = ''
31+
% for QLArg in QLArgs:
32+
% if not QLArgFirst:
33+
% QLArgString = QLArgString + ', '
34+
% SummaryString = SummaryString + ', '
35+
% else:
36+
% QLArgFirst = False
37+
% QLArgString = QLArgString + 'Double(_value.' + QLArg + ')'
38+
% SummaryString = SummaryString + '\(_value.' + QLArg + ')'
39+
% end
40+
41+
${MirrorDecl} {
42+
${MirrorBoilerplate}
43+
44+
var count: Int { return 2 }
45+
46+
subscript(i: Int) -> (String, _MirrorType) {
47+
switch i {
48+
case 0: return ("${Children[0]}", _reflect(_value.${Children[0]}))
49+
case 1: return ("${Children[1]}", _reflect(_value.${Children[1]}))
50+
default: _preconditionFailure("cannot extract this child index")
51+
}
52+
}
53+
54+
var summary: String { return "(${SummaryString})" }
55+
56+
var quickLookObject: PlaygroundQuickLook? { return .Some(.${QLTag}(${QLArgString})) }
57+
}
58+
59+
${MirrorConformance}

stdlib/public/SDK/Darwin/Darwin.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public struct DarwinBoolean : BooleanType, BooleanLiteralConvertible {
4242
}
4343
}
4444

45-
extension DarwinBoolean : CustomReflectable {
45+
extension DarwinBoolean : _Reflectable {
4646
/// Returns a mirror that reflects `self`.
47-
public func customMirror() -> Mirror {
48-
return Mirror(reflecting: boolValue)
47+
public func _getMirror() -> _MirrorType {
48+
return _reflect(boolValue)
4949
}
5050
}
5151

stdlib/public/SDK/Foundation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_swift_library(swiftFoundation IS_SDK_OVERLAY
22
Foundation.swift
3+
FoundationMirrors.swift.gyb
34
NSError.swift
45
NSStringAPI.swift
56
NSValue.swift

stdlib/public/SDK/Foundation/Foundation.swift

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,6 @@ extension NSKeyedUnarchiver {
13761376
}
13771377
}
13781378

1379-
//===----------------------------------------------------------------------===//
1380-
// NSURL
1381-
//===----------------------------------------------------------------------===//
1382-
13831379
extension NSURL : _FileReferenceLiteralConvertible {
13841380
private convenience init(failableFileReferenceLiteral path: String) {
13851381
let fullPath = NSBundle.mainBundle().pathForResource(path, ofType: nil)!
@@ -1392,62 +1388,3 @@ extension NSURL : _FileReferenceLiteralConvertible {
13921388
}
13931389

13941390
public typealias _FileReferenceLiteralType = NSURL
1395-
1396-
//===----------------------------------------------------------------------===//
1397-
// Mirror/Quick Look Conformance
1398-
//===----------------------------------------------------------------------===//
1399-
1400-
extension NSURL : CustomPlaygroundQuickLookable {
1401-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
1402-
return .URL(absoluteString)
1403-
}
1404-
}
1405-
1406-
extension NSRange : CustomReflectable {
1407-
public func customMirror() -> Mirror {
1408-
return Mirror(self, children: ["location": location, "length": length])
1409-
}
1410-
}
1411-
1412-
extension NSRange : CustomPlaygroundQuickLookable {
1413-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
1414-
return .Range(Int64(location), Int64(length))
1415-
}
1416-
}
1417-
1418-
extension NSDate : CustomPlaygroundQuickLookable {
1419-
var summary: String {
1420-
let df = NSDateFormatter()
1421-
df.dateStyle = .MediumStyle
1422-
df.timeStyle = .ShortStyle
1423-
return df.stringFromDate(self)
1424-
}
1425-
1426-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
1427-
return .Text(summary)
1428-
}
1429-
}
1430-
1431-
extension NSSet : CustomReflectable {
1432-
public func customMirror() -> Mirror {
1433-
return Mirror(reflecting: _convertNSSetToSet(self) as Set<NSObject>)
1434-
}
1435-
}
1436-
1437-
extension NSString : CustomPlaygroundQuickLookable {
1438-
public func customPlaygroundQuickLook() -> PlaygroundQuickLook {
1439-
return .Text(self as String)
1440-
}
1441-
}
1442-
1443-
extension NSArray : CustomReflectable {
1444-
public func customMirror() -> Mirror {
1445-
return Mirror(reflecting: self as [AnyObject])
1446-
}
1447-
}
1448-
1449-
extension NSDictionary : CustomReflectable {
1450-
public func customMirror() -> Mirror {
1451-
return Mirror(reflecting: _convertNSDictionaryToDictionary(self) as [NSObject : AnyObject])
1452-
}
1453-
}

0 commit comments

Comments
 (0)