]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: for rangefunc, add checks and tests, fix panic interactions
authorDavid Chase <drchase@google.com>
Fri, 26 Jan 2024 22:49:33 +0000 (17:49 -0500)
committerDavid Chase <drchase@google.com>
Tue, 21 May 2024 21:08:03 +0000 (21:08 +0000)
commit5a9dabc2ba873f89a5de9ff53c8eab7c96d0c6b5
tree0012a70f6ab947152eb5702dc102c4bd6275252c
parent643865856c535a5a644201c602b18bd87b121c93
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>
16 files changed:
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/ir/sizeof_test.go
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/noder/unified.go
src/cmd/compile/internal/noder/writer.go
src/cmd/compile/internal/rangefunc/rangefunc_test.go
src/cmd/compile/internal/rangefunc/rewrite.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/typecheck/_builtin/runtime.go
src/cmd/compile/internal/typecheck/builtin.go
src/cmd/compile/internal/types2/compiler_internal.go [new file with mode: 0644]
src/cmd/internal/goobj/builtinlist.go
src/runtime/panic.go
src/runtime/race/testdata/rangefunc_test.go [new file with mode: 0644]