diff --git a/internal/lsp/cache/analysis.go b/internal/lsp/cache/analysis.go index 847ac2db8d0..db2ca2a8b09 100644 --- a/internal/lsp/cache/analysis.go +++ b/internal/lsp/cache/analysis.go @@ -10,7 +10,6 @@ import ( "go/ast" "go/types" "reflect" - "sort" "sync" "golang.org/x/sync/errgroup" @@ -122,13 +121,8 @@ func (s *snapshot) actionHandle(ctx context.Context, id PackageID, a *analysis.A // An analysis that consumes/produces facts // must run on the package's dependencies too. if len(a.FactTypes) > 0 { - importIDs := make([]string, 0, len(ph.m.Deps)) for _, importID := range ph.m.Deps { - importIDs = append(importIDs, string(importID)) - } - sort.Strings(importIDs) // for determinism - for _, importID := range importIDs { - depActionHandle, err := s.actionHandle(ctx, PackageID(importID), a) + depActionHandle, err := s.actionHandle(ctx, importID, a) if err != nil { return nil, err } diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index aeb45635c3b..5ded278f514 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -102,13 +102,6 @@ func (s *snapshot) buildPackageHandle(ctx context.Context, id PackageID, mode so return nil, fmt.Errorf("no metadata for %s", id) } - // For key stability, sort depList. - // TODO(adonovan): make m.Deps have a well defined order. - depList := append([]PackageID{}, m.Deps...) - sort.Slice(depList, func(i, j int) bool { - return depList[i] < depList[j] - }) - // Begin computing the key by getting the depKeys for all dependencies. // This requires reading the transitive closure of dependencies' source files. // @@ -122,8 +115,8 @@ func (s *snapshot) buildPackageHandle(ctx context.Context, id PackageID, mode so // for each package is computed by at most one thread, then do // the recursive key building of dependencies in parallel. deps := make(map[PackagePath]*packageHandle) - depKeys := make([]packageHandleKey, len(depList)) - for i, depID := range depList { + depKeys := make([]packageHandleKey, len(m.Deps)) + for i, depID := range m.Deps { depHandle, err := s.buildPackageHandle(ctx, depID, s.workspaceParseMode(depID)) // Don't use invalid metadata for dependencies if the top-level // metadata is valid. We only load top-level packages, so if the diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index d613dc3337e..00d4ab2cbb3 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -539,6 +539,7 @@ func computeMetadataUpdates(ctx context.Context, g *metadataGraph, pkgPath Packa event.Error(ctx, "error in dependency", err) } } + sort.Slice(m.Deps, func(i, j int) bool { return m.Deps[i] < m.Deps[j] }) // for determinism return nil } diff --git a/internal/lsp/cache/metadata.go b/internal/lsp/cache/metadata.go index b4da7130c23..486035f9390 100644 --- a/internal/lsp/cache/metadata.go +++ b/internal/lsp/cache/metadata.go @@ -32,7 +32,7 @@ type Metadata struct { ForTest PackagePath TypesSizes types.Sizes Errors []packages.Error - Deps []PackageID + Deps []PackageID // direct dependencies, in string order MissingDeps map[PackagePath]struct{} Module *packages.Module depsErrors []*packagesinternal.PackageError