Skip to content

Commit 6bb6ca3

Browse files
committed
SwiftCompilerSources: add a few utility APIs
1 parent 2c36401 commit 6bb6ca3

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,16 @@ struct OperandSet : IntrusiveSet {
228228
context.freeOperandSet(bridged)
229229
}
230230
}
231+
232+
extension IntrusiveSet {
233+
mutating func insert(contentsOf source: some Sequence<Element>) {
234+
for element in source {
235+
_ = insert(element)
236+
}
237+
}
238+
239+
init(insertContentsOf source: some Sequence<Element>, _ context: some Context) {
240+
self.init(context)
241+
insert(contentsOf: source)
242+
}
243+
}

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ extension Sequence where Element == Operand {
150150
self.lazy.filter { !($0.instruction is I) }
151151
}
152152

153+
public func ignore(user: Instruction) -> LazyFilterSequence<Self> {
154+
self.lazy.filter { !($0.instruction == user) }
155+
}
156+
153157
public func getSingleUser<I: Instruction>(ofType: I.Type) -> I? {
154158
filterUsers(ofType: I.self).singleUse?.instruction as? I
155159
}

SwiftCompilerSources/Sources/SIL/Utilities/SequenceUtilities.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public extension CollectionLikeSequence {
9898
}
9999
return singleElement
100100
}
101+
102+
var first: Element? { first(where: { _ in true }) }
101103
}
102104

103105
// Also make the lazy sequences a CollectionLikeSequence if the underlying sequence is one.

0 commit comments

Comments
 (0)