MCPcopy
hub / github.com/golang/tools / cacheKey

Method cacheKey

gopls/internal/cache/analysis.go:620–648  ·  view source on GitHub ↗

cacheKey returns a cache key that is a cryptographic digest of the all the values that might affect type checking and analysis: the analyzer names, package metadata, names and contents of compiled Go files, and vdeps (successor) information (export data and facts).

()

Source from the content-addressed store, hash-verified

618// compiled Go files, and vdeps (successor) information
619// (export data and facts).
620func (an *analysisNode) cacheKey() file.Hash {
621 hasher := sha256.New()
622
623 // In principle, a key must be the hash of an
624 // unambiguous encoding of all the relevant data.
625 // If it's ambiguous, we risk collisions.
626
627 // analyzers
628 fmt.Fprintf(hasher, "analyzers: %d\n", len(an.analyzers))
629 for _, a := range an.analyzers {
630 fmt.Fprintln(hasher, a.Name)
631 }
632
633 // type checked package
634 fmt.Fprintf(hasher, "package: %s\n", an.ph.key)
635
636 // metadata errors: used for 'compiles' field
637 fmt.Fprintf(hasher, "errors: %d", len(an.ph.mp.Errors))
638
639 // vdeps, in PackageID order
640 for _, vdep := range moremaps.Sorted(an.succs) {
641 hash := vdep.summaryHash()
642 hasher.Write(hash[:])
643 }
644
645 var hash file.Hash
646 hasher.Sum(hash[:0])
647 return hash
648}
649
650// run implements the cache-miss case.
651// This function does not access the snapshot.

Callers 1

AnalyzeMethod · 0.80

Calls 4

SortedFunction · 0.92
NewMethod · 0.80
summaryHashMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected