]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add debugging mode for poset
authorGiovanni Bajo <rasky@develer.com>
Sat, 21 Sep 2019 23:34:13 +0000 (01:34 +0200)
committerGiovanni Bajo <rasky@develer.com>
Mon, 14 Oct 2019 21:00:36 +0000 (21:00 +0000)
Add an internal mode to simplify debugging of posets
by checking the integrity after every mutation. Turn
it on within SSA checked builds.

Change-Id: Idaa8277f58e5bce3753702e212cea4d698de30ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/196780
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/compile.go
src/cmd/compile/internal/ssa/poset.go

index 1a0a46c154ca6e080128e2e373e11af838f1b2d6..8551c0a54b9b7cc68b19f0931df008a262d503a8 100644 (file)
@@ -286,10 +286,12 @@ commas. For example:
 
        if phase == "check" && flag == "on" {
                checkEnabled = val != 0
+               debugPoset = checkEnabled // also turn on advanced self-checking in prove's datastructure
                return ""
        }
        if phase == "check" && flag == "off" {
                checkEnabled = val == 0
+               debugPoset = checkEnabled
                return ""
        }
 
index e74cabb33788181038b1b38e5ea8f8bd1d53501f..cf5b915b9460561f8b136e8c47ced9db5c4a2a87 100644 (file)
@@ -9,6 +9,9 @@ import (
        "os"
 )
 
+// If true, check poset integrity after every mutation
+var debugPoset = false
+
 const uintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64
 
 // bitset is a bit array for dense indexes.
@@ -785,6 +788,9 @@ func (po *poset) DotDump(fn string, title string) error {
 // to tell.
 // Complexity is O(n).
 func (po *poset) Ordered(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call Ordered with n1==n2")
        }
@@ -803,6 +809,9 @@ func (po *poset) Ordered(n1, n2 *Value) bool {
 // to tell.
 // Complexity is O(n).
 func (po *poset) OrderedOrEqual(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call Ordered with n1==n2")
        }
@@ -821,6 +830,9 @@ func (po *poset) OrderedOrEqual(n1, n2 *Value) bool {
 // to tell.
 // Complexity is O(1).
 func (po *poset) Equal(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call Equal with n1==n2")
        }
@@ -836,6 +848,9 @@ func (po *poset) Equal(n1, n2 *Value) bool {
 // Complexity is O(n) (because it internally calls Ordered to see if we
 // can infer n1!=n2 from n1<n2 or n2<n1).
 func (po *poset) NonEqual(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call Equal with n1==n2")
        }
@@ -982,6 +997,9 @@ func (po *poset) setOrder(n1, n2 *Value, strict bool) bool {
 // SetOrder records that n1<n2. Returns false if this is a contradiction
 // Complexity is O(1) if n2 was never seen before, or O(n) otherwise.
 func (po *poset) SetOrder(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call SetOrder with n1==n2")
        }
@@ -991,6 +1009,9 @@ func (po *poset) SetOrder(n1, n2 *Value) bool {
 // SetOrderOrEqual records that n1<=n2. Returns false if this is a contradiction
 // Complexity is O(1) if n2 was never seen before, or O(n) otherwise.
 func (po *poset) SetOrderOrEqual(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call SetOrder with n1==n2")
        }
@@ -1001,6 +1022,9 @@ func (po *poset) SetOrderOrEqual(n1, n2 *Value) bool {
 // (that is, if it is already recorded that n1<n2 or n2<n1).
 // Complexity is O(1) if n2 was never seen before, or O(n) otherwise.
 func (po *poset) SetEqual(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call Add with n1==n2")
        }
@@ -1060,6 +1084,9 @@ func (po *poset) SetEqual(n1, n2 *Value) bool {
 // (that is, if it is already recorded that n1==n2).
 // Complexity is O(n).
 func (po *poset) SetNonEqual(n1, n2 *Value) bool {
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
        if n1.ID == n2.ID {
                panic("should not call Equal with n1==n2")
        }
@@ -1108,6 +1135,9 @@ func (po *poset) Undo() {
        if len(po.undo) == 0 {
                panic("empty undo stack")
        }
+       if debugPoset {
+               defer po.CheckIntegrity()
+       }
 
        for len(po.undo) > 0 {
                pass := po.undo[len(po.undo)-1]
@@ -1187,4 +1217,8 @@ func (po *poset) Undo() {
                        panic(pass.typ)
                }
        }
+
+       if debugPoset && po.CheckEmpty() != nil {
+               panic("poset not empty at the end of undo")
+       }
 }