From f398f71fa947dbf03587b1a28d314a969aa6b351 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 31 May 2026 14:19:27 +0900 Subject: internal/pkg: input iterator via IR cache Primarily useful for garbage collection. Signed-off-by: Ophestra --- internal/pkg/ir.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'internal/pkg/ir.go') diff --git a/internal/pkg/ir.go b/internal/pkg/ir.go index 72a2c90c..366d9ca0 100644 --- a/internal/pkg/ir.go +++ b/internal/pkg/ir.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "io" + "iter" "slices" "strconv" "sync" @@ -65,6 +66,18 @@ func NewIR() *IRCache { return &IRCache{zeroIRCache()} } +// Inputs returns an iterator over direct and transitive inputs of an [Artifact] +// in randomised order. +func Inputs(a Artifact) iter.Seq2[Artifact, unique.Handle[ID]] { + ic := NewIR() + ic.Ident(a) + return func(yield func(Artifact, unique.Handle[ID]) bool) { + ic.artifact.Range(func(key, value any) bool { + return yield(key.(Artifact), value.(unique.Handle[ID])) + }) + } +} + // IContext is passed to [Artifact.Params] and provides methods for writing // values to the IR writer. It does not expose the underlying [io.Writer]. // -- cgit v1.3.1