internal/pkg: input iterator via IR cache
All checks were successful
Test / Create distribution (push) Successful in 1m5s
Test / Sandbox (push) Successful in 2m51s
Test / ShareFS (push) Successful in 3m42s
Test / Hakurei (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 5m31s
Test / Hakurei (race detector) (push) Successful in 6m32s
Test / Flake checks (push) Successful in 1m22s
All checks were successful
Test / Create distribution (push) Successful in 1m5s
Test / Sandbox (push) Successful in 2m51s
Test / ShareFS (push) Successful in 3m42s
Test / Hakurei (push) Successful in 3m58s
Test / Sandbox (race detector) (push) Successful in 5m31s
Test / Hakurei (race detector) (push) Successful in 6m32s
Test / Flake checks (push) Successful in 1m22s
Primarily useful for garbage collection. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"iter"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -65,6 +66,18 @@ func NewIR() *IRCache {
|
|||||||
return &IRCache{zeroIRCache()}
|
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
|
// IContext is passed to [Artifact.Params] and provides methods for writing
|
||||||
// values to the IR writer. It does not expose the underlying [io.Writer].
|
// values to the IR writer. It does not expose the underlying [io.Writer].
|
||||||
//
|
//
|
||||||
|
|||||||
21
internal/rosa/llvm_test.go
Normal file
21
internal/rosa/llvm_test.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user