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

[Merged by Bors] - Bump Go to 1.22.2 #5580

Closed
wants to merge 15 commits into from
Closed

[Merged by Bors] - Bump Go to 1.22.2 #5580

wants to merge 15 commits into from

Conversation

poszu
Copy link
Contributor

@poszu poszu commented Feb 16, 2024

Description

Go 1.22.0 release notes: https://tip.golang.org/doc/go1.22

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

Attention: Patch coverage is 95.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 80.2%. Comparing base (5d129a4) to head (f1891b7).

Files Patch % Lines
node/test_network.go 0.0% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #5580     +/-   ##
=========================================
- Coverage     80.2%   80.2%   -0.1%     
=========================================
  Files          285     285             
  Lines        29754   29738     -16     
=========================================
- Hits         23883   23866     -17     
  Misses        4224    4224             
- Partials      1647    1648      +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@fasmat fasmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't update to 1.22 yet.

Tools and libraries might not yet be compatible with it yet and we are not yet using any of its features.

I went through some of the codebase to check where we can update the code to actually use 1.22 improvements and its quite a bit (WIP: bump-go-1.22...golang-1.22-features)

@poszu
Copy link
Contributor Author

poszu commented Feb 19, 2024

@fasmat

I think we shouldn't update to 1.22 yet.

There are quite a few tools and libraries not compatible with it yet (e.g. libp2p afaik) and we are not yet using any of its features.

The go-libp2p is a good point. We probably shouldn't update to go 1.22 until this issue is resolved: libp2p/go-libp2p#2706. What other tools and libraries block the upgrade?

I went through some of the codebase to check where we can update the code to actually use 1.22 improvements and its quite a bit (WIP: dependabot/docker/golang-1.22...golang-1.22-features)

Just because there are new functionalities in the language doesn't mean we should use them everywhere and upgrade the codebase in a single huge PR. I intentionally didn't change all for i := 0; i< x; i++ into for range x. Which version is better in each context depends.

@fasmat
Copy link
Member

fasmat commented Feb 19, 2024

What other tools and libraries block the upgrade?

I saw staticcheck failing earlier, but I haven't checked everything yet. Some internals of the runtime changed with 1.22 which probably broke things (e.g. one of our tests because a different amount of memory is now allocated). I haven't checked yet but this might affect go-scale (where we do unsafe memory operations on strings and bytes).

golangci-lint reports errors like loopclosure: variable X captured by func literal although this is not a problem any more in 1.22. I am not sure if this is a golangci-lint issue or if we need to update our config accordingly, but my VSCode is now full of these false positives 😅.

gci seems to not understand that math/rand/v2 is a standard library package and tries to sort it with external imports.

Just because there are new functionalities in the language doesn't mean we should use them everywhere and upgrade the codebase in a single huge PR.

True, but I still think that we should at least migrate code from math/rand to math/rand/v2 and add the former to the list of not allowed packages in golangci-lint. math/rand/v2 is a big improvement over the old version, but cannot easily be used both in the same package.

@poszu
Copy link
Contributor Author

poszu commented Feb 19, 2024

Staticcheck required a bump and now passes. I haven't seen any issues with golangci-lint, the CI is clean 🤔.

@fasmat
Copy link
Member

fasmat commented Feb 19, 2024

Staticcheck required a bump and now passes. I haven't seen any issues with golangci-lint, the CI is clean 🤔.

Try removing a tc := tc statement from any test (which is now possible in Go 1.22) and golangci-lint will start complaining. The same is also true if you import "math/rand/v2" in any file that currently uses "math/rand" and golanci-lint will start complaining about that as well:

syncer/find_fork_test.go:7: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/spacemeshos/go-spacemesh) (gci)
        "math/rand/v2"
syncer/find_fork_test.go:13: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/spacemeshos/go-spacemesh) (gci)
        "go.uber.org/mock/gomock"
...
activation/nipost_test.go:1156:19: loopclosure: loop variable tc captured by func literal (govet)
                                PublishEpoch: tc.epoch,

Both of which are false positives 🙂

@poszu
Copy link
Contributor Author

poszu commented Feb 20, 2024

Staticcheck required a bump and now passes. I haven't seen any issues with golangci-lint, the CI is clean 🤔.

Try removing a tc := tc statement from any test (which is now possible in Go 1.22) and golangci-lint will start complaining. The same is also true if you import "math/rand/v2" in any file that currently uses "math/rand" and golanci-lint will start complaining about that as well:

syncer/find_fork_test.go:7: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/spacemeshos/go-spacemesh) (gci)
        "math/rand/v2"
syncer/find_fork_test.go:13: File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/spacemeshos/go-spacemesh) (gci)
        "go.uber.org/mock/gomock"
...
activation/nipost_test.go:1156:19: loopclosure: loop variable tc captured by func literal (govet)
                                PublishEpoch: tc.epoch,

