W8001 copy_on_write
An update to a shared collection is forced to copy inside a loop because another reference retains the old value (design §8.2).
A warning from the package phase. sakura explain W8001 prints this explanation offline.
An update to a shared collection is forced to copy inside a loop because another reference retains the old value (design §8.2). Drop the retaining use or restructure the loop. The code is registered ahead of its check, which comes with the native backend's reuse analysis (M5); no command reports it yet.
Wrong program
compiler/tests/ui/W8001_copy_on_write.sakura, which the compiler's ui suite does not run yet (needs: native backend with Perceus reuse analysis):
fn grow() -> List<Int> {
var xs = [1]
var kept = xs
for i in 0..100 {
kept = xs
xs = List.push(xs, i)
}
xs
}Fixed program
No fixed program is checked in for this code yet; the explanation above describes the repair.