Skip to content

Commit 213da24

Browse files
committed
SIL: add an overload of Sequence<Operand>.users(ofType:) which returns a sequence of the specific instruction class and not a sequence of Instruction
1 parent 7bbd9a9 commit 213da24

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ extension Sequence where Element == Operand {
182182
return self.lazy.map { $0.instruction }
183183
}
184184

185-
// This intentinally returns a Sequence of `Instruction` and not a Sequence of `I` to be able to use
186-
// it as argument to `InstructionSet.insert(contentsOf:)`.
185+
public func users<I: Instruction>(ofType: I.Type) -> LazyMapSequence<LazyFilterSequence<Self>, I> {
186+
self.lazy.filter{ $0.instruction is I }.lazy.map { $0.instruction as! I }
187+
}
188+
189+
// This overload which returns a Sequence of `Instruction` and not a Sequence of `I` is used for APIs, like
190+
// `InstructionSet.insert(contentsOf:)`, which require a sequence of `Instruction`.
187191
public func users<I: Instruction>(ofType: I.Type) -> LazyMapSequence<LazyFilterSequence<Self>, Instruction> {
188192
self.lazy.filter{ $0.instruction is I }.users
189193
}

0 commit comments

Comments
 (0)