From 7cbdb4fb14d13784d45ad033d5a44b68b269e747 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Thu, 30 Jul 2020 11:02:44 -0400 Subject: [PATCH] Limit typecheck parallelism by default --- test/typecheck/main.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/test/typecheck/main.go b/test/typecheck/main.go index c4f9f8d4c26..29d74de48dd 100644 --- a/test/typecheck/main.go +++ b/test/typecheck/main.go @@ -38,7 +38,8 @@ var ( platforms = flag.String("platform", "", "comma-separated list of platforms to typecheck") timings = flag.Bool("time", false, "output times taken for each phase") defuses = flag.Bool("defuse", false, "output defs/uses") - serial = flag.Bool("serial", false, "don't type check platforms in parallel") + serial = flag.Bool("serial", false, "don't type check platforms in parallel (equivalent to --parallel=1)") + parallel = flag.Int("parallel", 4, "limits how many platforms can be checked in parallel. 0 means no limit.") skipTest = flag.Bool("skip-test", false, "don't type check test code") tags = flag.String("tags", "", "comma-separated list of build tags to apply in addition to go's defaults") ignoreDirs = flag.String("ignore-dirs", "", "comma-separated list of directories to ignore in addition to the default hardcoded list including staging, vendor, and hidden dirs") @@ -273,9 +274,24 @@ func main() { var wg sync.WaitGroup var failMu sync.Mutex failed := false + + if *serial { + *parallel = 1 + } else if *parallel == 0 { + *parallel = len(plats) + } + throttle := make(chan int, *parallel) + for _, plat := range plats { wg.Add(1) - fn := func(plat string) { + go func(plat string) { + // block until there's room for this task + throttle <- 1 + defer func() { + // indicate this task is done + <-throttle + }() + f := false serialFprintf(os.Stdout, "type-checking %s\n", plat) errors, err := c.verify(plat) @@ -295,12 +311,7 @@ func main() { failed = failed || f failMu.Unlock() wg.Done() - } - if *serial { - fn(plat) - } else { - go fn(plat) - } + }(plat) } wg.Wait() if failed {