internal/rosa: read-only access to built-ins

This removes potential footguns caused by mutable builtins without requiring unnecessary clones.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
cat
2026-08-25 14:00:42 +09:00
parent 7ee5d5368d
commit ac7abbbe3f
16 changed files with 123 additions and 94 deletions
+17 -17
View File
@@ -184,16 +184,16 @@ type cachedArtifact struct {
const (
// OptSkipCheck skips running all test suites.
OptSkipCheck = 1 << iota
// OptLLVMNoLTO disables LTO in all [LLVM] stages.
OptLLVMNoLTO
// OptToolchainLTO enables LTO in all LLVM stages.
OptToolchainLTO
)
// S holds a set of [Artifact].
type S struct {
// [ArtifactH] to [Artifact].
artifacts sync.Map
// Size of artifacts.
artifactCount atomic.Uint64
p sync.Map
// Size of p.
len atomic.Uint64
// Target architecture.
arch string
@@ -220,9 +220,9 @@ type S struct {
// Clone returns a copy of s.
func (s *S) Clone() *S {
v := S{arch: s.arch, opts: s.opts}
s.artifacts.Range(func(key, value any) bool {
v.artifacts.Store(key, value)
v.artifactCount.Add(1)
s.p.Range(func(key, value any) bool {
v.p.Store(key, value)
v.len.Add(1)
return true
})
return &v
@@ -304,7 +304,7 @@ func (s *S) DropCaches(targetArch string, flags int) {
// get returns the named [Artifact].
func (s *S) get(handle ArtifactH) (f Artifact) {
s.wantsArch()
v, ok := s.artifacts.Load(handle)
v, ok := s.p.Load(handle)
if ok {
f = v.(Artifact)
}
@@ -393,9 +393,9 @@ func (s *S) Register(name string, f Artifact) bool {
return false
}
p := ArtifactH(unique.Make(name))
_, ok := s.artifacts.LoadOrStore(p, f)
_, ok := s.p.LoadOrStore(p, f)
if !ok {
s.artifactCount.Add(1)
s.len.Add(1)
}
return !ok
}
@@ -418,15 +418,15 @@ func (s *S) MustRegister(name string, f Artifact) {
}
}
// count returns the number of [Artifact] registered to s.
// count returns the number of [Artifact] registered to r.
func (s *S) count() int {
return int(s.artifactCount.Load())
return int(s.len.Load())
}
// CollectAll returns all [ArtifactH] registered to s.
func (s *S) CollectAll() (handles P) {
handles = make(P, 0, s.count())
s.artifacts.Range(func(key, _ any) bool {
s.p.Range(func(key, _ any) bool {
handles = append(handles, key.(ArtifactH))
return true
})
@@ -439,7 +439,7 @@ func (s *S) CollectAll() (handles P) {
// Collect returns all non-excluded [ArtifactH] registered to s.
func (s *S) Collect() (handles P) {
handles = make(P, 0, s.count())
s.artifacts.Range(func(key, _ any) bool {
s.p.Range(func(key, _ any) bool {
h := key.(ArtifactH)
meta, _ := s.Std().MustLoad(h)
if !meta.Exclude {
@@ -453,7 +453,7 @@ func (s *S) Collect() (handles P) {
return
}
// deferredGit is a call to Toolchain.newTagRemote from azalea.
// deferredGit is a call to [Toolchain.NewViaGit] from azalea.
type deferredGit struct {
url string
tag string
@@ -1375,7 +1375,7 @@ func (s *S) SetSource(fsys fs.FS) error {
const name = "hakurei-source"
a := pkg.NewFile("hakurei-src-current.tar.gz", buf.Bytes())
s.artifacts.Store(
s.p.Store(
H(name),
Artifact(func(t Toolchain) (*Metadata, pkg.Artifact) {
return &Metadata{