Commit 0a511649 authored by Giovanni Bajo's avatar Giovanni Bajo

cmd/compile: in poset, simplify usage of CheckIntegrity

Instead of returning an error, just panic: the function is
used only for debugging purposes anyway.

Change-Id: Ie81b2309daaf1efb9470992391534bce2141b3c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/196779Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent 490646e4
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package ssa package ssa
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
) )
...@@ -625,13 +624,12 @@ func (po *poset) setnoneq(id1, id2 ID) { ...@@ -625,13 +624,12 @@ func (po *poset) setnoneq(id1, id2 ID) {
// CheckIntegrity verifies internal integrity of a poset. It is intended // CheckIntegrity verifies internal integrity of a poset. It is intended
// for debugging purposes. // for debugging purposes.
func (po *poset) CheckIntegrity() (err error) { func (po *poset) CheckIntegrity() {
// Record which index is a constant // Record which index is a constant
constants := newBitset(int(po.lastidx + 1)) constants := newBitset(int(po.lastidx + 1))
for _, c := range po.constants { for _, c := range po.constants {
if idx, ok := po.values[c.ID]; !ok { if idx, ok := po.values[c.ID]; !ok {
err = errors.New("node missing for constant") panic("node missing for constant")
return err
} else { } else {
constants.Set(idx) constants.Set(idx)
} }
...@@ -642,34 +640,27 @@ func (po *poset) CheckIntegrity() (err error) { ...@@ -642,34 +640,27 @@ func (po *poset) CheckIntegrity() (err error) {
seen := newBitset(int(po.lastidx + 1)) seen := newBitset(int(po.lastidx + 1))
for ridx, r := range po.roots { for ridx, r := range po.roots {
if r == 0 { if r == 0 {
err = errors.New("empty root") panic("empty root")
return
} }
po.dfs(r, false, func(i uint32) bool { po.dfs(r, false, func(i uint32) bool {
if seen.Test(i) { if seen.Test(i) {
err = errors.New("duplicate node") panic("duplicate node")
return true
} }
seen.Set(i) seen.Set(i)
if constants.Test(i) { if constants.Test(i) {
if ridx != 0 { if ridx != 0 {
err = errors.New("constants not in the first DAG") panic("constants not in the first DAG")
return true
} }
} }
return false return false
}) })
if err != nil {
return
}
} }
// Verify that values contain the minimum set // Verify that values contain the minimum set
for id, idx := range po.values { for id, idx := range po.values {
if !seen.Test(idx) { if !seen.Test(idx) {
err = fmt.Errorf("spurious value [%d]=%d", id, idx) panic(fmt.Errorf("spurious value [%d]=%d", id, idx))
return
} }
} }
...@@ -677,17 +668,13 @@ func (po *poset) CheckIntegrity() (err error) { ...@@ -677,17 +668,13 @@ func (po *poset) CheckIntegrity() (err error) {
for i, n := range po.nodes { for i, n := range po.nodes {
if n.l|n.r != 0 { if n.l|n.r != 0 {
if !seen.Test(uint32(i)) { if !seen.Test(uint32(i)) {
err = fmt.Errorf("children of unknown node %d->%v", i, n) panic(fmt.Errorf("children of unknown node %d->%v", i, n))
return
} }
if n.l.Target() == uint32(i) || n.r.Target() == uint32(i) { if n.l.Target() == uint32(i) || n.r.Target() == uint32(i) {
err = fmt.Errorf("self-loop on node %d", i) panic(fmt.Errorf("self-loop on node %d", i))
return
} }
} }
} }
return
} }
// CheckEmpty checks that a poset is completely empty. // CheckEmpty checks that a poset is completely empty.
......
...@@ -146,9 +146,7 @@ func testPosetOps(t *testing.T, unsigned bool, ops []posetTestOp) { ...@@ -146,9 +146,7 @@ func testPosetOps(t *testing.T, unsigned bool, ops []posetTestOp) {
po.DotDump(fmt.Sprintf("op%d.dot", idx), fmt.Sprintf("Last op: %v", op)) po.DotDump(fmt.Sprintf("op%d.dot", idx), fmt.Sprintf("Last op: %v", op))
} }
if err := po.CheckIntegrity(); err != nil { po.CheckIntegrity()
t.Fatalf("op%d%v: integrity error: %v", idx, op, err)
}
} }
// Check that the poset is completely empty // Check that the poset is completely empty
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment