Skip to content

cmd/compile: dead code-elimination should work for sync.OnceValue #62202

Open
@dsnet

Description

@dsnet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.binary-sizecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions