From 19532d04bfe4bfb2e4a2de239ac13f31b77080fc Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Sun, 22 Sep 2019 01:34:13 +0200 Subject: [PATCH] cmd/compile: add debugging mode for poset 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall Reviewed-by: David Chase --- src/cmd/compile/internal/ssa/compile.go | 2 ++ src/cmd/compile/internal/ssa/poset.go | 34 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go index 1a0a46c154..8551c0a54b 100644 --- a/src/cmd/compile/internal/ssa/compile.go +++ b/src/cmd/compile/internal/ssa/compile.go @@ -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 "" } diff --git a/src/cmd/compile/internal/ssa/poset.go b/src/cmd/compile/internal/ssa/poset.go index e74cabb337..cf5b915b94 100644 --- a/src/cmd/compile/internal/ssa/poset.go +++ b/src/cmd/compile/internal/ssa/poset.go @@ -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 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") + } } -- 2.50.0