Skip to content
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

x/tools/go/gcexportdata: Read to support only 2 Go releases + tip #68898

Closed
adonovan opened this issue Aug 15, 2024 · 19 comments
Closed

x/tools/go/gcexportdata: Read to support only 2 Go releases + tip #68898

adonovan opened this issue Aug 15, 2024 · 19 comments

Comments

@adonovan
Copy link
Member

adonovan commented Aug 15, 2024

The gcexportdata package defines functions to export and import types.Packages as binary messages. They serve two purposes:

  1. gcexportdata.{Write,Read} permit applications to serialize and deserialize type information. For example, gopls uses it for its index (database) of types.
  2. gcexportdata.Read permits applications to read export data written by the Go compiler. For example, x/tools/go/packages uses this when NeedExport is set.

For (1), all that matters is that the Write and Read functions (at the exact same version) can faithfully round-trip all aspects of a types.Package; the form of the message isn't important. Currently, it uses the "indexed" (i) form, which the compiler used prior to its support for inlining and generics. This form is obsolete within GOROOT and is mentioned only in a few stale references, including documentation at cmd/compile/internal/typecheck/iexport.go. We plan to purge GOROOT of all mention to the i format, and move the docs to x/tools/internal.

For (2), what matters is that Read can read export data written by supported versions of the compiler. The compiler currently uses the "unified" (u) form. The gcexportdata package currently promises to "support[s] go1.7 export data format and all later versions". Given that almost all other promises of toolchain compatibility are limited to the last two Go releases (plus tip GOROOT), we propose to reduce Read's support window to match. (As a matter of fact, the code actually supports only as far back as go1.11.)

@timothy-king @griesemer @findleyr

@gopherbot gopherbot added this to the Proposal milestone Aug 15, 2024
@adonovan adonovan moved this to Incoming in Proposals Aug 15, 2024
@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

gopherbot pushed a commit to golang/tools that referenced this issue Aug 21, 2024
Move the documentation for indexed export data format from
  $GOROOT/src/cmd/compile/internal/typecheck/iexport.go
to
  x/tools/internal/gcimporter/iexport.go .
This is the only current writer of this format.

Updates golang/go#68778
Updates golang/go#68898

Change-Id: I365f56315d03affc5860cf407ea6e3d0caa1a88e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/607495
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/607495 mentions this issue: internal/gcimporter: move indexed format docs

@rsc
Copy link
Contributor

rsc commented Aug 29, 2024

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc rsc moved this from Incoming to Active in Proposals Aug 29, 2024
@adonovan
Copy link
Member Author

adonovan commented Sep 16, 2024

After discussion with @griesemer, we agree that the support policy proposed here seems appropriate.

Furthermore, we agree that purpose (1), a serialization format for types.Packages, should really move into the go/types package where it will be easier to maintain, since it won't need all the cleverness each time the toolchain upgrades (witness: aliases). We'll file a separate proposal for that:

@aclements
Copy link
Member

Is there ever a reason a tool using gcexportdata would need to read old export data? I can't think of any, but want to put the question out there.

@timothy-king
Copy link
Contributor

Is there ever a reason a tool using gcexportdata would need to read old export data? I can't think of any, but want to put the question out there.

You may want to ship a single tool that is compatible with analyzing the output of a large range of go toolchains. Today this would be something like creating a single binary that supports working with builds of both the 1.18 and 1.24 (tip) toolchains.

@adonovan
Copy link
Member Author

You may want to ship a single tool that is compatible with analyzing the output of a large range of go toolchains.

This is more a description of the hypothetical tool than a motivation for it. In any case, you could still build such a tool by forking the old importer.

@aarzilli
Copy link
Contributor

If for some reason you are working with multiple versions of go you wouldn't want to have, for example, multiple copies of staticcheck, each compiled with a different version of go.

@aclements
Copy link
Member

Thanks for playing devil's advocate everyone. :) I think we can move this forward.

@aclements
Copy link
Member

Have all remaining concerns about this proposal been addressed?

The proposal is for x/tools/go/gcexportdata.Read to only support the export data produced by the Go compiler from the last 2 releases plus tip, bringing it in line with our general Go version support policy.

@timothy-king
Copy link
Contributor

Have all remaining concerns about this proposal been addressed?

I have one remaining somewhat theoretical concern.

