aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/ir.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-31 14:19:27 +0900
committerOphestra <cat@gensokyo.uk>2026-05-31 14:19:27 +0900
commitf398f71fa947dbf03587b1a28d314a969aa6b351 (patch)
tree2e21ebaeacb9c0197d209b7398c749d538bdbe39 /internal/pkg/ir.go
parent4d017b13094ab29704aaee5b15d6e5db8a0842f5 (diff)
internal/pkg: input iterator via IR cache
Primarily useful for garbage collection. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/ir.go')
-rw-r--r--internal/pkg/ir.go13
1 files changed, 13 insertions, 0 deletions
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].
//