New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: go/types: Export Info.FileVersions for access to file-specific version information #62605
Comments
cc: @findleyr |
I seem to understand that this information is already available via the Is this new API about parsing the version so that it can be used and compared more easily? That would remind me of #62039, so I wonder if we could deduplicate. Or is it about accessing the version information when one loads |
@mvdan You are correct that clients can find out about the respective Go version already, but that would involve duplicating parsing the string and various decisions. For instance, the The type checker needs to make all these decisions already internally. By exporting the data via |
Ah, so go/types would "flatten" this information beyond just parsing it out of the go/ast string - that makes sense then. It might still make sense to reuse the logic from #62039 if possible, or somehow merge the proposals. That API is still in flux, but it would be a bit weird for the |
Maybe the Version should be a string to match |
@timothy-king A string doesn't lend itself well to before/after comparisons. |
I think the key of the map should be I think there's meandering history that led us to |
This proposal has been added to the active column of the proposals project |
We should probably do something to fit better with #62039. Maybe that proposal should become a new go/version package, and then this package can just use a plain string and direct people to the go/version package for operations. If we do that, the only addition in this proposal is the FileVersions map added to Info, of type |
Background
Tools (such as the compiler) need access to per-file version information as provided in the processed Go source such that they (the tools) can do correct semantic analysis. For instance, this information is needed for correct scoping rules for the loop variable scoping change (#60078). The type checker (
go/types
) can collect this information during type-checking and provide it to clients.Proposal
We propose to export the following additional data structures from
go/types
:We add a new map to the
go/types.Info
struct which will be populated if present:The
Version
type will be defined as follows:The
Version
type may also define/export the following methods for convenience:These methods are not necessary (they are trivial to implement if needed), but unexported versions of them exist in the type checker and there are no strong reasons to withhold them from being exported.
Implementation
This proposal has been implemented in
types2
for use by the compiler and the code is present in unexported form ingo/types
, see CL 515135. If there are no objections to the proposed API we can simply export the functionality. If there are viable alternative proposals, we can adjust the existing implementation as needed.The text was updated successfully, but these errors were encountered: