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).
()
| 618 | // compiled Go files, and vdeps (successor) information |
| 619 | // (export data and facts). |
| 620 | func (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. |
no test coverage detected