Skip to content

Commit

Permalink
feat: bump to go 1.23
Browse files Browse the repository at this point in the history
Signed-off-by: Zxilly <[email protected]>
  • Loading branch information
Zxilly committed Jun 27, 2024
1 parent 7f37a67 commit 5922f27
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 44 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ jobs:
- name: Checkout Actions Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Run golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
with:
version: v1.59.1
args: '--out-format=colored-line-number,sarif:golangci-lint-results.sarif'
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10
with:
sarif_file: ./golangci-lint-results.sarif
wait-for-processing: true
# fixme: disable for now, wait for golangci-lint supports go 1.23
# - name: Run golangci-lint
# uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
# with:
# version: v1.59.1
# args: '--out-format=colored-line-number,sarif:golangci-lint-results.sarif'
# continue-on-error: true
#
# - name: Upload analysis results to GitHub
# uses: github/codeql-action/upload-sarif@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3.25.10
# with:
# sarif_file: ./golangci-lint-results.sarif
# wait-for-processing: true

typos:
name: Spell Check with Typos
Expand Down
8 changes: 2 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/Zxilly/go-size-analyzer

go 1.22

toolchain go1.22.4
go 1.23rc1

require (
github.com/ZxillyFork/gore v0.0.0-20240622181243-e08af164b21c
Expand All @@ -24,9 +22,8 @@ require (
github.com/nikolaydubina/treemap v1.2.5
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/samber/lo v1.39.0
github.com/samber/lo v1.41.0
github.com/stretchr/testify v1.9.0
go4.org/intern v0.0.0-20230525184215-6c62f75575cb
golang.org/x/arch v0.8.0
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/net v0.26.0
Expand All @@ -53,7 +50,6 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20231121144256-b99613f794b6 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
15 changes: 2 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ github.com/charmbracelet/lipgloss v0.11.0 h1:UoAcbQ6Qml8hDwSWs0Y1cB5TEQuZkDPH/Zq
github.com/charmbracelet/lipgloss v0.11.0/go.mod h1:1UdRTH9gYgpcdNN5oBtjbu/IzNKtzVtb7sqN1t9LNn8=
github.com/charmbracelet/x/ansi v0.1.2 h1:6+LR39uG8DE6zAmbu023YlqjJHkYXDF1z36ZwzO4xZY=
github.com/charmbracelet/x/ansi v0.1.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/exp/golden v0.0.0-20240525152034-77596eb8760e h1:i7saGBzkbTcMz8okIDrqBr5381f50EIZKA5R7U/v2Ns=
github.com/charmbracelet/x/exp/golden v0.0.0-20240525152034-77596eb8760e/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/golden v0.0.0-20240617190524-788ec55faed1 h1:MW7arc+KIDoURwm0KKr5tdPUZM+liJf54Oe7Ld+hNqw=
github.com/charmbracelet/x/exp/golden v0.0.0-20240617190524-788ec55faed1/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/golden v0.0.0-20240625134410-de32bb7b5d4e h1:RHVibg7mp++RILPdzcaeVhXWI46uH2qnwG747jazKWI=
github.com/charmbracelet/x/exp/golden v0.0.0-20240625134410-de32bb7b5d4e/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/teatest v0.0.0-20240606154654-7c42867b53c7 h1:S/o60nDjY4g1AKIifpYvHPV44I8qKazVTOqI86E2QJ8=
github.com/charmbracelet/x/exp/teatest v0.0.0-20240606154654-7c42867b53c7/go.mod h1:5SXVy5IiqnjEZF82fNe+h5NZv70UnQ8irVnG1gvXlDw=
github.com/charmbracelet/x/exp/teatest v0.0.0-20240625134410-de32bb7b5d4e h1:ai+YxFNZzfs8+195zZZMw95dRFCor965XGw8OT/A/7I=
github.com/charmbracelet/x/exp/teatest v0.0.0-20240625134410-de32bb7b5d4e/go.mod h1:YKm1t6wYRVj9+r8XSQoYJc0KdmeDYXbTwfmEsPMEi8w=
github.com/charmbracelet/x/input v0.1.2 h1:QJAZr33eOhDowkkEQ24rsJy4Llxlm+fRDf/cQrmqJa0=
Expand Down Expand Up @@ -94,19 +88,14 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/lo v1.41.0 h1:vZEqVQNmX/ykONfla8tiW6cdoLZxb3+LCZ63B8z/2eE=
github.com/samber/lo v1.41.0/go.mod h1:w7R6fO7h2lrnx/s0bWcZ55vXJI89p5UPM6+kyDL373E=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
go4.org/intern v0.0.0-20230525184215-6c62f75575cb h1:ae7kzL5Cfdmcecbh22ll7lYP3iuUdnfnhiPcSaDgH/8=
go4.org/intern v0.0.0-20230525184215-6c62f75575cb/go.mod h1:Ycrt6raEcnF5FTsLiLKkhBTO6DPX3RCUCUVnks3gFJU=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20231121144256-b99613f794b6 h1:lGdhQUN/cnWdSH3291CUuxSEqc+AsGTiDxPP3r2J0l4=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20231121144256-b99613f794b6/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
Expand Down
6 changes: 4 additions & 2 deletions internal/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package internal
import (
"cmp"
"errors"

"io"
"log/slog"
"maps"
"path/filepath"
"slices"

"github.com/ZxillyFork/gore"
"golang.org/x/exp/maps"

"github.com/Zxilly/go-size-analyzer/internal/entity"
"github.com/Zxilly/go-size-analyzer/internal/knowninfo"
"github.com/Zxilly/go-size-analyzer/internal/result"
"github.com/Zxilly/go-size-analyzer/internal/utils"
"github.com/Zxilly/go-size-analyzer/internal/wrapper"
)

Expand Down Expand Up @@ -106,7 +108,7 @@ func Analyze(name string, reader io.ReaderAt, size uint64, options Options) (*re
// for packages
k.CalculatePackageSize()

sections := maps.Values(k.Sects.Sections)
sections := utils.Collect(maps.Values(k.Sects.Sections))
slices.SortFunc(sections, func(a, b *entity.Section) int {
return cmp.Compare(a.Name, b.Name)
})
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package entity
import (
"debug/dwarf"
"fmt"
"maps"
"runtime/debug"

"github.com/ZxillyFork/gore"
"github.com/ZxillyFork/gosym"
"github.com/samber/lo"
"golang.org/x/exp/maps"

"github.com/Zxilly/go-size-analyzer/internal/utils"
)
Expand Down Expand Up @@ -130,7 +130,7 @@ func (p *Package) fileEnsureUnique() {
}
}

p.Files = maps.Values(fileSeen)
p.Files = utils.Collect(maps.Values(fileSeen))
p.filesCache = fileSeen

p.funcsCache = make(map[string]*Function)
Expand Down
5 changes: 3 additions & 2 deletions internal/printer/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import (
"fmt"
"io"
"log/slog"
"maps"
"path/filepath"
"slices"

"github.com/dustin/go-humanize"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/samber/lo"
"golang.org/x/exp/maps"

"github.com/Zxilly/go-size-analyzer/internal/entity"
"github.com/Zxilly/go-size-analyzer/internal/result"
"github.com/Zxilly/go-size-analyzer/internal/utils"
)

func percentString(f float64) string {
Expand Down Expand Up @@ -49,7 +50,7 @@ func Text(r *result.Result, options *CommonOption) error {

entries := make([]sizeEntry, 0)

pkgs := maps.Values(r.Packages)
pkgs := utils.Collect(maps.Values(r.Packages))
for _, p := range pkgs {
if options.HideMain && p.Type == entity.PackageTypeMain {
continue
Expand Down
5 changes: 2 additions & 3 deletions internal/utils/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package utils

import (
"cmp"
"maps"
"slices"

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

func SortedKeys[T cmp.Ordered, U any](m map[T]U) []T {
keys := maps.Keys(m)
keys := Collect(maps.Keys(m))
slices.Sort(keys)
return keys
}
4 changes: 2 additions & 2 deletions internal/utils/set.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils

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

type Set[T comparable] map[T]struct{}

Expand All @@ -22,5 +22,5 @@ func (s Set[T]) Contains(item T) bool {
}

func (s Set[T]) ToSlice() []T {
return maps.Keys(s)
return Collect(maps.Keys(s))
}
15 changes: 13 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package utils
import (
"debug/pe"
"fmt"
"iter"
"log/slog"
"strconv"
"strings"
"unique"

"go4.org/intern"
"golang.org/x/net/publicsuffix"
)

Expand All @@ -23,7 +24,7 @@ func GetImageBase(file *pe.File) uint64 {
}

func Deduplicate(s string) string {
return intern.GetByString(s).Get().(string) //nolint: revive // should be replaced with unique after 1.23
return unique.Make(s).Value()
}

// UglyGuess an ugly hack for a known issue about golang compiler
Expand Down Expand Up @@ -122,3 +123,13 @@ func Must(err error) {
panic(err)
}
}

func Collect[K comparable](seq iter.Seq[K]) []K {
m := make([]K, 0)

for k := range seq {
m = append(m, k)
}

return m
}
12 changes: 12 additions & 0 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"debug/gosym"
"fmt"
"maps"
"reflect"
"testing"
"unsafe"
Expand Down Expand Up @@ -104,3 +105,14 @@ func TestMust(t *testing.T) {
assert.Panics(t, func() { Must(fmt.Errorf("test error")) })
})
}

func TestCollect(t *testing.T) {
args := map[string]struct{}{
"foo": {},
"bar": {},
"baz": {},
}
seq := maps.Keys(args)

assert.Equal(t, []string{"foo", "bar", "baz"}, Collect(seq))
}

0 comments on commit 5922f27

Please sign in to comment.