SwiftCompilerSources: add a few utility APIs

This commit is contained in:
Erik Eckstein
2024-01-22 20:20:16 +01:00
parent f9015e0e11
commit 3c368575b4
3 changed files with 19 additions and 0 deletions

View File

@@ -228,3 +228,16 @@ struct OperandSet : IntrusiveSet {
context.freeOperandSet(bridged)
}
}
extension IntrusiveSet {
mutating func insert(contentsOf source: some Sequence<Element>) {
for element in source {
_ = insert(element)
}
}
init(insertContentsOf source: some Sequence<Element>, _ context: some Context) {
self.init(context)
insert(contentsOf: source)
}
}

View File

@@ -150,6 +150,10 @@ extension Sequence where Element == Operand {
self.lazy.filter { !($0.instruction is I) }
}
public func ignore(user: Instruction) -> LazyFilterSequence<Self> {
self.lazy.filter { !($0.instruction == user) }
}
public func getSingleUser<I: Instruction>(ofType: I.Type) -> I? {
filterUsers(ofType: I.self).singleUse?.instruction as? I
}

View File

@@ -98,6 +98,8 @@ public extension CollectionLikeSequence {
}
return singleElement
}
var first: Element? { first(where: { _ in true }) }
}
// Also make the lazy sequences a CollectionLikeSequence if the underlying sequence is one.