Skip to content

Commit

Permalink
Remove stdlib api functions now that we're on Go 1.23 (#3639)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkwarren authored Feb 24, 2025
1 parent 24f475b commit 72d85fb
Show file tree
Hide file tree
Showing 29 changed files with 94 additions and 206 deletions.
2 changes: 1 addition & 1 deletion private/buf/buflsp/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (s *symbol) ResolveCrossFile(ctx context.Context) {

// Done.
kind.file = def.file
kind.path = append(slicesext.Copy(ref.path), components...)
kind.path = append(slices.Clone(ref.path), components...)
return
}

Expand Down
5 changes: 3 additions & 2 deletions private/buf/bufmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"io/fs"
"log/slog"
"slices"
"sort"
"strings"

Expand Down Expand Up @@ -521,7 +522,7 @@ func (m *migrator) upgradeModuleKeysToB5(
ctx context.Context,
moduleKeys []bufmodule.ModuleKey,
) ([]bufmodule.ModuleKey, error) {
moduleKeys = slicesext.Copy(moduleKeys)
moduleKeys = slices.Clone(moduleKeys)

b4IndexedModuleKeys, err := slicesext.FilterError(
slicesext.ToIndexed(moduleKeys),
Expand Down Expand Up @@ -743,7 +744,7 @@ func equivalentCheckConfigInV2(
return rule.ID()
},
)
if slicesext.ElementsEqual(expectedIDs, simplyTranslatedIDs) {
if slices.Equal(expectedIDs, simplyTranslatedIDs) {
// If the simple translation is equivalent to before, use it.
return simplyTranslatedCheckConfig, nil
}
Expand Down
6 changes: 3 additions & 3 deletions private/buf/bufprotopluginexec/protoc_proxy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"io"
"log/slog"
"path/filepath"
"slices"
"strings"

"github.com/bufbuild/buf/private/pkg/app"
"github.com/bufbuild/buf/private/pkg/execext"
"github.com/bufbuild/buf/private/pkg/ioext"
"github.com/bufbuild/buf/private/pkg/protoencoding"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/slogext"
"github.com/bufbuild/buf/private/pkg/storage"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
Expand Down Expand Up @@ -121,7 +121,7 @@ func (h *protocProxyHandler) Handle(
defer func() {
retErr = errors.Join(retErr, tmpDir.Close())
}()
args := slicesext.Concat(h.protocExtraArgs, []string{
args := slices.Concat(h.protocExtraArgs, []string{
fmt.Sprintf("--descriptor_set_in=%s", descriptorFilePath),
fmt.Sprintf("--%s_out=%s", h.pluginName, tmpDir.Path()),
})
Expand Down Expand Up @@ -194,7 +194,7 @@ func (h *protocProxyHandler) getProtocVersion(
if err := execext.Run(
ctx,
h.protocPath,
execext.WithArgs(slicesext.Concat(h.protocExtraArgs, []string{"--version"})...),
execext.WithArgs(slices.Concat(h.protocExtraArgs, []string{"--version"})...),
execext.WithEnv(pluginEnv.Environ),
execext.WithStdout(stdoutBuffer),
); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions private/buf/bufworkspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
package bufworkspace

import (
"slices"

"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/slicesext"
)

// Workspace is a buf workspace.
Expand Down Expand Up @@ -149,15 +150,15 @@ func (w *workspace) GetBreakingConfigForOpaqueID(opaqueID string) bufconfig.Brea
}

func (w *workspace) PluginConfigs() []bufconfig.PluginConfig {
return slicesext.Copy(w.pluginConfigs)
return slices.Clone(w.pluginConfigs)
}

func (w *workspace) RemotePluginKeys() []bufplugin.PluginKey {
return slicesext.Copy(w.remotePluginKeys)
return slices.Clone(w.remotePluginKeys)
}

func (w *workspace) ConfiguredDepModuleRefs() []bufparse.Ref {
return slicesext.Copy(w.configuredDepModuleRefs)
return slices.Clone(w.configuredDepModuleRefs)
}

func (w *workspace) IsV2() bool {
Expand Down
7 changes: 4 additions & 3 deletions private/buf/cmd/buf/buf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -1259,7 +1260,7 @@ func TestCheckLsBreakingRulesFromConfig(t *testing.T) {
}`,
append(
slicesext.Filter(builtinBreakingRulesV2, func(breakingRule *outputCheckRule) bool {
return slicesext.ElementsContained(breakingRule.Categories, []string{"WIRE"})
return slices.Contains(breakingRule.Categories, "WIRE")
}),
&outputCheckRule{ID: "ENUM_SUFFIXES_NO_CHANGE", Categories: []string{"ATTRIBUTES_SUFFIXES"}, Default: false, Purpose: "Ensure that enums with configured suffixes are not deleted and do not have new enum values or delete enum values.", Plugin: "buf-plugin-suffix"},
&outputCheckRule{ID: "MESSAGE_SUFFIXES_NO_CHANGE", Categories: []string{"ATTRIBUTES_SUFFIXES"}, Default: false, Purpose: "Ensure that messages with configured suffixes are not deleted and do not have new fields or delete fields.", Plugin: "buf-plugin-suffix"},
Expand Down Expand Up @@ -1295,7 +1296,7 @@ func TestCheckLsBreakingRulesFromConfig(t *testing.T) {
}`,
append(
slicesext.Filter(builtinBreakingRulesV2, func(breakingRule *outputCheckRule) bool {
return slicesext.ElementsContained(breakingRule.Categories, []string{"PACKAGE"})
return slices.Contains(breakingRule.Categories, "PACKAGE")
}),
&outputCheckRule{ID: "FIELD_WIRE_COMPATIBLE_TYPE", Categories: []string{"WIRE"}, Default: false, Purpose: "Checks that fields have wire-compatible types in a given message."},
&outputCheckRule{ID: "ENUM_SUFFIXES_NO_CHANGE", Categories: []string{"ATTRIBUTES_SUFFIXES"}, Default: false, Purpose: "Ensure that enums with configured suffixes are not deleted and do not have new enum values or delete enum values.", Plugin: "buf-plugin-suffix"},
Expand All @@ -1314,7 +1315,7 @@ func TestCheckLsBreakingRulesFromConfig(t *testing.T) {
}`,
append(
slicesext.Filter(builtinBreakingRulesV2, func(breakingRule *outputCheckRule) bool {
return slicesext.ElementsContained(breakingRule.Categories, []string{"PACKAGE"}) || breakingRule.ID == "FIELD_WIRE_COMPATIBLE_TYPE"
return slices.Contains(breakingRule.Categories, "PACKAGE") || breakingRule.ID == "FIELD_WIRE_COMPATIBLE_TYPE"
}),
&outputCheckRule{ID: "SERVICE_SUFFIXES_NO_CHANGE", Categories: []string{"OPERATION_SUFFIXES"}, Default: true, Purpose: "Ensure that services with configured suffixes are not deleted and do not have new RPCs or delete RPCs.", Plugin: "buf-plugin-suffix"},
&outputCheckRule{ID: "ENUM_SUFFIXES_NO_CHANGE", Categories: []string{"ATTRIBUTES_SUFFIXES"}, Default: false, Purpose: "Ensure that enums with configured suffixes are not deleted and do not have new enum values or delete enum values.", Plugin: "buf-plugin-suffix"},
Expand Down
16 changes: 3 additions & 13 deletions private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"buf.build/go/bufplugin/check"
"buf.build/go/bufplugin/descriptor"
"buf.build/go/bufplugin/option"
"github.com/bufbuild/buf/private/pkg/slicesext"
"google.golang.org/protobuf/reflect/protoreflect"
)

Expand Down Expand Up @@ -202,10 +201,7 @@ func handleBreakingServiceSuffixesNoChange(
if currentServiceDescriptor, ok := currentNoChangeServiceNameToServiceDescriptor[previousServiceName]; ok {
previousMethodNames := getAllMethodNamesSortedForService(previousServiceDescriptor)
currentMethodNames := getAllMethodNamesSortedForService(currentServiceDescriptor)
if !slicesext.ElementsEqual(
previousMethodNames,
currentMethodNames,
) {
if !slices.Equal(previousMethodNames, currentMethodNames) {
responseWriter.AddAnnotation(
check.WithDescriptor(currentServiceDescriptor),
check.WithAgainstDescriptor(previousServiceDescriptor),
Expand Down Expand Up @@ -281,10 +277,7 @@ func handleBreakingMessageSuffixesNoChange(
if currentMessageDescriptor, ok := currentNoChangeMessageNameToMessageDescriptor[previousMessageName]; ok {
previousFieldNames := getFieldNamesSortedForMessage(previousMessageDescriptor)
currentFieldNames := getFieldNamesSortedForMessage(currentMessageDescriptor)
if !slicesext.ElementsEqual(
previousFieldNames,
currentFieldNames,
) {
if !slices.Equal(previousFieldNames, currentFieldNames) {
responseWriter.AddAnnotation(
check.WithDescriptor(currentMessageDescriptor),
check.WithAgainstDescriptor(previousMessageDescriptor),
Expand Down Expand Up @@ -374,10 +367,7 @@ func handleBreakingEnumSuffixesNoChange(
if currentEnumDescriptor, ok := currentNoChangeEnumNameToEnumDescriptor[previousEnumName]; ok {
previousEnumValueNames := getEnumValueNamesSortedForEnum(previousEnumDescriptor)
currentEnumValueNames := getEnumValueNamesSortedForEnum(currentEnumDescriptor)
if !slicesext.ElementsEqual(
previousEnumValueNames,
currentEnumValueNames,
) {
if !slices.Equal(previousEnumValueNames, currentEnumValueNames) {
responseWriter.AddAnnotation(
check.WithDescriptor(currentEnumDescriptor),
check.WithAgainstDescriptor(previousEnumDescriptor),
Expand Down
6 changes: 3 additions & 3 deletions private/bufpkg/bufconfig/buf_lock_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"io"
"slices"
"sort"
"strings"
"time"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/pkg/encoding"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/storage"
"github.com/bufbuild/buf/private/pkg/syserror"
"github.com/bufbuild/buf/private/pkg/uuidutil"
Expand Down Expand Up @@ -227,14 +227,14 @@ func newBufLockFile(
return nil, syserror.Newf("unknown FileVersion: %v", fileVersion)
}
// To make sure we aren't editing input.
depModuleKeys = slicesext.Copy(depModuleKeys)
depModuleKeys = slices.Clone(depModuleKeys)
sort.Slice(
depModuleKeys,
func(i int, j int) bool {
return depModuleKeys[i].FullName().String() < depModuleKeys[j].FullName().String()
},
)
remotePluginKeys = slicesext.Copy(remotePluginKeys)
remotePluginKeys = slices.Clone(remotePluginKeys)
sort.Slice(
remotePluginKeys,
func(i int, j int) bool {
Expand Down
3 changes: 2 additions & 1 deletion private/bufpkg/bufconfig/buf_work_yaml_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"io"
"slices"

"github.com/bufbuild/buf/private/pkg/encoding"
"github.com/bufbuild/buf/private/pkg/normalpath"
Expand Down Expand Up @@ -163,7 +164,7 @@ func (w *bufWorkYAMLFile) ObjectData() ObjectData {
}

func (w *bufWorkYAMLFile) DirPaths() []string {
return slicesext.Copy(w.dirPaths)
return slices.Clone(w.dirPaths)
}

func (*bufWorkYAMLFile) isBufWorkYAMLFile() {}
Expand Down
5 changes: 3 additions & 2 deletions private/bufpkg/bufconfig/buf_yaml_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"sort"

"github.com/bufbuild/buf/private/bufpkg/bufparse"
Expand Down Expand Up @@ -337,7 +338,7 @@ func (c *bufYAMLFile) ObjectData() ObjectData {
}

func (c *bufYAMLFile) ModuleConfigs() []ModuleConfig {
return slicesext.Copy(c.moduleConfigs)
return slices.Clone(c.moduleConfigs)
}

func (c *bufYAMLFile) TopLevelLintConfig() LintConfig {
Expand All @@ -353,7 +354,7 @@ func (c *bufYAMLFile) PluginConfigs() []PluginConfig {
}

func (c *bufYAMLFile) ConfiguredDepModuleRefs() []bufparse.Ref {
return slicesext.Copy(c.configuredDepModuleRefs)
return slices.Clone(c.configuredDepModuleRefs)
}

func (c *bufYAMLFile) IncludeDocsLink() bool {
Expand Down
8 changes: 5 additions & 3 deletions private/bufpkg/bufconfig/check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package bufconfig

import (
"slices"

"github.com/bufbuild/buf/private/pkg/slicesext"
)

Expand Down Expand Up @@ -216,15 +218,15 @@ func (c *checkConfig) FileVersion() FileVersion {
}

func (c *checkConfig) UseIDsAndCategories() []string {
return slicesext.Copy(c.use)
return slices.Clone(c.use)
}

func (c *checkConfig) ExceptIDsAndCategories() []string {
return slicesext.Copy(c.except)
return slices.Clone(c.except)
}

func (c *checkConfig) IgnorePaths() []string {
return slicesext.Copy(c.ignore)
return slices.Clone(c.ignore)
}

func (c *checkConfig) IgnoreIDOrCategoryToPaths() map[string][]string {
Expand Down
4 changes: 2 additions & 2 deletions private/bufpkg/bufconfig/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

package bufconfig

import "github.com/bufbuild/buf/private/pkg/slicesext"
import "slices"

func copyStringToStringSliceMap(m map[string][]string) map[string][]string {
c := make(map[string][]string)
for k, v := range m {
c[k] = slicesext.Copy(v)
c[k] = slices.Clone(v)
}
return c
}
2 changes: 1 addition & 1 deletion private/bufpkg/bufimage/bufimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ func appendWellKnownTypeImageFileInfos(
if !slices.Equal(datawkt.AllFilePaths, wktPaths) {
return nil, syserror.Newf("wktBucket paths %s are not equal to datawkt.AllFilePaths %s", strings.Join(wktPaths, ","), strings.Join(datawkt.AllFilePaths, ","))
}
resultImageFileInfos := slicesext.Copy(imageFileInfos)
resultImageFileInfos := slices.Clone(imageFileInfos)
for _, wktObjectInfo := range wktObjectInfos {
if _, ok := pathToImageFileInfo[wktObjectInfo.Path()]; !ok {
fileImports, ok := datawkt.FileImports(wktObjectInfo.Path())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package internal

import (
"fmt"
"slices"

"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/pkg/slicesext"
"google.golang.org/protobuf/types/descriptorpb"
)

Expand Down Expand Up @@ -98,7 +98,7 @@ func removeLocationsFromSourceCodeInfo(
return fmt.Errorf("path %v must have a preceding parent path", location.Path)
}
if isPathForFileOption(location.Path) {
if !slicesext.ElementsEqual(sourceCodeInfo.Location[i-1].Path, fileOptionPath) {
if !slices.Equal(sourceCodeInfo.Location[i-1].Path, fileOptionPath) {
return fmt.Errorf("file option path %v must have a preceding parent path equal to %v", location.Path, fileOptionPath)
}
// Add the target path and its parent.
Expand Down
5 changes: 3 additions & 2 deletions private/bufpkg/bufimage/image_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package bufimage

import (
"slices"

"github.com/bufbuild/buf/private/bufpkg/bufparse"
"github.com/bufbuild/buf/private/pkg/protodescriptor"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/google/uuid"
"google.golang.org/protobuf/types/descriptorpb"
)
Expand Down Expand Up @@ -112,7 +113,7 @@ func (f *imageFile) CommitID() uuid.UUID {
}

func (f *imageFile) Imports() ([]string, error) {
return slicesext.Copy(f.fileDescriptorProto.GetDependency()), nil
return slices.Clone(f.fileDescriptorProto.GetDependency()), nil
}

func (f *imageFile) IsImport() bool {
Expand Down
3 changes: 2 additions & 1 deletion private/bufpkg/bufmodule/module_read_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"errors"
"io/fs"
"slices"
"sort"
"strings"

Expand Down Expand Up @@ -681,7 +682,7 @@ func (t *targetedModuleReadBucket) WalkFileInfos(
func(fileInfo FileInfo) error {
return fn(fileInfo)
},
slicesext.Concat(
slices.Concat(
options,
[]WalkFileInfosOption{WalkFileInfosWithOnlyTargetFiles()},
)...,
Expand Down
Loading

0 comments on commit 72d85fb

Please sign in to comment.