From 390763aed84189cb360e7ceb94aef56125fb140d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 30 Jun 2023 16:18:44 -0400 Subject: cmd/compile, runtime: make room for rangefunc defers This is subtle and the compiler and runtime be in sync. It is easier to develop the rest of the changes (especially when using toolstash save/restore) if this change is separated out and done first. Preparation for proposal #61405. The actual logic in the compiler will be guarded by a GOEXPERIMENT, but it is easier not to have GOEXPERIMENT-specific data structures in the runtime, so just make the field always. Change-Id: I7ec7049b99ae98bf0db365d42966baeec56e3774 Reviewed-on: https://go-review.googlesource.com/c/go/+/510539 TryBot-Result: Gopher Robot Run-TryBot: Russ Cox Reviewed-by: Matthew Dempsky --- src/runtime/runtime2.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/runtime/runtime2.go') diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 54fab050ea..5017a7a80a 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -1001,11 +1001,16 @@ func extendRandom(r []byte, n int) { // initialize them are not required. All defers must be manually scanned, // and for heap defers, marked. type _defer struct { - heap bool - sp uintptr // sp at time of defer - pc uintptr // pc at time of defer - fn func() // can be nil for open-coded defers - link *_defer // next defer on G; can point to either heap or stack! + heap bool + rangefunc bool // true for rangefunc list + sp uintptr // sp at time of defer + pc uintptr // pc at time of defer + fn func() // can be nil for open-coded defers + link *_defer // next defer on G; can point to either heap or stack! + + // If rangefunc is true, *head is the head of the atomic linked list + // during a range-over-func execution. + head *atomic.Pointer[_defer] } // A _panic holds information about an active panic. -- cgit v1.3