Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 0a9f6d9

Browse files
committed
Encompass both internal and external in ReachMaps
Rather than splitting the data into two separate map return values, this makes ReachMaps' value a struct containing both the internal package import and external import path list information.
1 parent 81d18c6 commit 0a9f6d9

File tree

6 files changed

+147
-227
lines changed

6 files changed

+147
-227
lines changed

analysis.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,16 @@ type PackageOrErr struct {
356356
Err error
357357
}
358358

359-
// ReachMap maps a set of import paths (keys) to the set of external packages
360-
// transitively reachable from the packages at those import paths.
359+
// ReachMap maps a set of import paths (keys) to the sets of transitively
360+
// reachable tree-internal packages, and all the tree-external reachable through
361+
// those internal packages.
361362
//
362-
// See PackageTree.ExternalReach() for more information.
363-
type ReachMap map[string][]string
363+
// See PackageTree.ToReachMap() for more information.
364+
type ReachMap map[string]struct {
365+
Internal, External []string
366+
}
364367

365-
// ToReachMaps looks through a PackageTree and computes the list of external
368+
// ToReachMap looks through a PackageTree and computes the list of external
366369
// import statements (that is, import statements pointing to packages that are
367370
// not logical children of PackageTree.ImportRoot) that are transitively
368371
// imported by the internal packages in the tree.
@@ -434,7 +437,7 @@ type ReachMap map[string][]string
434437
//
435438
// When backprop is false, errors in internal packages are functionally
436439
// identical to ignoring that package.
437-
func (t PackageTree) ToReachMaps(main, tests bool, ignore map[string]bool) (ex ReachMap, in ReachMap) {
440+
func (t PackageTree) ToReachMap(main, tests bool, ignore map[string]bool) ReachMap {
438441
if ignore == nil {
439442
ignore = make(map[string]bool)
440443
}
@@ -508,7 +511,7 @@ func (t PackageTree) ToReachMaps(main, tests bool, ignore map[string]bool) (ex R
508511
//
509512
// The basedir string, with a trailing slash ensured, will be stripped from the
510513
// keys of the returned map.
511-
func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
514+
func wmToReach(workmap map[string]wm) ReachMap {
512515
// Uses depth-first exploration to compute reachability into external
513516
// packages, dropping any internal packages on "poisoned paths" - a path
514517
// containing a package with an error, or with a dep on an internal package
@@ -541,10 +544,6 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
541544
// stack of parent packages we've visited to get to pkg. The return value
542545
// indicates whether the level completed successfully (true) or if it was
543546
// poisoned (false).
544-
//
545-
// TODO(sdboyer) some deft improvements could probably be made by passing the list of
546-
// parent reachsets, rather than a list of parent package string names.
547-
// might be able to eliminate the use of exrsets map-of-maps entirely.
548547
dfe = func(pkg string, path []string) bool {
549548
// white is the zero value of uint8, which is what we want if the pkg
550549
// isn't in the colors map, so this works fine
@@ -691,12 +690,16 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
691690
dfe(pkg, path)
692691
}
693692

694-
// Flatten exrsets into the final external reachmap
695-
rm := make(map[string][]string)
693+
type ie struct {
694+
Internal, External []string
695+
}
696+
697+
// Flatten exrsets into reachmap
698+
rm := make(ReachMap)
696699
for pkg, rs := range exrsets {
697700
rlen := len(rs)
698701
if rlen == 0 {
699-
rm[pkg] = nil
702+
rm[pkg] = ie{}
700703
continue
701704
}
702705

@@ -706,15 +709,16 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
706709
}
707710

708711
sort.Strings(edeps)
709-
rm[pkg] = edeps
712+
713+
sets := rm[pkg]
714+
sets.External = edeps
715+
rm[pkg] = sets
710716
}
711717

712-
// Flatten inrsets into the final internal reachmap
713-
irm := make(map[string][]string)
718+
// Flatten inrsets into reachmap
714719
for pkg, rs := range inrsets {
715720
rlen := len(rs)
716721
if rlen == 0 {
717-
irm[pkg] = nil
718722
continue
719723
}
720724

@@ -724,10 +728,13 @@ func wmToReach(workmap map[string]wm) (ex ReachMap, in ReachMap) {
724728
}
725729

726730
sort.Strings(ideps)
727-
irm[pkg] = ideps
731+
732+
sets := rm[pkg]
733+
sets.Internal = ideps
734+
rm[pkg] = sets
728735
}
729736

730-
return rm, irm
737+
return rm
731738
}
732739

733740
// ListExternalImports computes a sorted, deduplicated list of all the external

0 commit comments

Comments
 (0)