Both of which are false positives 🙂

The loop variable false positive is already fixed in golangci-lint v1.56.2. The gci false-positive should be fixed in the next release of golangci-lint (it's already fixed on their master branch). Summing up, we need to wait for:

  • golangci-lint v1.56.3
  • version of go-libp2p that supports go1.22

@poszu
Copy link
Contributor Author

poszu commented Feb 23, 2024

@fasmat go-libp2p v0.33 which supports go1.22 was released already: https://github.com/libp2p/go-libp2p/releases/tag/v0.33.0

@poszu poszu requested a review from fasmat February 23, 2024 12:18
@fasmat
Copy link
Member

fasmat commented Feb 23, 2024

@poszu but the problem with math/rand/v2 for golangci-lint formatting and the false positives about loop capture haven't been fixed yet or have they?

@poszu
Copy link
Contributor Author

poszu commented Feb 26, 2024

@poszu but the problem with math/rand/v2 for golangci-lint formatting and the false positives about loop capture haven't been fixed yet or have they?

No, there's no new version of golangci-lint yet. IMHO, bump to go1.22 shouldn't be blocked by that, we cannot use math/rand/v2 anyway in go1.21 🤷. Anyway, I hope it's a matter of days before a new version of golangci-lint is released.

@fasmat
Copy link
Member

fasmat commented Feb 26, 2024

No, there's no new version of golangci-lint yet. IMHO, bump to go1.22 shouldn't be blocked by that, we cannot use math/rand/v2 anyway in go1.21 🤷.

I don't think I understand. The goal of this PR is to update 1.22 and the argument to not wait for compatibility is because after upgrading to 1.22 we are still using 1.21? What is the point of upgrading then? 😅

@poszu
Copy link
Contributor Author

poszu commented Feb 26, 2024

No, there's no new version of golangci-lint yet. IMHO, bump to go1.22 shouldn't be blocked by that, we cannot use math/rand/v2 anyway in go1.21 🤷.

I don't think I understand. The goal of this PR is to update 1.22 and the argument to not wait for compatibility is because after upgrading to 1.22 we are still using 1.21? What is the point of upgrading then? 😅

The goal is to update the toolchain to go1.22, not to migrate the codebase to things new in 1.22. The toolchain can be bumped without any issues. Just the fact that some linter will falsely scream if you use a tiny subset of new features shouldn't block from upgrading the toolchain in my opinion.

@fasmat
Copy link
Member

fasmat commented Feb 26, 2024

The goal is to update the toolchain to go1.22, not to migrate the codebase to things new in 1.22. The toolchain can be bumped without any issues. Just the fact that some linter will falsely scream if you use a tiny subset of new features shouldn't block from upgrading the toolchain in my opinion.

I don't understand. As you said we are not using any of the new features of 1.22 and don't plan on doing so in the near future; actually using some of them will also block merging PRs because of golangci-lint. So why rush upgrading? Go 1.21 will be supported for another 6 months, we can update as soon as golanci-lint 1.56.4 is out?

@dshulyak
Copy link
Contributor

beside changes in language and stdlib, there are also regular improvements in golang runtime. so if we will compile with new toolchain we will benefit from them. that said there are also sometime regressions in newer versions, and i personally would wait until 2 or 3 patch release.

appveyor.yml Outdated Show resolved Hide resolved
@poszu poszu changed the title Bump Go to 1.22.0 Bump Go to 1.22.1 Mar 25, 2024
@poszu
Copy link
Contributor Author

poszu commented Apr 4, 2024

@fasmat I bumped Go to 1.22.2. Do you think you could approve now?

@poszu poszu requested a review from fasmat April 4, 2024 07:19
@poszu poszu changed the title Bump Go to 1.22.1 Bump Go to 1.22.2 Apr 4, 2024
@fasmat
Copy link
Member

fasmat commented Apr 4, 2024

bors merge

@spacemesh-bors
Copy link

spacemesh-bors bot commented Apr 4, 2024

Merge conflict.

@fasmat
Copy link
Member

fasmat commented Apr 4, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Apr 4, 2024
@spacemesh-bors
Copy link

spacemesh-bors bot commented Apr 4, 2024

Build failed:

@poszu
Copy link
Contributor Author

poszu commented Apr 4, 2024

Systest logs are incomplete, can't tell what went wrong - retrying.

bors retry

spacemesh-bors bot pushed a commit that referenced this pull request Apr 4, 2024
@spacemesh-bors
Copy link

spacemesh-bors bot commented Apr 4, 2024

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title Bump Go to 1.22.2 [Merged by Bors] - Bump Go to 1.22.2 Apr 4, 2024
@spacemesh-bors spacemesh-bors bot closed this Apr 4, 2024
@spacemesh-bors spacemesh-bors bot deleted the bump-go-1.22 branch April 4, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants