mirror of
https://github.com/golang/go
synced 2024-11-23 21:20:03 -07:00
f1caf1aa1c
When a closure is inlined, it may contain other hidden closures, which the inliner will duplicate, rendering the original nested closures as unreachable. Because they are unreachable, they don't get processed in escape analysis, meaning that go/defer statements don't get rewritten, which can then in turn trigger errors in walk. This patch looks for nested hidden closures and marks them as dead, so that they can be skipped later on in the compilation flow. NB: if during escape analysis we rediscover a hidden closure (due to an explicit reference) that was previously marked dead, revive it at that point. Fixes #59404. Change-Id: I76db1e9cf1ee38bd1147aeae823f916dbbbf081b Reviewed-on: https://go-review.googlesource.com/c/go/+/482355 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
62 lines
935 B
Go
62 lines
935 B
Go
// build -gcflags=-l=4
|
|
|
|
// Copyright 2023 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package p
|
|
|
|
type Interface interface {
|
|
MonitoredResource() (resType string, labels map[string]string)
|
|
Done()
|
|
}
|
|
|
|
func Autodetect() Interface {
|
|
return func() Interface {
|
|
Do(func() {
|
|
var ad, gd Interface
|
|
|
|
go func() {
|
|
defer gd.Done()
|
|
ad = aad()
|
|
}()
|
|
go func() {
|
|
defer ad.Done()
|
|
gd = aad()
|
|
defer func() { recover() }()
|
|
}()
|
|
|
|
autoDetected = ad
|
|
if gd != nil {
|
|
autoDetected = gd
|
|
}
|
|
})
|
|
return autoDetected
|
|
}()
|
|
}
|
|
|
|
var autoDetected Interface
|
|
var G int
|
|
|
|
type If int
|
|
|
|
func (x If) MonitoredResource() (resType string, labels map[string]string) {
|
|
return "", nil
|
|
}
|
|
|
|
//go:noinline
|
|
func (x If) Done() {
|
|
G++
|
|
}
|
|
|
|
//go:noinline
|
|
func Do(fn func()) {
|
|
fn()
|
|
}
|
|
|
|
//go:noinline
|
|
func aad() Interface {
|
|
var x If
|
|
return x
|
|
}
|