-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: add Import, Export functions #69491
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Change https://go.dev/cl/623638 mentions this issue: |
See also #52163. The export data format has a versioning header precisely for this reason. Presumably if the version has not changed, go/types.Import should be able to read the export data produced by an older version of go/types. On the other hand, if the version changes, we'll need to snapshot the logic of the older version in x/tools. Therefore, x/tools will have already interpretted the version header before it calls into go/types. Is you expectation that the bytes passed to go/types will be stripped of this header? |
And update the package documentation. Fixes golang/go#68898 Updates golang/go#69491 Change-Id: Ib01ef9ca4dfa204410c7b3e8d9439ddfee2d76f5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/623638 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
No, for better or worse the existing gcexportdata.Read function must continue to support files produced both by the compiler (2 releases + tip) and by gcexportdata.Write (which will become a wrapper around types.Export), so we would still need some way to detect the format. I propose that we pick a new version byte (in addition to |
[Status: WORK IN PROGRESS. Do not review yet.]
Background: The package golang.org/x/tools/go/gcexportdata provides two functions, Write and Read. As described in #68898, they serve two purposes:
These two purposes are quite independent, and the actual protocols they use are unrelated. (The first uses "indexed" form, the second "unified".) Much of the challenge of maintaining go/types and x/tools/go/gcexportdata comes from version skew between std and x/tools: witness the number of delicate changes to both made recently to support materialized Alias types, and then the addition of type parameters to aliases. In this instance, the skew is unnecessary as the codec can be tightly coupled go/types and needn't support any other versions.
Proposal: We propose to add the read and write functions to go/types itself:
This API is a synthesis of gcexportdata and internal/gcimporter.{Im,Ex}portShallow, which are used by gopls for "shallow" encodings.
Open questions:
types.Import,Export
would guarantee. How disruptive is that likely to be? I suspect that no existing tools rely on this implicit promise because we often temporarily break it during the course of normal development (e.g. adding generics, type aliases) over many CLs.@griesemer @findleyr @timothy-king
@znkr (for shallow export data)
The text was updated successfully, but these errors were encountered: