aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2022-02-02 13:47:31 -0500
committerRobert Findley <rfindley@google.com>2022-02-02 19:37:44 +0000
commit77eff30ec0bc63df61ea742bb8278f92e2c133dc (patch)
tree5d152782520da197733da353bcfa96e72955a78a /src
parentedbe4742a296239c06cd99721bb0dbc5008d35a1 (diff)
downloadgo-77eff30ec0bc63df61ea742bb8278f92e2c133dc.tar.xz
go/types, types2: add a const to control recursion panics in unification
Add a panicAtUnificationDepthLimit const to replace the use of the debug const to control whether to panic when the unification recursion depth is reached. Our tests should pass when debug==true. Change-Id: I58847f49d66010bd4ca01c0408ec10acac95cba6 Reviewed-on: https://go-review.googlesource.com/c/go/+/382534 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/types2/unify.go14
-rw-r--r--src/go/types/unify.go14
2 files changed, 20 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/types2/unify.go b/src/cmd/compile/internal/types2/unify.go
index 13d5af671e..079db3276c 100644
--- a/src/cmd/compile/internal/types2/unify.go
+++ b/src/cmd/compile/internal/types2/unify.go
@@ -33,9 +33,15 @@ import (
// by setting up one of them (using init) and then assigning its value
// to the other.
-// Upper limit for recursion depth. Used to catch infinite recursions
-// due to implementation issues (e.g., see issues #48619, #48656).
-const unificationDepthLimit = 50
+const (
+ // Upper limit for recursion depth. Used to catch infinite recursions
+ // due to implementation issues (e.g., see issues #48619, #48656).
+ unificationDepthLimit = 50
+
+ // Whether to panic when unificationDepthLimit is reached. Turn on when
+ // investigating infinite recursion.
+ panicAtUnificationDepthLimit = false
+)
// A unifier maintains the current type parameters for x and y
// and the respective types inferred for each type parameter.
@@ -244,7 +250,7 @@ func (u *unifier) nifyEq(x, y Type, p *ifacePair) bool {
func (u *unifier) nify(x, y Type, p *ifacePair) bool {
// Stop gap for cases where unification fails.
if u.depth >= unificationDepthLimit {
- if debug {
+ if panicAtUnificationDepthLimit {
panic("unification reached recursion depth limit")
}
return false
diff --git a/src/go/types/unify.go b/src/go/types/unify.go
index 5d6d78bff0..be2037ca81 100644
--- a/src/go/types/unify.go
+++ b/src/go/types/unify.go
@@ -33,9 +33,15 @@ import (
// by setting up one of them (using init) and then assigning its value
// to the other.
-// Upper limit for recursion depth. Used to catch infinite recursions
-// due to implementation issues (e.g., see issues #48619, #48656).
-const unificationDepthLimit = 50
+const (
+ // Upper limit for recursion depth. Used to catch infinite recursions
+ // due to implementation issues (e.g., see issues #48619, #48656).
+ unificationDepthLimit = 50
+
+ // Whether to panic when unificationDepthLimit is reached. Turn on when
+ // investigating infinite recursion.
+ panicAtUnificationDepthLimit = false
+)
// A unifier maintains the current type parameters for x and y
// and the respective types inferred for each type parameter.
@@ -244,7 +250,7 @@ func (u *unifier) nifyEq(x, y Type, p *ifacePair) bool {
func (u *unifier) nify(x, y Type, p *ifacePair) bool {
// Stop gap for cases where unification fails.
if u.depth >= unificationDepthLimit {
- if debug {
+ if panicAtUnificationDepthLimit {
panic("unification reached recursion depth limit")
}
return false