Skip to content

Commit 5015555

Browse files
committed
Swift SIL: add a utility protocol BridgedRandomAccessCollection
It fixes the default reflection for bridged random access collections, which usually have a `bridged` stored property. Conforming to this protocol displays the "real" children of a bridged random access collection and not just `bridged`.
1 parent c2ef106 commit 5015555

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

SwiftCompilerSources/Sources/SIL/Utils.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ extension FormattedLikeArray {
131131
}
132132
}
133133

134+
/// RandomAccessCollection which bridges to some C++ array.
135+
///
136+
/// It fixes the default reflection for bridged random access collections, which usually have a
137+
/// `bridged` stored property.
138+
/// Conforming to this protocol displays the "real" children not just `bridged`.
139+
public protocol BridgedRandomAccessCollection : RandomAccessCollection, CustomReflectable {
140+
}
141+
142+
extension BridgedRandomAccessCollection {
143+
public var customMirror: Mirror {
144+
Mirror(self, children: self.map { (label: nil, value: $0 as Any) })
145+
}
146+
}
147+
134148
/// A Sequence which is not consuming and therefore behaves like a Collection.
135149
///
136150
/// Many sequences in SIL and the optimizer should be collections but cannot

0 commit comments

Comments
 (0)