]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add -d=ssa/check/seed=SEED
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 24 Jan 2020 21:52:41 +0000 (13:52 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 2 Mar 2020 22:11:29 +0000 (22:11 +0000)
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 <khr@golang.org>
src/cmd/compile/internal/ssa/compile.go

index 8551c0a54b9b7cc68b19f0931df008a262d503a8..448b1cf8147f7c33758697131b2d19a1558e1c27 100644 (file)
@@ -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 + `
 
 - <flag> is one of:
-    on, off, debug, mem, time, test, stats, dump
+    on, off, debug, mem, time, test, stats, dump, seed
 
 - <value> 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