]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: in poset, simplify usage of CheckIntegrity
authorGiovanni Bajo <rasky@develer.com>
Sat, 21 Sep 2019 23:31:02 +0000 (01:31 +0200)
committerGiovanni Bajo <rasky@develer.com>
Thu, 26 Sep 2019 21:24:48 +0000 (21:24 +0000)
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/+/196779
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/poset.go
src/cmd/compile/internal/ssa/poset_test.go

index 5548c3b1c40a8c30375a1fc987cec553f018eb70..378ecc92637cb0de0c2805e61bb93331789126d2 100644 (file)
@@ -5,7 +5,6 @@
 package ssa
 
 import (
-       "errors"
        "fmt"
        "os"
 )
@@ -625,13 +624,12 @@ func (po *poset) setnoneq(id1, id2 ID) {
 
 // CheckIntegrity verifies internal integrity of a poset. It is intended
 // for debugging purposes.
-func (po *poset) CheckIntegrity() (err error) {
+func (po *poset) CheckIntegrity() {
        // Record which index is a constant
        constants := newBitset(int(po.lastidx + 1))
        for _, c := range po.constants {
                if idx, ok := po.values[c.ID]; !ok {
-                       err = errors.New("node missing for constant")
-                       return err
+                       panic("node missing for constant")
                } else {
                        constants.Set(idx)
                }
@@ -642,34 +640,27 @@ func (po *poset) CheckIntegrity() (err error) {
        seen := newBitset(int(po.lastidx + 1))
        for ridx, r := range po.roots {
                if r == 0 {
-                       err = errors.New("empty root")
-                       return
+                       panic("empty root")
                }
 
                po.dfs(r, false, func(i uint32) bool {
                        if seen.Test(i) {
-                               err = errors.New("duplicate node")
-                               return true
+                               panic("duplicate node")
                        }
                        seen.Set(i)
                        if constants.Test(i) {
                                if ridx != 0 {
-                                       err = errors.New("constants not in the first DAG")
-                                       return true
+                                       panic("constants not in the first DAG")
                                }
                        }
                        return false
                })
-               if err != nil {
-                       return
-               }
        }
 
        // Verify that values contain the minimum set
        for id, idx := range po.values {
                if !seen.Test(idx) {
-                       err = fmt.Errorf("spurious value [%d]=%d", id, idx)
-                       return
+                       panic(fmt.Errorf("spurious value [%d]=%d", id, idx))
                }
        }
 
@@ -677,17 +668,13 @@ func (po *poset) CheckIntegrity() (err error) {
        for i, n := range po.nodes {
                if n.l|n.r != 0 {
                        if !seen.Test(uint32(i)) {
-                               err = fmt.Errorf("children of unknown node %d->%v", i, n)
-                               return
+                               panic(fmt.Errorf("children of unknown node %d->%v", i, n))
                        }
                        if n.l.Target() == uint32(i) || n.r.Target() == uint32(i) {
-                               err = fmt.Errorf("self-loop on node %d", i)
-                               return
+                               panic(fmt.Errorf("self-loop on node %d", i))
                        }
                }
        }
-
-       return
 }
 
 // CheckEmpty checks that a poset is completely empty.
index cb739d9a0cecd1a541f8256b4f94436a06d35812..0a4f991e0022a0d59ef1d03b8e4221522a7353fd 100644 (file)
@@ -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))
                }
 
-               if err := po.CheckIntegrity(); err != nil {
-                       t.Fatalf("op%d%v: integrity error: %v", idx, op, err)
-               }
+               po.CheckIntegrity()
        }
 
        // Check that the poset is completely empty