mirror of
https://github.com/golang/go
synced 2024-11-14 13:30:30 -07:00
ea69de9b92
[This is a roll-forward of CL 484859, this time including a fix for issue #59709. The call to do dead function marking was taking place in the wrong spot, causing it to run more than once if generics were instantiated.] This patch generalizes the code in the inliner that marks unreferenced hidden closure functions as dead. Rather than doing the marking on the fly (previous approach), this new approach does a single pass at the end of inlining, which catches more dead functions. Change-Id: I0e079ad755c21295477201acbd7e1a732a98fffd Reviewed-on: https://go-review.googlesource.com/c/go/+/492016 Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
66 lines
1004 B
Go
66 lines
1004 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(x int) Interface {
|
|
return func() Interface {
|
|
func() Interface {
|
|
x++
|
|
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
|
|
}()
|
|
return nil
|
|
}()
|
|
}
|
|
|
|
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
|
|
}
|