This is special case of #14840, but identified as a potential source of special-cases if the general case is hard to solve.
Compiling the following program:
package main
import "sync"
var initializeVariable = sync.OnceValue(func() string {
return "THIS_IS_DEAD_CODE"
})
func main() {}
should not link in logic for initializeVariable since the variable is dead.
This also applies to OnceFunc and OnceValues.
At present, OnceValue is unfortunately not a drop-in replacement for for sync.Once for initializing global variables.
This is special case of #14840, but identified as a potential source of special-cases if the general case is hard to solve.
Compiling the following program:
should not link in logic for
initializeVariablesince the variable is dead.This also applies to
OnceFuncandOnceValues.At present,
OnceValueis unfortunately not a drop-in replacement for forsync.Oncefor initializing global variables.