mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: implement range over func
Add compiler support for range over functions. See the large comment at the top of cmd/compile/internal/rangefunc/rewrite.go for details. This is only reachable if GOEXPERIMENT=range is set, because otherwise type checking will fail. For proposal #61405 (but behind a GOEXPERIMENT). For #61717. Change-Id: I05717f94e63089c503acc49b28b47edeb4e011b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/510541 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
a94347a05c
commit
2fba42cb52
17 changed files with 2101 additions and 217 deletions
|
|
@ -583,6 +583,17 @@ func walkCall(n *ir.CallExpr, init *ir.Nodes) ir.Node {
|
|||
return e
|
||||
}
|
||||
|
||||
if name, ok := n.X.(*ir.Name); ok {
|
||||
sym := name.Sym()
|
||||
if sym.Pkg.Path == "go.runtime" && sym.Name == "deferrangefunc" {
|
||||
// Call to runtime.deferrangefunc is being shared with a range-over-func
|
||||
// body that might add defers to this frame, so we cannot use open-coded defers
|
||||
// and we need to call deferreturn even if we don't see any other explicit defers.
|
||||
ir.CurFunc.SetHasDefer(true)
|
||||
ir.CurFunc.SetOpenCodedDeferDisallowed(true)
|
||||
}
|
||||
}
|
||||
|
||||
walkCall1(n, init)
|
||||
return n
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue