Skip to content

Commit

Permalink
all: remove dependency on golang.org/exp (ethereum#29314)
Browse files Browse the repository at this point in the history
This change includes a leftovers from ethereum#29307
- using the [new `slices` package](https://go.dev/doc/go1.21#slices) and
- using the [new `cmp.Ordered`](https://go.dev/doc/go1.21#cmp) instead of exp `constraints.Ordered`
  • Loading branch information
holiman authored Mar 25, 2024
1 parent ae47004 commit 14cc967
Show file tree
Hide file tree
Showing 42 changed files with 51 additions and 56 deletions.
2 changes: 1 addition & 1 deletion accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"sync"
Expand All @@ -31,7 +32,6 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"golang.org/x/exp/slices"
)

// Minimum amount of time between cache reloads. This limit applies if the platform does
Expand Down
2 changes: 1 addition & 1 deletion accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"os"
"path/filepath"
"reflect"
"slices"
"testing"
"time"

"github.com/cespare/cp"
"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion accounts/keystore/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math/rand"
"os"
"runtime"
"slices"
"strings"
"sync"
"sync/atomic"
Expand All @@ -30,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event"
"golang.org/x/exp/slices"
)

var testSigData = make([]byte, 32)
Expand Down
3 changes: 1 addition & 2 deletions build/update-license.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strconv"
"strings"
"sync"
"text/template"
"time"

"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/devp2p/dns_route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/dnsdisc"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/devp2p/internal/ethtest/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"math/big"
"os"
"path/filepath"
"slices"
"sort"
"strings"

Expand All @@ -40,7 +41,6 @@ import (
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/exp/slices"
)

// Chain is a lightweight blockchain-like store which can read a hivechain
Expand Down
2 changes: 1 addition & 1 deletion cmd/devp2p/nodeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/p2p/enode"
"golang.org/x/exp/slices"
)

const jsonIndent = " "
Expand Down
10 changes: 5 additions & 5 deletions common/prque/lazyqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package prque

import (
"cmp"
"container/heap"
"time"

"github.com/ethereum/go-ethereum/common/mclock"
"golang.org/x/exp/constraints"
)

