Skip to content

refactor: replace sort.Slice with slices.Sort for natural ordering#1068

Closed
tsinglua wants to merge 1 commit intocosmos:mainfrom
tsinglua:main
Closed

refactor: replace sort.Slice with slices.Sort for natural ordering#1068
tsinglua wants to merge 1 commit intocosmos:mainfrom
tsinglua:main

Conversation

@tsinglua
Copy link

@tsinglua tsinglua commented Mar 11, 2026

Description

There is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.

Closes: #XXXX


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...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

@greptile-apps
Copy link

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR refactors two uses of sort.Slice to the more concise slices.Sort from Go's 1.21 standard library — a valid and idiomatic improvement. However, both changed files neglect to remove the now-unused "sort" import, which will prevent the package from compiling.

Key changes:

  • utils/utils.go: SortSlice[T cmp.Ordered] now delegates to slices.Sort instead of an inline sort.Slice comparator — functionally equivalent, more readable.
  • x/vm/keeper/params.go: EnableEIPs now sorts ExtraEIPs with slices.Sort — functionally equivalent.

Issues found:

  • Both utils/utils.go (line 9) and x/vm/keeper/params.go (line 6) retain the "sort" import after it is no longer used. Go treats unused imports as compile errors, so this PR will not build as-is. The "sort" import must be removed from both files.

Confidence Score: 2/5

  • This PR will not compile due to unused imports left in both changed files.
  • The refactoring intent is correct and the slices.Sort replacements are semantically equivalent. However, the leftover "sort" import in both utils/utils.go and x/vm/keeper/params.go are unused, which is a hard compile error in Go. The PR cannot be merged until these are removed.
  • utils/utils.go and x/vm/keeper/params.go both need the stale "sort" import removed.

Important Files Changed

Filename Overview
utils/utils.go Replaced sort.Slice with slices.Sort inside SortSlice — correct semantics, but the now-unused "sort" import was not removed, causing a compile error.
x/vm/keeper/params.go Replaced sort.Slice with slices.Sort in EnableEIPs — correct semantics, but the now-unused "sort" import was not removed, causing a compile error.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["SortSlice[T cmp.Ordered](slice []T)"] --> B["slices.Sort(slice)"]
    C["EnableEIPs(...int64)"] --> D["append ExtraEIPs"] --> E["slices.Sort(evmParams.ExtraEIPs)"] --> F["SetParams"]
    G["SetParams(params)"] --> H["slices.Sort(ActiveStaticPrecompiles)"] --> I["params.Validate()"] --> J["store.Set(...)"]

    style B fill:#90EE90
    style E fill:#90EE90
    style H fill:#90EE90
Loading

Comments Outside Diff (1)

  1. x/vm/keeper/params.go, line 6 (link)

    Unused "sort" import causes compile error

    The only usage of sort in this file was sort.Slice in EnableEIPs, which has been replaced with slices.Sort. The "sort" import is now unused and will cause a compile error.

Last reviewed commit: c606736

Signed-off-by: tsinglua <tsinglua@outlook.com>
@aljo242
Copy link
Contributor

aljo242 commented Mar 11, 2026

closing for now - PRs require signed commits.

Could you please re-open with signed commits?

@tsinglua
Copy link
Author

closing for now - PRs require signed commits.

Could you please re-open with signed commits?

@aljo242 Thanks. The signed pr #1075
Please review it again.😄

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.

2 participants