Skip to content

proposal: go/types: add Info.MinVersion map to record each Node's language constraint #76162

@adonovan

Description

@adonovan

Background: the source-level inliner needs (see #75726) to disallow inlinings when the callee function body uses newer features of Go than are permitted in the caller. Currently this is done by checking the version of the file as a whole, but that is very imprecise, because inlinable functions tend to be small and simple and much less likely to be actually constrained by the language version.

Proposal: We propose to add to types.Info a MinVersions map[ast.Node]string mapping that records, for each syntax node, what minimum version of Go its semantics demand. For example, a call to the built-in max(x, y) depends on at least Go 1.21 ("go1.21"). The vast majority of nodes entail no constraint, so the map is sparse. The client would be expected to combine constraints as desired, for example by computing the maximum constraint for all the nodes in a given function body.

As a minor space optimization, the map values could be a type Version uint8 with a String method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions