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

Go 1.21 cleanups #13862

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0
github.com/xlab/treeprint v1.2.0
go.uber.org/goleak v1.1.11
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090
golang.org/x/sync v0.1.0
modernc.org/sqlite v1.20.3
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
4 changes: 1 addition & 3 deletions go/cache/ristretto/bloom/bbloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ func (bl *Bloom) Size(sz uint64) {

// Clear resets the Bloom filter.
func (bl *Bloom) Clear() {
for i := range bl.bitset {
bl.bitset[i] = 0
}
clear(bl.bitset)
}

// Set sets the bit[idx] of bitset.
Expand Down
4 changes: 1 addition & 3 deletions go/cache/ristretto/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ func (r cmRow) reset() {

func (r cmRow) clear() {
// Zero each counter.
for i := range r {
r[i] = 0
}
clear(r)
}

func (r cmRow) string() string {
Expand Down
37 changes: 37 additions & 0 deletions go/maps2/maps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2023 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package maps2

// Keys returns the keys of the map m.
// The keys will be in an indeterminate order.
func Keys[M ~map[K]V, K comparable, V any](m M) []K {
r := make([]K, 0, len(m))
for k := range m {
r = append(r, k)
}
return r
}

// Values returns the values of the map m.
// The values will be in an indeterminate order.
func Values[M ~map[K]V, K comparable, V any](m M) []V {
r := make([]V, 0, len(m))
for _, v := range m {
r = append(r, v)
}
return r
}
4 changes: 1 addition & 3 deletions go/mysql/auth_server_static_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ func TestStaticConfigHUP(t *testing.T) {
mu.Lock()
defer mu.Unlock()
// delete registered Auth server
for auth := range authServers {
delete(authServers, auth)
}
clear(authServers)
}

func TestStaticConfigHUPWithRotation(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions go/mysql/collations/8bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *Collation_8bit_bin) WeightString(dst, src []byte, numCodepoints int) []
case PadToMax:
padToMax = true
default:
copyCodepoints = minInt(copyCodepoints, numCodepoints)
copyCodepoints = min(copyCodepoints, numCodepoints)
}

dst = append(dst, src[:copyCodepoints]...)
Expand All @@ -92,7 +92,7 @@ func (c *Collation_8bit_bin) Hash(hasher *vthash.Hasher, src []byte, numCodepoin
return
}

tocopy := minInt(len(src), numCodepoints)
tocopy := min(len(src), numCodepoints)
hasher.Write(src[:tocopy])

numCodepoints -= tocopy
Expand Down Expand Up @@ -153,7 +153,7 @@ func (c *Collation_8bit_simple_ci) IsBinary() bool {

func (c *Collation_8bit_simple_ci) Collate(left, right []byte, rightIsPrefix bool) int {
sortOrder := c.sort
cmpLen := minInt(len(left), len(right))
cmpLen := min(len(left), len(right))

for i := 0; i < cmpLen; i++ {
sortL, sortR := sortOrder[left[i]], sortOrder[right[i]]
Expand All @@ -178,7 +178,7 @@ func (c *Collation_8bit_simple_ci) WeightString(dst, src []byte, numCodepoints i
case PadToMax:
padToMax = true
default:
copyCodepoints = minInt(copyCodepoints, numCodepoints)
copyCodepoints = min(copyCodepoints, numCodepoints)
}

for _, ch := range src[:copyCodepoints] {
Expand All @@ -192,7 +192,7 @@ func (c *Collation_8bit_simple_ci) Hash(hasher *vthash.Hasher, src []byte, numCo

var tocopy = len(src)
if numCodepoints > 0 {
tocopy = minInt(tocopy, numCodepoints)
tocopy = min(tocopy, numCodepoints)
}

hasher.Write64(uint64(c.id))
Expand Down Expand Up @@ -280,7 +280,7 @@ func (c *Collation_binary) WeightString(dst, src []byte, numCodepoints int) []by
case PadToMax:
padToMax = true
default:
copyCodepoints = minInt(copyCodepoints, numCodepoints)
copyCodepoints = min(copyCodepoints, numCodepoints)
}

dst = append(dst, src[:copyCodepoints]...)
Expand Down
7 changes: 0 additions & 7 deletions go/mysql/collations/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,3 @@ type WildcardPattern interface {
type Charset = charset.Charset

const PadToMax = math.MaxInt32

func minInt(i1, i2 int) int {
if i1 < i2 {
return i1
}
return i2
}
4 changes: 2 additions & 2 deletions go/mysql/collations/multibyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *Collation_multibyte) Collate(left, right []byte, isPrefix bool) int {
return collationBinary(left, right, isPrefix)
}

cmpLen := minInt(len(left), len(right))
cmpLen := min(len(left), len(right))
cs := c.charset
sortOrder := c.sort
for i := 0; i < cmpLen; i++ {
Expand All @@ -62,7 +62,7 @@ func (c *Collation_multibyte) Collate(left, right []byte, isPrefix bool) int {
}
_, widthL := cs.DecodeRune(left[i:])
_, widthR := cs.DecodeRune(right[i:])
switch minInt(widthL, widthR) {
switch min(widthL, widthR) {
case 4:
i++
if left[i] != right[i] {
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/uca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"math/rand"
"slices"
"sort"
"strings"
"sync"
Expand All @@ -28,7 +29,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"vitess.io/vitess/go/mysql/collations/charset"
"vitess.io/vitess/go/vt/vthash"
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/unicode.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (c *Collation_unicode_bin) Wildcard(pat []byte, matchOne rune, matchMany ru
}

func collationBinary(left, right []byte, rightPrefix bool) int {
minLen := minInt(len(left), len(right))
minLen := min(len(left), len(right))
if diff := bytes.Compare(left[:minLen], right[:minLen]); diff != 0 {
return diff
}
Expand Down
7 changes: 0 additions & 7 deletions go/mysql/decimal/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,6 @@ func RescalePair(d1 Decimal, d2 Decimal) (Decimal, Decimal) {
return d1, d2.rescale(baseScale)
}

func min(x, y int32) int32 {
if x >= y {
return y
}
return x
}

// largestForm returns the largest decimal that can be represented
// with the given amount of integral and fractional digits
// Example:
Expand Down
3 changes: 1 addition & 2 deletions go/mysql/icuregex/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ package icuregex

import (
"math"
"slices"
"strings"
"unicode/utf8"

"golang.org/x/exp/slices"

"vitess.io/vitess/go/mysql/icuregex/internal/pattern"
"vitess.io/vitess/go/mysql/icuregex/internal/ucase"
"vitess.io/vitess/go/mysql/icuregex/internal/uchar"
Expand Down
60 changes: 29 additions & 31 deletions go/mysql/icuregex/internal/uchar/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ limitations under the License.

package uchar

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

func uMask[T constraints.Integer](x T) uint32 {
func Mask[T ~int | ~int8](x T) uint32 {
return 1 << x
}

Expand Down Expand Up @@ -110,68 +108,68 @@ const (
)

var (
GcCnMask = uMask(GeneralOtherTypes)
GcCnMask = Mask(GeneralOtherTypes)

/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcLuMask = uMask(UppercaseLetter)
GcLuMask = Mask(UppercaseLetter)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcLlMask = uMask(LowercaseLetter)
GcLlMask = Mask(LowercaseLetter)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcLtMask = uMask(TitlecaseLetter)
GcLtMask = Mask(TitlecaseLetter)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcLmMask = uMask(ModifierLetter)
GcLmMask = Mask(ModifierLetter)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcLoMask = uMask(OtherLetter)
GcLoMask = Mask(OtherLetter)

/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcMnMask = uMask(NonSpacingMask)
GcMnMask = Mask(NonSpacingMask)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcMeMask = uMask(EnclosingMark)
GcMeMask = Mask(EnclosingMark)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcMcMask = uMask(CombiningSpacingMask)
GcMcMask = Mask(CombiningSpacingMask)

/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcNdMask = uMask(DecimalDigitNumber)
GcNdMask = Mask(DecimalDigitNumber)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcNlMask = uMask(LetterNumber)
GcNlMask = Mask(LetterNumber)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcNoMask = uMask(OtherNumber)
GcNoMask = Mask(OtherNumber)

/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcZsMask = uMask(SpaceSeparator)
GcZsMask = Mask(SpaceSeparator)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcZlMask = uMask(LineSeparator)
GcZlMask = Mask(LineSeparator)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcZpMask = uMask(ParagraphSeparator)
GcZpMask = Mask(ParagraphSeparator)

/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcCcMask = uMask(ControlChar)
GcCcMask = Mask(ControlChar)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcCfMask = uMask(FormatChar)
GcCfMask = Mask(FormatChar)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcCoMask = uMask(PrivateUseChar)
GcCoMask = Mask(PrivateUseChar)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcCsMask = uMask(Surrogate)
GcCsMask = Mask(Surrogate)

/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcPdMask = uMask(DashPunctuation)
GcPdMask = Mask(DashPunctuation)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcPsMask = uMask(StartPunctuation)
GcPsMask = Mask(StartPunctuation)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcPeMask = uMask(EndPunctuation)
GcPeMask = Mask(EndPunctuation)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcPcMask = uMask(ConnectorPunctuation)
GcPcMask = Mask(ConnectorPunctuation)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcPoMask = uMask(OtherPunctuation)
GcPoMask = Mask(OtherPunctuation)

/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcSmMask = uMask(MathSymbol)
GcSmMask = Mask(MathSymbol)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcScMask = uMask(CurrencySymbol)
GcScMask = Mask(CurrencySymbol)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcSkMask = uMask(ModifierSymbol)
GcSkMask = Mask(ModifierSymbol)
/** Mask constant for a UCharCategory. @stable ICU 2.1 */
GcSoMask = uMask(OtherSymbol)
GcSoMask = Mask(OtherSymbol)

/** Mask constant for multiple UCharCategory bits (L Letters). @stable ICU 2.1 */
GcLMask = (GcLuMask | GcLlMask | GcLtMask | GcLmMask | GcLoMask)
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/internal/uchar/uchar.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func IsGraphPOSIX(c rune) bool {
props := trie().Get16(c)
/* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */
/* comparing ==0 returns FALSE for the categories mentioned */
return uMask(getCategory(props))&(GcCcMask|GcCsMask|GcCnMask|GcZMask) == 0
return Mask(getCategory(props))&(GcCcMask|GcCsMask|GcCnMask|GcZMask) == 0
}

func IsXDigit(c rune) bool {
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/internal/uprops/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func ApplyIntPropertyValue(u *uset.UnicodeSet, prop Property, value int32) error
return err
}
u.ApplyFilter(inclusions, func(ch rune) bool {
return (uMask(uchar.CharType(ch)) & uint32(value)) != 0
return (uchar.Mask(uchar.CharType(ch)) & uint32(value)) != 0
})
case prop == UCharScriptExtensions:
inclusions, err := getInclusionsForProperty(prop)
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/internal/uprops/uprops.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func getIntPropertyValue(c rune, which Property) int32 {
iprop := intProps[which-UCharIntStart]
return iprop.getValue(iprop, c, which)
} else if which == UCharGeneralCategoryMask {
return int32(uMask(uchar.CharType(c)))
return int32(uchar.Mask(uchar.CharType(c)))
}
return 0 // undefined
}
Expand Down
Loading