aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/panic.go
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2024-01-26 17:49:33 -0500
committerDavid Chase <drchase@google.com>2024-05-21 21:08:03 +0000
commit5a9dabc2ba873f89a5de9ff53c8eab7c96d0c6b5 (patch)
tree0012a70f6ab947152eb5702dc102c4bd6275252c /src/runtime/panic.go
parent643865856c535a5a644201c602b18bd87b121c93 (diff)
downloadgo-5a9dabc2ba873f89a5de9ff53c8eab7c96d0c6b5.tar.xz
cmd/compile: for rangefunc, add checks and tests, fix panic interactions
Modify rangefunc #next protocol to make it more robust Extra-terrible nests of rangefunc iterators caused the prior implementation to misbehave non-locally (in outer loops). Add more rangefunc exit flag tests, parallel and tricky This tests the assertion that a rangefunc iterator running in parallel can trigger the race detector if any of the parallel goroutines attempts an early exit. It also verifies that if everything else is carefully written, that it does NOT trigger the race detector if all the parts run time completion. Another test tries to rerun a yield function within a loop, so that any per-line shared checking would be fooled. Added all the use-of-body/yield-function checking. These checks handle pathological cases that would cause rangefunc for loops to behave in surprising ways (compared to "regular" for loops). For example, a rangefunc iterator might defer-recover a panic thrown in the syntactic body of a loop; this notices the fault and panics with an explanation Modified closure naming to ID rangefunc bodies Add a "-range<N>" suffix to the name of any closure generated for a rangefunc loop body, as provided in Alessandro Arzilli's CL (which is merged into this one). Fix return values for panicky range functions This removes the delayed implementation of "return x" by ensuring that return values (in rangefunc-return-containing functions) always have names and translating the "return x" into "#rv1 = x" where #rv1 is the synthesized name of the first result. Updates #61405. Change-Id: I933299ecce04ceabcf1c0c2de8e610b2ecd1cfd8 Reviewed-on: https://go-review.googlesource.com/c/go/+/584596 Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tim King <taking@google.com>
Diffstat (limited to 'src/runtime/panic.go')
-rw-r--r--src/runtime/panic.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/runtime/panic.go b/src/runtime/panic.go
index 58d13b6adb..8bbb769df7 100644
--- a/src/runtime/panic.go
+++ b/src/runtime/panic.go
@@ -297,11 +297,31 @@ func deferproc(fn func()) {
// been set and must not be clobbered.
}
-var rangeExitError = error(errorString("range function continued iteration after exit"))
+var rangeDoneError = error(errorString("range function continued iteration after loop body exit"))
+var rangePanicError = error(errorString("range function continued iteration after loop body panic"))
+var rangeExhaustedError = error(errorString("range function continued iteration after whole loop exit"))
+var rangeMissingPanicError = error(errorString("range function recovered a loop body panic and did not resume panicking"))
//go:noinline
-func panicrangeexit() {
- panic(rangeExitError)
+func panicrangestate(state int) {
+ const (
+ // These duplicate magic numbers in cmd/compile/internal/rangefunc
+ DONE = 0 // body of loop has exited in a non-panic way
+ PANIC = 2 // body of loop is either currently running, or has panicked
+ EXHAUSTED = 3 // iterator function return, i.e., sequence is "exhausted"
+ MISSING_PANIC = 4 // body of loop panicked but iterator function defer-recovered it away
+ )
+ switch state {
+ case DONE:
+ panic(rangeDoneError)
+ case PANIC:
+ panic(rangePanicError)
+ case EXHAUSTED:
+ panic(rangeExhaustedError)
+ case MISSING_PANIC:
+ panic(rangeMissingPanicError)
+ }
+ throw("unexpected state passed to panicrangestate")
}
// deferrangefunc is called by functions that are about to