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

refactor: replace golang.org/x/exp with stdlib #23501

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

Juneezee
Copy link
Contributor

@Juneezee Juneezee commented Jan 24, 2025

Description

These experimental packages are now available in the Go standard library since Go 1.21 and Go 1.23:

  1. golang.org/x/exp/slices -> slices (https://go.dev/doc/go1.21#slices)
  2. golang.org/x/exp/maps -> maps (https://go.dev/doc/go1.21#maps)

The key difference is that maps.Keys in the golang.org/x/exp/maps package return a slice, whereas maps.Keys in the standard library return an iterator. To work with slices, we need to use slices.Collect to convert the iterator into a slice.

Reference: https://go.dev/doc/go1.23#iterators


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • [N/A] confirmed ! in the type prefix if API or client breaking change No breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • [N/A] included the necessary unit and integration tests Refactor only. No new features or behavior change
  • [N/A] added a changelog entry to CHANGELOG.md No user-facing changes
  • [N/A] updated the relevant documentation or specification, including comments for documenting Go code Refactor only. No new features or behavior change
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

Release Notes

  • Dependencies

    • Removed external dependency on golang.org/x/exp
    • Updated to use standard library packages for slices and maps
  • Package Updates

    • Migrated type constraints from constraints.Ordered to cmp.Ordered
    • Updated Go version to 1.23 in multiple modules
    • Simplified import statements across several packages
  • Performance

    • Streamlined key retrieval and sorting operations
    • Minor optimization in map and slice handling

These changes primarily focus on modernizing package dependencies and improving code clarity without altering core functionality.

These experimental packages are now available in the Go standard
library since Go 1.21 and Go 1.23:

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/maps -> maps [2]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.21#maps
[3]: https://go.dev/doc/go1.23#iterators

Signed-off-by: Eng Zer Jun <[email protected]>
@Juneezee Juneezee requested review from a team, lucaslopezf, alpe and julienrbrt as code owners January 24, 2025 16:17
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

📝 Walkthrough

Walkthrough

This pull request focuses on updating the codebase to utilize standard library packages instead of external experimental packages. Key changes include replacing imports from golang.org/x/exp with standard library equivalents like slices, maps, and cmp. The modifications span multiple modules, including depinject, math, and orm, primarily involving updates to import statements and type constraints. Additionally, the Go version is updated to 1.23 in some module files, and certain dependencies are managed differently.

Changes

File Change Summary
depinject/check_type.go Replaced golang.org/x/exp/slices import with standard library slices
depinject/go.mod Updated Go version to 1.23, removed golang.org/x/exp dependency
depinject/internal/util/util.go Replaced constraints.Ordered with cmp.Ordered in function signatures
depinject/provider_desc.go Updated slices import to standard library version
math/go.mod Removed golang.org/x/exp dependency, retracted specific module versions
math/max_min.go Updated type constraints from constraints.Ordered to cmp.Ordered
orm/go.mod Changed golang.org/x/exp from direct to indirect dependency
orm/internal/codegen/query.go Replaced experimental package imports with standard library versions
orm/model/ormdb/genesis.go Updated key collection method using slices.Collect

Possibly related PRs

Suggested Labels

C:core/testing, C:Store, C:x/accounts, C:x/bank, C:x/feegrant, C:x/gov, C:x/staking, C:x/consensus, C:x/distribution, C:x/epochs, C:x/mint, C:x/nft, C:x/protocolpool, C:x/slashing, C:x/group, C:x/authz, C:Simulations, C:CLI, backport/v0.52.x

Suggested Reviewers

  • lucaslopezf
  • julienrbrt
  • kocubinski
  • tac0turtle
  • aaronc

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 254685c and 235618b.

⛔ Files ignored due to path filters (2)
  • depinject/go.sum is excluded by !**/*.sum
  • math/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • depinject/go.mod (1 hunks)
  • math/go.mod (0 hunks)
  • orm/go.mod (1 hunks)
💤 Files with no reviewable changes (1)
  • math/go.mod
🚧 Files skipped from review as they are similar to previous changes (2)
  • depinject/go.mod
  • orm/go.mod
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: Analyze
  • GitHub Check: golangci-lint
  • GitHub Check: Summary

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the C:orm label Jan 24, 2025
Copy link
Contributor Author

@Juneezee Juneezee left a comment

Choose a reason for hiding this comment

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

I have performed a self-review of my code changes.

Comment on lines -22 to +23
func OrderedMapKeys[K constraints.Ordered, V any](m map[K]V) []K {
keys := maps.Keys(m)
slices.Sort(keys)
return keys
func OrderedMapKeys[K cmp.Ordered, V any](m map[K]V) []K {
return slices.Sorted(maps.Keys(m))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the PR description, this is the only difference between maps.Keys from the golang.org/x/exp/maps package and the standard library maps package.

For reference, see https://pkg.go.dev/maps#Keys and https://pkg.go.dev/slices#Collect

@aljo242
Copy link
Collaborator

aljo242 commented Jan 24, 2025

@Juneezee thanks for opening this! this is something we've been meaning to do :)

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Thanks for this! Originally we didn't do it there to not have to bump the minimum go version. But given probably nobody should build their in a version less than go 1.23 in feb that's fine 👍🏾

@aljo242 aljo242 added this pull request to the merge queue Jan 24, 2025
Merged via the queue into cosmos:main with commit 2675857 Jan 24, 2025
70 of 73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants