internal/core/adt: fix race condition in Vertex.Default()
When Default() is called on a vertex with a disjunction where
NumDefaults == 1, the recursive call ToVertex(Default(d.Values[0]))
could return a shared vertex. Multiple goroutines calling Default()
on the same value would then race on the check-then-modify pattern:
if w.Conjuncts == nil {
w.Conjuncts = append(w.Conjuncts, ...)
}
Fix by ensuring we always work on a fresh copy before modifying:
- If the recursive result already has conjuncts, return as-is
- Otherwise, make a copy before populating conjuncts
This eliminates the race by ensuring no shared vertex is ever modified.
Updates #2733
Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Iaeb58fe3262d720d3757c5388a91c158cd2615a7
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1230712
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>