Skip to content

Commit 2675857

Browse files
Juneezeealjo242
andauthored
refactor: replace golang.org/x/exp with stdlib (#23501)
Signed-off-by: Eng Zer Jun <[email protected]> Co-authored-by: Alex | Interchain Labs <[email protected]>
1 parent 66e610c commit 2675857

File tree

11 files changed

+21
-31
lines changed

11 files changed

+21
-31
lines changed

depinject/check_type.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package depinject
33
import (
44
"fmt"
55
"reflect"
6+
"slices"
67
"strings"
78
"unicode"
8-
9-
"golang.org/x/exp/slices"
109
)
1110

1211
// isExportedType checks if the type is exported and not in an internal

depinject/go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module cosmossdk.io/depinject
22

3-
go 1.22
3+
go 1.23
44

55
require (
66
github.com/cosmos/cosmos-proto v1.0.0-beta.5
77
github.com/cosmos/gogoproto v1.7.0
88
github.com/stretchr/testify v1.10.0
9-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
109
google.golang.org/grpc v1.70.0
1110
google.golang.org/protobuf v1.36.3
1211
gotest.tools/v3 v3.5.1

depinject/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
3434
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3535
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=
3636
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
37-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
38-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
3937
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
4038
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
4139
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=

depinject/internal/util/util.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package util
22

33
import (
4-
"golang.org/x/exp/constraints"
5-
"golang.org/x/exp/maps"
6-
"golang.org/x/exp/slices"
4+
"cmp"
5+
"maps"
6+
"slices"
77
)
88

99
// IterateMapOrdered iterates over the map with keys sorted in ascending order
1010
// calling forEach for each key-value pair as long as forEach does not return an error.
11-
func IterateMapOrdered[K constraints.Ordered, V any](m map[K]V, forEach func(k K, v V) error) error {
11+
func IterateMapOrdered[K cmp.Ordered, V any](m map[K]V, forEach func(k K, v V) error) error {
1212
keys := OrderedMapKeys(m)
1313
for _, k := range keys {
1414
if err := forEach(k, m[k]); err != nil {
@@ -19,8 +19,6 @@ func IterateMapOrdered[K constraints.Ordered, V any](m map[K]V, forEach func(k K
1919
}
2020

2121
// OrderedMapKeys returns the map keys in ascending order.
22-
func OrderedMapKeys[K constraints.Ordered, V any](m map[K]V) []K {
23-
keys := maps.Keys(m)
24-
slices.Sort(keys)
25-
return keys
22+
func OrderedMapKeys[K cmp.Ordered, V any](m map[K]V) []K {
23+
return slices.Sorted(maps.Keys(m))
2624
}

depinject/provider_desc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package depinject
33
import (
44
"fmt"
55
"reflect"
6+
"slices"
67
"strings"
78
"unicode"
8-
9-
"golang.org/x/exp/slices"
109
)
1110

1211
// providerDescriptor defines a special provider type that is defined by

math/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.22
55
require (
66
github.com/cockroachdb/apd/v3 v3.2.1
77
github.com/stretchr/testify v1.10.0
8-
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0
98
sigs.k8s.io/yaml v1.4.0
109
)
1110

math/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
2626
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
2727
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
2828
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
29-
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8=
30-
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
3129
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
3230
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
3331
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=

math/max_min.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package math
22

3-
import "golang.org/x/exp/constraints"
3+
import "cmp"
44

5-
func Max[T constraints.Ordered](a, b T, rest ...T) T {
5+
func Max[T cmp.Ordered](a, b T, rest ...T) T {
66
max := a
77
if b > a {
88
max = b
@@ -15,7 +15,7 @@ func Max[T constraints.Ordered](a, b T, rest ...T) T {
1515
return max
1616
}
1717

18-
func Min[T constraints.Ordered](a, b T, rest ...T) T {
18+
func Min[T cmp.Ordered](a, b T, rest ...T) T {
1919
min := a
2020
if b < a {
2121
min = b

orm/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require (
1515
github.com/regen-network/gocuke v1.1.1
1616
github.com/stretchr/testify v1.10.0
1717
go.uber.org/mock v0.5.0
18-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
1918
google.golang.org/grpc v1.70.0
2019
google.golang.org/protobuf v1.36.3
2120
gotest.tools/v3 v3.5.1
@@ -65,6 +64,7 @@ require (
6564
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
6665
github.com/tendermint/go-amino v0.16.0 // indirect
6766
github.com/tidwall/btree v1.7.0 // indirect
67+
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
6868
golang.org/x/net v0.34.0 // indirect
6969
golang.org/x/sys v0.29.0 // indirect
7070
golang.org/x/text v0.21.0 // indirect

orm/internal/codegen/query.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package codegen
33
import (
44
"bytes"
55
"fmt"
6+
"maps"
67
"os"
8+
"slices"
79

810
"github.com/iancoleman/strcase"
9-
"golang.org/x/exp/maps"
10-
"golang.org/x/exp/slices"
1111
"google.golang.org/protobuf/compiler/protogen"
1212
"google.golang.org/protobuf/proto"
1313
"google.golang.org/protobuf/reflect/protoreflect"
@@ -57,8 +57,7 @@ func (g queryProtoGen) gen() error {
5757
outBuf.F("package %s;", g.Desc.Package())
5858
outBuf.F("")
5959

60-
imports := maps.Keys(g.imports)
61-
slices.Sort(imports)
60+
imports := slices.Sorted(maps.Keys(g.imports))
6261
for _, i := range imports {
6362
outBuf.F(`import "%s";`, i)
6463
}

orm/model/ormdb/genesis.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package ormdb
33
import (
44
"context"
55
"fmt"
6+
"maps"
7+
"slices"
68
"sort"
79

8-
"golang.org/x/exp/maps"
910
"google.golang.org/protobuf/reflect/protoreflect"
1011

1112
"cosmossdk.io/core/appmodule"
@@ -22,7 +23,7 @@ func (m appModuleGenesisWrapper) IsOnePerModuleType() {}
2223
func (m appModuleGenesisWrapper) IsAppModule() {}
2324

2425
func (m appModuleGenesisWrapper) DefaultGenesis(target appmodule.GenesisTarget) error {
25-
tableNames := maps.Keys(m.tablesByName)
26+
tableNames := slices.Collect(maps.Keys(m.tablesByName))
2627
sort.Slice(tableNames, func(i, j int) bool {
2728
ti, tj := tableNames[i], tableNames[j]
2829
return ti.Name() < tj.Name()
@@ -50,7 +51,7 @@ func (m appModuleGenesisWrapper) DefaultGenesis(target appmodule.GenesisTarget)
5051

5152
func (m appModuleGenesisWrapper) ValidateGenesis(source appmodule.GenesisSource) error {
5253
errMap := map[protoreflect.FullName]error{}
53-
names := maps.Keys(m.tablesByName)
54+
names := slices.Collect(maps.Keys(m.tablesByName))
5455
sort.Slice(names, func(i, j int) bool {
5556
ti, tj := names[i], names[j]
5657
return ti.Name() < tj.Name()
@@ -124,7 +125,7 @@ func (m appModuleGenesisWrapper) InitGenesis(ctx context.Context, source appmodu
124125

125126
func (m appModuleGenesisWrapper) ExportGenesis(ctx context.Context, sink appmodule.GenesisTarget) error {
126127
// Ensure that we export the tables in a deterministic order.
127-
tableNames := maps.Keys(m.tablesByName)
128+
tableNames := slices.Collect(maps.Keys(m.tablesByName))
128129
sort.Slice(tableNames, func(i, j int) bool {
129130
ti, tj := tableNames[i], tableNames[j]
130131
return ti.Name() < tj.Name()

0 commit comments

Comments
 (0)