Repository navigation
Upgrade for current Go releases - #88
Merged
Merged
Conversation
Travis CI has been shut down, so CI moves to GitHub Actions, testing against the two currently supported Go releases (1.26 and 1.27). golang.org/x/tools v0.1.12 could not read export data produced by modern toolchains, panicking in the gotypes and gopackages resolvers. v0.50.0 is the current release: it reads the version 4 export data emitted by Go 1.27 (as do v0.44.0 and later) and adds version 5 support for whatever emits it next. v0.50.0 requires go 1.26.0. That is also the go directive used by the golang.org/x repositories, and the oldest Go release still supported, so it costs nothing to anyone on a supported toolchain. The go directive is a minimum for every module that depends on us, so it is deliberately not set to the latest release.
generateDstDecs slices the formatted source of positions.go using token.Pos values, which are relative to the base of the file in the FileSet rather than to the start of the file. This is only correct when positions.go happens to be the first file added to the FileSet. The loader parses the files of a package concurrently, so the base depends on which file wins the race. When positions.go loses, the slices are offset and we either write corrupted comments into decorations-types-generated.go (each example missing its leading characters) or panic with a slice bounds error. Normalise the positions to a base of 1, which is what the slicing expects.
go vet now rejects an ExampleXxx function where Xxx is not an identifier in the package under test, which broke the build of the dst test package. Rename the affected examples to the Example_xxx form, which vet accepts for package level examples. Examples that do name a real identifier (ExampleClone, ExampleDecorations, ExampleInspect) are left alone so they stay attached to that identifier in the documentation.
A run of two blank lines produces an empty-line fragment followed by a new-line fragment, and both resolve to the same node. The second overwrote the spacing set by the first, downgrading EmptyLine to NewLine, and where the node was found in both directions the spacing was lost altogether - two blank lines restored as none. Only ever increase the spacing when attaching a newline fragment to a node. gofmt collapses a run of blank lines to a single blank line, so EmptyLine is the correct result. Fixes #81
The standard library has grown more files that import the same path twice with different aliases (e.g. "unsafe" alongside `_ "unsafe"` for go:linkname), which we can't restore yet - see #45. Collect the affected files into a map instead of a growing boolean expression, and add the files that have appeared since this list was last updated. Also skip packages that have nothing for us to restore, rather than failing: those with no non-test source, and those where every source file is preprocessed by cgo (Load only decorates the files in GoFiles).
Also commit the generated import block as gendst writes it, rather than
the goimports-grouped version that was committed previously, so that
running the generator leaves a clean tree. That makes it possible to
check the generated files are up to date with:
go run ./gendst && git diff --exit-code
go/ast gained File.GoVersion in Go 1.21, recording the minimum Go version required by the //go:build directives in the file. We were dropping it, so a restored file lost its version constraint as far as go/types was concerned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings the library up to date with current Go releases.
Adapted from #86 by @SamuelMarks — the dependency upgrade, the GitHub Actions migration, the gofmt pass, the
go vetexample renames and the fix for #81 are his work, and those commits keep his authorship. They have been modified: the dependency rationale differs, and the blank-line fix gained a regression test.Not taken from #86: the TypeSpec
Assigndecoration point (adds public API and silently moves comment attachment for type aliases — worth doing, but separately), and ~125 generated docstrings.Changes
gotypesandgopackagesresolvers. Requiresgo 1.26.0, matching the golang.org/x repos and the oldest supported Go release.EmptyLinecan't be downgraded by a followingNewLine.gendstthat could corrupt or panic when regeneratingdecorations-types-generated.go. It sliced the formatted source ofpositions.gousingtoken.Posvalues, which are relative to the file's base in the FileSet, and the loader parses a package's files concurrently.File.GoVersion, whichgo/astgained in Go 1.21. It was being dropped, so a restored file lost its version constraint as far asgo/typeswas concerned.Verification
go run ./gendstleaves a clean tree, so every generated file matches the generatorgofmtclean;go vetclean apart from pre-existing warnings ingendst/data/positions.goFile.GoVersionfield