From 97a268624c9f2830133d2bdfae677f5d99ec82cb Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 24 Jan 2020 13:52:41 -0800 Subject: [PATCH] cmd/compile: add -d=ssa/check/seed=SEED This change adds the option to run the ssa checker with a random seed. The current system uses a completely fixed seed, which is good for reproducibility but bad for exploring the state space. Preserve what we have, but also provide a way for the caller to provide a seed. The caller can report the seed alongside any failures. Change-Id: I2676a8112d8260e6cac86d95d2e8db4d3221aeeb Reviewed-on: https://go-review.googlesource.com/c/go/+/216418 Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/compile.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go index 8551c0a54b..448b1cf814 100644 --- a/src/cmd/compile/internal/ssa/compile.go +++ b/src/cmd/compile/internal/ssa/compile.go @@ -35,7 +35,8 @@ func Compile(f *Func) { var rnd *rand.Rand if checkEnabled { - rnd = rand.New(rand.NewSource(int64(crc32.ChecksumIEEE(([]byte)(f.Name))))) + seed := int64(crc32.ChecksumIEEE(([]byte)(f.Name))) ^ int64(checkRandSeed) + rnd = rand.New(rand.NewSource(seed)) } // hook to print function & phase if panic happens @@ -199,7 +200,10 @@ func (p *pass) addDump(s string) { } // Run consistency checker between each phase -var checkEnabled = false +var ( + checkEnabled = false + checkRandSeed = 0 +) // Debug output var IntrinsicsDebug int @@ -253,7 +257,7 @@ where: ` + phasenames + ` - is one of: - on, off, debug, mem, time, test, stats, dump + on, off, debug, mem, time, test, stats, dump, seed - defaults to 1 @@ -271,6 +275,10 @@ Examples: -d=ssa/check/on enables checking after each phase + -d=ssa/check/seed=1234 +enables checking after each phase, using 1234 to seed the PRNG +used for value order randomization + -d=ssa/all/time enables time reporting for all phases @@ -294,6 +302,12 @@ commas. For example: debugPoset = checkEnabled return "" } + if phase == "check" && flag == "seed" { + checkEnabled = true + checkRandSeed = val + debugPoset = checkEnabled + return "" + } alltime := false allmem := false -- 2.50.0