// LazyQueue is a priority queue data structure where priorities can change over
Expand All @@ -33,7 +33,7 @@ import (
//
// If the upper estimate is exceeded then Update should be called for that item.
// A global Refresh function should also be called periodically.
type LazyQueue[P constraints.Ordered, V any] struct {
type LazyQueue[P cmp.Ordered, V any] struct {
clock mclock.Clock
// Items are stored in one of two internal queues ordered by estimated max
// priority until the next and the next-after-next refresh. Update and Refresh
Expand All @@ -50,12 +50,12 @@ type LazyQueue[P constraints.Ordered, V any] struct {
}

type (
PriorityCallback[P constraints.Ordered, V any] func(data V) P // actual priority callback
MaxPriorityCallback[P constraints.Ordered, V any] func(data V, until mclock.AbsTime) P // estimated maximum priority callback
PriorityCallback[P cmp.Ordered, V any] func(data V) P // actual priority callback
MaxPriorityCallback[P cmp.Ordered, V any] func(data V, until mclock.AbsTime) P // estimated maximum priority callback
)

// NewLazyQueue creates a new lazy queue
func NewLazyQueue[P constraints.Ordered, V any](setIndex SetIndexCallback[V], priority PriorityCallback[P, V], maxPriority MaxPriorityCallback[P, V], clock mclock.Clock, refreshPeriod time.Duration) *LazyQueue[P, V] {
func NewLazyQueue[P cmp.Ordered, V any](setIndex SetIndexCallback[V], priority PriorityCallback[P, V], maxPriority MaxPriorityCallback[P, V], clock mclock.Clock, refreshPeriod time.Duration) *LazyQueue[P, V] {
q := &LazyQueue[P, V]{
popQueue: newSstack[P, V](nil),
setIndex: setIndex,
Expand Down
7 changes: 3 additions & 4 deletions common/prque/prque.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
package prque

import (
"cmp"
"container/heap"

"golang.org/x/exp/constraints"
)

// Priority queue data structure.
type Prque[P constraints.Ordered, V any] struct {
type Prque[P cmp.Ordered, V any] struct {
cont *sstack[P, V]
}

// New creates a new priority queue.
func New[P constraints.Ordered, V any](setIndex SetIndexCallback[V]) *Prque[P, V] {
func New[P cmp.Ordered, V any](setIndex SetIndexCallback[V]) *Prque[P, V] {
return &Prque[P, V]{newSstack[P, V](setIndex)}
}

Expand Down
8 changes: 4 additions & 4 deletions common/prque/sstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

package prque

import "golang.org/x/exp/constraints"
import "cmp"

// The size of a block of data
const blockSize = 4096

// A prioritized item in the sorted stack.
type item[P constraints.Ordered, V any] struct {
type item[P cmp.Ordered, V any] struct {
value V
priority P
}
Expand All @@ -29,7 +29,7 @@ type SetIndexCallback[V any] func(data V, index int)
// Internal sortable stack data structure. Implements the Push and Pop ops for
// the stack (heap) functionality and the Len, Less and Swap methods for the
// sortability requirements of the heaps.
type sstack[P constraints.Ordered, V any] struct {
type sstack[P cmp.Ordered, V any] struct {
setIndex SetIndexCallback[V]
size int
capacity int
Expand All @@ -40,7 +40,7 @@ type sstack[P constraints.Ordered, V any] struct {
}

// Creates a new, empty stack.
func newSstack[P constraints.Ordered, V any](setIndex SetIndexCallback[V]) *sstack[P, V] {
func newSstack[P cmp.Ordered, V any](setIndex SetIndexCallback[V]) *sstack[P, V] {
result := new(sstack[P, V])
result.setIndex = setIndex
result.active = make([]*item[P, V], blockSize)
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package clique
import (
"bytes"
"encoding/json"
"slices"
"time"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"golang.org/x/exp/slices"
)

// Vote represents a single vote that an authorized signer made to modify the
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/ecdsa"
"fmt"
"math/big"
"slices"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -30,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"golang.org/x/exp/slices"
)

// testerAccountPool is a pool to maintain currently active tester accounts,
Expand Down
2 changes: 1 addition & 1 deletion core/forkid/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"math"
"math/big"
"reflect"
"slices"
"strings"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion core/mkalloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import (
"fmt"
"math/big"
"os"
"slices"
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/exp/slices"
)

type allocItem struct {
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"math/big"
"slices"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
Expand All @@ -31,7 +32,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/exp/slices"
)

// ReadCanonicalHash retrieves the hash assigned to a canonical block number.
Expand Down
2 changes: 1 addition & 1 deletion core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"math"
"math/rand"
"slices"
"sync"
"sync/atomic"
"time"
Expand All @@ -29,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
bloomfilter "github.com/holiman/bloomfilter/v2"
"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion core/state/snapshot/iterator_fast.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package snapshot
import (
"bytes"
"fmt"
"slices"
"sort"

"github.com/ethereum/go-ethereum/common"
"golang.org/x/exp/slices"
)

// weightedIterator is a iterator with an assigned weight. It is used to prioritise
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/legacypool/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"container/heap"
"math"
"math/big"
"slices"
"sort"
"sync"
"sync/atomic"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/holiman/uint256"
"golang.org/x/exp/slices"
)

// nonceHeap is a heap.Interface implementation over 64bit unsigned integers for
Expand Down
2 changes: 1 addition & 1 deletion eth/api_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"reflect"
"slices"
"strings"
"testing"

Expand All @@ -32,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/triedb"
"github.com/holiman/uint256"
"golang.org/x/exp/slices"
)

var dumper = spew.ConfigState{Indent: " "}
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/feehistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"fmt"
"math"
"math/big"
"slices"
"sync/atomic"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gasprice
import (
"context"
"math/big"
"slices"
"sync"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -30,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"golang.org/x/exp/slices"
)

const sampleNumber = 3 // Number of transactions sampled in a block
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/snap/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"math/big"
mrand "math/rand"
"slices"
"sync"
"testing"
"time"
Expand All @@ -41,7 +42,6 @@ import (
"github.com/ethereum/go-ethereum/triedb/pathdb"
"github.com/holiman/uint256"
"golang.org/x/crypto/sha3"
"golang.org/x/exp/slices"
)

func TestHashing(t *testing.T) {
Expand Down
Loading

0 comments on commit 14cc967

Please sign in to comment.