Skip to content

Commit aea26bb

Browse files
committed
Swift SIL: add a utility protocol NoReflectionChildren for better debug output with lldb po
Let's lldb's `po` command not print any "internal" properties of the conforming type. This is useful if the `description` already contains all the information of a type instance.
1 parent 40d1146 commit aea26bb

File tree

11 files changed

+32
-45
lines changed

11 files changed

+32
-45
lines changed

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,31 @@ public func assert(_ condition: Bool, file: StaticString = #fileID, line: UInt =
4040
}
4141
}
4242

43+
//===----------------------------------------------------------------------===//
44+
// Debugging Utilities
45+
//===----------------------------------------------------------------------===//
46+
47+
/// Let's lldb's `po` command not print any "internal" properties of the conforming type.
48+
///
49+
/// This is useful if the `description` already contains all the information of a type instance.
50+
public protocol NoReflectionChildren : CustomReflectable { }
51+
52+
public extension NoReflectionChildren {
53+
var customMirror: Mirror { Mirror(self, children: []) }
54+
}
55+
4356

4457
//===----------------------------------------------------------------------===//
4558
// StringRef
4659
//===----------------------------------------------------------------------===//
4760

48-
public struct StringRef : CustomStringConvertible, CustomReflectable {
61+
public struct StringRef : CustomStringConvertible, NoReflectionChildren {
4962
let _bridged: llvm.StringRef
5063

5164
public init(bridged: llvm.StringRef) { self._bridged = bridged }
5265

5366
public var string: String { _bridged.string }
5467
public var description: String { string }
55-
public var customMirror: Mirror { Mirror(self, children: []) }
5668

5769
public static func ==(lhs: StringRef, rhs: StaticString) -> Bool {
5870
let lhsBuffer = UnsafeBufferPointer<UInt8>(

SwiftCompilerSources/Sources/Optimizer/DataStructures/BasicBlockRange.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import SIL
4646
/// This type should be a move-only type, but unfortunately we don't have move-only
4747
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
4848
/// destruct this data structure, e.g. in a `defer {}` block.
49-
struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
49+
struct BasicBlockRange : CustomStringConvertible, NoReflectionChildren {
5050

5151
/// The dominating begin block.
5252
let begin: BasicBlock
@@ -149,8 +149,6 @@ struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
149149
"""
150150
}
151151

152-
var customMirror: Mirror { Mirror(self, children: []) }
153-
154152
/// TODO: once we have move-only types, make this a real deinit.
155153
mutating func deinitialize() {
156154
worklist.deinitialize()

SwiftCompilerSources/Sources/Optimizer/DataStructures/BasicBlockWorklist.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SIL
2020
/// This type should be a move-only type, but unfortunately we don't have move-only
2121
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
2222
/// destruct this data structure, e.g. in a `defer {}` block.
23-
struct BasicBlockWorklist : CustomStringConvertible, CustomReflectable {
23+
struct BasicBlockWorklist : CustomStringConvertible, NoReflectionChildren {
2424
private var worklist: Stack<BasicBlock>
2525
private var pushedBlocks: BasicBlockSet
2626

@@ -56,8 +56,6 @@ struct BasicBlockWorklist : CustomStringConvertible, CustomReflectable {
5656
"""
5757
}
5858

59-
var customMirror: Mirror { Mirror(self, children: []) }
60-
6159
/// TODO: once we have move-only types, make this a real deinit.
6260
mutating func deinitialize() {
6361
pushedBlocks.deinitialize()

SwiftCompilerSources/Sources/Optimizer/DataStructures/InstructionRange.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import SIL
3838
/// This type should be a move-only type, but unfortunately we don't have move-only
3939
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
4040
/// destruct this data structure, e.g. in a `defer {}` block.
41-
struct InstructionRange : CustomStringConvertible, CustomReflectable {
41+
struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
4242

4343
/// The dominating begin instruction.
4444
let begin: Instruction
@@ -139,8 +139,6 @@ struct InstructionRange : CustomStringConvertible, CustomReflectable {
139139
"""
140140
}
141141

142-
var customMirror: Mirror { Mirror(self, children: []) }
143-
144142
/// TODO: once we have move-only types, make this a real deinit.
145143
mutating func deinitialize() {
146144
insertedInsts.deinitialize()

SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import OptimizerBridging
2121
/// This type should be a move-only type, but unfortunately we don't have move-only
2222
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
2323
/// destruct this data structure, e.g. in a `defer {}` block.
24-
struct BasicBlockSet : CustomStringConvertible, CustomReflectable {
24+
struct BasicBlockSet : CustomStringConvertible, NoReflectionChildren {
2525

2626
private let context: PassContext
2727
private let bridged: BridgedBasicBlockSet
@@ -52,7 +52,6 @@ struct BasicBlockSet : CustomStringConvertible, CustomReflectable {
5252
return "{" + blockNames.joined(separator: ", ") + "}"
5353
}
5454

55-
var customMirror: Mirror { Mirror(self, children: []) }
5655

5756
/// TODO: once we have move-only types, make this a real deinit.
5857
mutating func deinitialize() {
@@ -68,7 +67,7 @@ struct BasicBlockSet : CustomStringConvertible, CustomReflectable {
6867
/// This type should be a move-only type, but unfortunately we don't have move-only
6968
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
7069
/// destruct this data structure, e.g. in a `defer {}` block.
71-
struct ValueSet : CustomStringConvertible, CustomReflectable {
70+
struct ValueSet : CustomStringConvertible, NoReflectionChildren {
7271

7372
private let context: PassContext
7473
private let bridged: BridgedNodeSet
@@ -113,8 +112,6 @@ struct ValueSet : CustomStringConvertible, CustomReflectable {
113112
return d
114113
}
115114

116-
var customMirror: Mirror { Mirror(self, children: []) }
117-
118115
/// TODO: once we have move-only types, make this a real deinit.
119116
mutating func deinitialize() {
120117
PassContext_freeNodeSet(context._bridged, bridged)
@@ -129,7 +126,7 @@ struct ValueSet : CustomStringConvertible, CustomReflectable {
129126
/// This type should be a move-only type, but unfortunately we don't have move-only
130127
/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
131128
/// destruct this data structure, e.g. in a `defer {}` block.
132-
struct InstructionSet : CustomStringConvertible, CustomReflectable {
129+
struct InstructionSet : CustomStringConvertible, NoReflectionChildren {
133130

134131
private let context: PassContext
135132
private let bridged: BridgedNodeSet
@@ -165,8 +162,6 @@ struct InstructionSet : CustomStringConvertible, CustomReflectable {
165162
return d
166163
}
167164

168-
var customMirror: Mirror { Mirror(self, children: []) }
169-
170165
/// TODO: once we have move-only types, make this a real deinit.
171166
mutating func deinitialize() {
172167
PassContext_freeNodeSet(context._bridged, bridged)

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SILBridging
1414

1515
/// An operand of an instruction.
16-
public struct Operand : CustomStringConvertible, CustomReflectable {
16+
public struct Operand : CustomStringConvertible, NoReflectionChildren {
1717
fileprivate let bridged: BridgedOperand
1818

1919
init(_ bridged: BridgedOperand) {
@@ -39,8 +39,6 @@ public struct Operand : CustomStringConvertible, CustomReflectable {
3939
public var isTypeDependent: Bool { Operand_isTypeDependent(bridged) != 0 }
4040

4141
public var description: String { "operand #\(index) of \(instruction)" }
42-
43-
public var customMirror: Mirror { Mirror(self, children: []) }
4442
}
4543

4644
public struct OperandArray : RandomAccessCollection, CustomReflectable {

SwiftCompilerSources/Sources/SIL/SmallProjectionPath.swift

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

13+
import Basic
14+
1315
/// A small and very efficient representation of a projection path.
1416
///
1517
/// A `SmallProjectionPath` can be parsed and printed in SIL syntax and parsed from Swift
@@ -37,7 +39,7 @@
3739
/// which means: it represents any number of any kind of projections.
3840
/// Though, it's very unlikely that the limit will be reached in real world scenarios.
3941
///
40-
public struct SmallProjectionPath : CustomStringConvertible, CustomReflectable, Hashable {
42+
public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflectionChildren {
4143

4244
/// The physical representation of the path. The path components are stored in
4345
/// reverse order: the first path component is stored in the lowest bits (LSB),
@@ -403,8 +405,6 @@ public struct SmallProjectionPath : CustomStringConvertible, CustomReflectable,
403405
}
404406
return false
405407
}
406-
407-
public var customMirror: Mirror { Mirror(self, children: []) }
408408
}
409409

410410
//===----------------------------------------------------------------------===//

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Basic
1414
import SILBridging
1515

16-
public struct Type : CustomStringConvertible, CustomReflectable {
16+
public struct Type : CustomStringConvertible, NoReflectionChildren {
1717
public let bridged: BridgedType
1818

1919
public var isAddress: Bool { SILType_isAddress(bridged) != 0 }
@@ -53,8 +53,6 @@ public struct Type : CustomStringConvertible, CustomReflectable {
5353
public var description: String {
5454
String(_cxxString: SILType_debugDescription(bridged))
5555
}
56-
57-
public var customMirror: Mirror { Mirror(self, children: []) }
5856
}
5957

6058
extension Type: Equatable {

SwiftCompilerSources/Sources/SIL/Utils.swift

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

13+
import Basic
1314
import SILBridging
1415

1516
// Need to export "Basic" to make `Basic.assert` available in the Optimizer module.
@@ -93,9 +94,8 @@ public protocol HasShortDescription {
9394
var shortDescription: String { get }
9495
}
9596

96-
private struct CustomMirrorChild : CustomStringConvertible, CustomReflectable {
97+
private struct CustomMirrorChild : CustomStringConvertible, NoReflectionChildren {
9798
public var description: String
98-
public var customMirror: Mirror { Mirror(self, children: []) }
9999

100100
public init(description: String) { self.description = description }
101101
}

SwiftCompilerSources/Sources/SIL/VTable.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
import SILBridging
1414

15-
public struct VTable : CustomStringConvertible, CustomReflectable {
15+
public struct VTable : CustomStringConvertible, NoReflectionChildren {
1616
let bridged: BridgedVTable
1717

1818
public init(bridged: BridgedVTable) { self.bridged = bridged }
1919

20-
public struct Entry : CustomStringConvertible, CustomReflectable {
20+
public struct Entry : CustomStringConvertible, NoReflectionChildren {
2121
fileprivate let bridged: BridgedVTableEntry
2222

2323
public var function: Function { SILVTableEntry_getFunction(bridged).function }
@@ -26,8 +26,6 @@ public struct VTable : CustomStringConvertible, CustomReflectable {
2626
let stdString = SILVTableEntry_debugDescription(bridged)
2727
return String(_cxxString: stdString)
2828
}
29-
30-
public var customMirror: Mirror { Mirror(self, children: []) }
3129
}
3230

3331
public struct EntryArray : BridgedRandomAccessCollection {
@@ -50,6 +48,4 @@ public struct VTable : CustomStringConvertible, CustomReflectable {
5048
let stdString = SILVTable_debugDescription(bridged)
5149
return String(_cxxString: stdString)
5250
}
53-
54-
public var customMirror: Mirror { Mirror(self, children: []) }
5551
}

0 commit comments

Comments
 (0)