There are three relevant copies of the indexed format export data reader.

  1. $GOROOT/src/go/internal/gcimporter/iimport.go
  2. $GOROOT/src/cmd/compile/internal/importer/iimport.go
  3. x/tools/internal/gcimporter/iimport.go

What this proposal means today, is that if it is accepted x/tools/go/gcexportdata.Read does not need to provide a path to x/tools/internal/gcimporter/iimport.go. However, the two copies I would be the happiest to stop supporting are the two in GOROOT. In particular, I would be the happiest to drop support for $GOROOT/src/go/internal/gcimporter/iimport.go. So I want to make sure we can remove $GOROOT/src/go/internal/gcimporter/iimport.go before we concretely try to limit usage of x/tools/internal/gcimporter/iimport.go. It may be easier to drop this copy, if we keep the x/tools copy so it can be used in combination with go/types/Config.Importer? Not sure. I have not deeply looked into this yet.

So this might just be a theoretical concern, but it is what I am worried about.

@adonovan
Copy link
Member Author

I think we could probably delete $GOROOT/src/go/internal/gcimporter/iimport.go today. It is only used as the implementation of go/importer.ForCompiler("gc"), aka importer.Default(), when it encounters an 'indexed' file, but since it only reads files emitted by cmd/compile, which have not used indexed in years, this control path will never be taken.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/620135 mentions this issue: go/internal/gcimporter: drop indexed import

@adonovan
Copy link
Member Author

@timothy-king I've sent a CL for the deletion. In any case I don't think the concern has any bearing on this proposal.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/620036 mentions this issue: internal/gcimporter: remove test of unsupported "goroot" iimport

gopherbot pushed a commit to golang/tools that referenced this issue Oct 16, 2024
This CL eliminates the "goroot" flavor of
TestIExportDataTypeParameterizedAliases, leaving just
the "tools" flavor, and simplifies accordingly.

The logic of the goroot version assumed that importer.Default()
could read what gcexportdata.Write would write... except that
that comments correctly stated the assumption was false.

Updates golang/go#68898

Change-Id: Ifded4ed2cc2103de32ac869731176a49877d10e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/620036
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
gopherbot pushed a commit that referenced this issue Oct 17, 2024
The compiler hasn't emitted indexed export data files since go1.19,
so this code, which is only statically reachable from
go/importer.For("gc") aka importer.Default(), is not dynamically
reachable since those files will not be in indexed format.

Updates #68898

Change-Id: I12ea4e1b88da4fffdc9a07f318b9445a61e0d02b
Reviewed-on: https://go-review.googlesource.com/c/go/+/620135
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@adonovan
Copy link
Member Author

adonovan commented Oct 18, 2024

Have all remaining concerns about this proposal been addressed?

The iimport implementation in GOROOT that @timothy-king mentioned has now been deleted.

@aarzilli If for some reason you are working with multiple versions of go you wouldn't want to have, for example, multiple copies of staticcheck, each compiled with a different version of go.

That's true, but this would only be a problem if "multiple versions" means "more than two Go releases plus tip". I don't know of any tools that fit this description, and given that the 2+tip support window would be--after this proposal--essentially uniform across all the Go project's modules, it doesn't seem like grounds for an exception here.

@aclements
Copy link
Member

Based on the discussion above, this proposal seems like a likely accept.

The proposal is for x/tools/go/gcexportdata.Read to only support the export data produced by the Go compiler from the last 2 releases plus tip, bringing it in line with our general Go version support policy.

@aclements aclements moved this from Active to Likely Accept in Proposals Oct 23, 2024
@aclements aclements moved this from Likely Accept to Accepted in Proposals Oct 30, 2024
@aclements
Copy link
Member

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.

The proposal is for x/tools/go/gcexportdata.Read to only support the export data produced by the Go compiler from the last 2 releases plus tip, bringing it in line with our general Go version support policy.

@aclements aclements changed the title proposal: x/tools/go/gcexportdata: Read to support only 2 Go releases + tip x/tools/go/gcexportdata: Read to support only 2 Go releases + tip Oct 30, 2024
@aclements aclements modified the milestones: Proposal, Backlog Oct 30, 2024
@adonovan adonovan self-assigned this Oct 30, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/623638 mentions this issue: go/gcexportdata: document 2 releases + tip policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Accepted
Development

No branches or pull requests

7 participants