Skip to content

Commit f5e4f0f

Browse files
committed
SwiftCompilerSources: add a few utility APIs
1 parent 168986b commit f5e4f0f

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
@@ -176,3 +176,16 @@ struct InstructionSet : IntrusiveSet {
176176
context.freeNodeSet(bridged)
177177
}
178178
}
179+
180+
extension IntrusiveSet {
181+
mutating func insert(contentsOf source: some Sequence<Element>) {
182+
for element in source {
183+
_ = insert(element)
184+
}
185+
}
186+
187+
init(insertContentsOf source: some Sequence<Element>, _ context: some Context) {
188+
self.init(context)
189+
insert(contentsOf: source)
190+
}
191+
}

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)