Repository navigation
Description
This is @cherrymui's idea.
Background: Export data is the compact binary notation for serialized type information: conceptually it is a serialized types.Package. There are two different formats today: the unified (u) format written and read by the compiler, and the indexed (i) format written and read by x/tools (incl. gopls). However, the x/tools reader must also be capable of reading u format because go list -export runs the compiler to generate export data files. This creates a complex and inconvenient coupling between the compiler and x/tools.
Proposal: Let's split the two formats apart. The compiler would read and write only u format written by the exact same version of the toolchain. This would allow it to evolve independently: any commit on any given day would be free to change the reader and writer. We would provide no supported way to read the compiler's format; even its existence would be an internal implementation detail.
The x/tools format would read and write only i format; however, it would still need to retain the ability to read files produced by go list -export. So, we could change go list -export to run not cmd/compile but a new frontend tool, cmd/export, based on go/ast + go/types + vendor/x/tools, that simply reads, parses, and type-checks Go source files, reading export data for dependencies and writing it out for the current package. (The cmd/export tool should be straightforward to write: it's basically unitchecker with the analysis parts ripped out, accepting its command-line arguments in cmd/compile not cmd/vet form).
The only unknown quantity is the go/importer package. Today it may be used to read files named by go list -export; since these would in future be produced by cmd/export, go/importer would use the vendored x/tools reader. But it's possible that some users are also using it to parse .a files produced by the compiler that they found some other way. (I vaguely recall seeing such file names in the output of go list -json but I cannot now find them. go help install talks about package files being installed, but I don't know exactly what that implies.) We need to investigate who would be broken if we stopped making go/importer support compiler export data files.
When a language change affects exported types, the process would be:
- add support to go/types{,2}. Now you can use the feature in single-package tests of go/types and/or the compiler.
- add support to the compiler and its export data reader/writer. Now you can use the feature in multi-package tests of the compiler.
- add support to x/tools reader and writer.
- vendor x/tools into GOROOT. Now Go developers'
go list -exportwould be emitting the new format (whether or not the package actually uses new language features). Any x/tools-based commands installed on their $PATH would need to be re-built with a version of x/tools later than step 3. - Go release. At this point all users of the new toolchain would be using the new format. Tools binaries on their PATH would need updating.
Several people have asked why not guarantee backward compatibility of the x/tools file format so that installed x/tools-based tools are not broken by each toolchain update. This is appealing, but in general it is impossible: if a package makes use of a new language feature that cannot yet be written, there is really nothing sound that the reader can do other than report a version skew error. It might seem gentler to the user not to report an error until we actually encounter a usage of the new language feature (not just the newer file version number), but typically the new feature will be quickly adopted in low-level packages, so there is little practical benefit to reporting the error lazily.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
- StatusShow more project fieldsAccepted
Activity
gabyhelp commentedon May 15, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
griesemer commentedon May 15, 2026
It may still be useful to have a separate reader/viewer for the compiler export format (we don't really have that), for debugging purposes. It could show a lot of compiler related information. But this would not affect this proposal, of course, and we wouldn't need to make this a public tool, necessarily (to avoid backward-compatibility requirements).
For completeness, per our discussion, there is also a gccgo export data importer but that is effectively defunct since it never supported generics.
I also note that the proposed new stand-alone tool would not need to type -check function bodies I think and that go/types already supports such a mode. So this could be pretty fast.
I wonder if there's any overlap between this and the work we do in the API checker.
adonovan commentedon May 18, 2026
Certainly that may be useful, but it is (as you say) orthogonal to the proposal.
FYI I filed #79453 to drop support for gccgo.
Exactly: the cmd/export tool should be much faster than the actual compiler, and it critical path much shorter.
griesemer commentedon May 27, 2026
We believe this is a good idea but we should get a better understanding of the impact of not being able to read the compiler export data by tools.
As an experiment we can poison the compiler export data (so that it cannot be read by the tools anymore) and see what needs to be fixed on the tools side.
aclements commentedon May 28, 2026
This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— aclements for the proposal review group
45 remaining items
[-]decouple export data formats used by compiler and x/tools[/-][+]cmd/compile,cmd/go: decouple export data formats used by compiler and x/tools[/+]mvdan commentedon Oct 13, 2026
Raised what I think could be a regression I spotted today downstream: #82186
gopherbot commentedon Oct 21, 2026
Change https://go.dev/cl/852225 mentions this issue:
go/gcexportdata: clarify which export files require NewReadergo/gcexportdata: clarify which export files require NewReader
go/gcexportdata: clarify which export files require NewReader
fix(tool/internal/instrument): read method_call type info from go lis…
Itz-Agasta commentedon Nov 11, 2026
one more case this breaks..... toolexec tools that add imports while compiling. i hit it in OpenTelemetry's compile-time instrumentation (open-telemetry/opentelemetry-go-compile-instrumentation#1740). when a rule adds an import to a package, i run
go list -exportfor it and put theExportfile into the compiler's-importcfg. on tip that's now a cmd/export file, so the compiler can't read it.The only workaround i found loorking around is the one in the pending compilebench change (CL 849326): getting the importcfg out of
go build -n / -work.so yaa is there any better supported way to get a package's compiler archive for an importcfg ?
adonovan commentedon Nov 11, 2026
Sorry for the breakage. That does seem like the smallest workaround, but the whole approach is unsound in general. There are many ways in which the build graph for the original build and for the one extra package built in isolation might differ. For example, test variants, PGO, a whole list of compiler flags. Presumably you would also need to modify the linker's
-importcfgtoo and ensure that every common dependency of the two builds was compiled under exactly the same regime.A more robust approach would be to inject the new imports where the build system can see them, using the -overlay mechanism to inject additional files.
gopherbot commentedon Nov 11, 2026
Change https://go.dev/cl/861988 mentions this issue:
internal/gcimporter: break dependency on objectpathinternal/gcimporter: break dependency on objectpath
gopherbot commentedon Nov 21, 2026
Change https://go.dev/cl/863174 mentions this issue:
internal/gcimporter: move legacy code to gcexportdata