aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
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
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')
-rw-r--r--internal/pkg/ir.go13
-rw-r--r--internal/rosa/llvm_test.go21
2 files changed, 34 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].
//
diff --git a/internal/rosa/llvm_test.go b/internal/rosa/llvm_test.go
new file mode 100644
index 00000000..de63cb6b
--- /dev/null
+++ b/internal/rosa/llvm_test.go
@@ -0,0 +1,21 @@
+package rosa_test
+
+import (
+ "testing"
+
+ "hakurei.app/internal/pkg"
+ "hakurei.app/internal/rosa"
+)
+
+func TestLLVMInputs(t *testing.T) {
+ const wantInputCount = 688
+
+ _, llvm := rosa.Native().Std().MustLoad(rosa.H("llvm"))
+ var n int
+ for range pkg.Inputs(llvm) {
+ n++
+ }
+ if n != wantInputCount {
+ t.Errorf("Inputs: %d, want %d", n, wantInputCount)
+ }
+}