diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f661d19778..cb3d80afa1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/go.mod b/go.mod index 8cf1c27f4a..bb66618689 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index dd3afdf796..6d34fc9651 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/analyze.go b/internal/analyze.go index 89a3b99bdb..b7e468ab6e 100644 --- a/internal/analyze.go +++ b/internal/analyze.go @@ -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" ) @@ -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) }) diff --git a/internal/entity/package.go b/internal/entity/package.go index 59a1ac0537..6ceb394568 100644 --- a/internal/entity/package.go +++ b/internal/entity/package.go @@ -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" ) @@ -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) diff --git a/internal/printer/console.go b/internal/printer/console.go index 715390b99f..b64138728f 100644 --- a/internal/printer/console.go +++ b/internal/printer/console.go @@ -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 { @@ -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 diff --git a/internal/utils/map.go b/internal/utils/map.go index 460897597f..a41c2bd7f7 100644 --- a/internal/utils/map.go +++ b/internal/utils/map.go @@ -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 } diff --git a/internal/utils/set.go b/internal/utils/set.go index 3c836f0f8e..1b4db0d12a 100644 --- a/internal/utils/set.go +++ b/internal/utils/set.go @@ -1,6 +1,6 @@ package utils -import "golang.org/x/exp/maps" +import "maps" type Set[T comparable] map[T]struct{} @@ -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)) } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 272623cb66..2cf6a2e311 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -3,11 +3,12 @@ package utils import ( "debug/pe" "fmt" + "iter" "log/slog" "strconv" "strings" + "unique" - "go4.org/intern" "golang.org/x/net/publicsuffix" ) @@ -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 @@ -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 +} diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 4f35ac7e7f..5aadce2c7f 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -3,6 +3,7 @@ package utils import ( "debug/gosym" "fmt" + "maps" "reflect" "testing" "unsafe" @@ -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)) +}