Skip to content

Commit 90e2e54

Browse files
committed
SwiftCompilerSources: add a few utility APIs
1 parent 89f22f0 commit 90e2e54

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public struct Operand : CustomStringConvertible, NoReflectionChildren {
3737

3838
public var index: Int { instruction.operands.getIndex(of: self) }
3939

40+
public var nextUse: Operand? {
41+
if let bridgedNextUse = bridged.getNextUse().operand {
42+
return Operand(bridged: bridgedNextUse)
43+
}
44+
return nil
45+
}
46+
4047
/// True if the operand is used to describe a type dependency, but it's not
4148
/// used as value.
4249
public var isTypeDependent: Bool { bridged.isTypeDependent() }

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)