]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: mark type eq/hash functions non-inlineable
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 17 Feb 2023 04:19:32 +0000 (11:19 +0700)
committerGopher Robot <gobot@golang.org>
Tue, 28 Feb 2023 17:42:29 +0000 (17:42 +0000)
The compiler used to generate ONAME node with nil Func for them, so the
inliner can still analyze, but could not generate inline call for them
anyway.

CL 436961 attempts to create ONAME node with non-nil Func, causing the
inliner complains about missing body reader.

This CL makes inliner recognize type eq/hash functions, and mark them as
non-inlineable. Longer term, if we do want to inline these functions, we
need to integrate the code generation into Unified IR frontend.

Updates #58572

Change-Id: Icdd4dda03711929faa3d48fe2d9886568471f0bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/469017
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/types/type.go

index 5b855252c01580014fb749075ec8a56c8e402cb9..03f565e9d3c1763deb0cc16bf99e856b7ba3a47d 100644 (file)
@@ -290,6 +290,13 @@ func CanInline(fn *ir.Func, profile *pgo.Profile) {
                return
        }
 
+       // If fn is synthetic hash or eq function, cannot inline it.
+       // The function is not generated in Unified IR frontend at this moment.
+       if ir.IsEqOrHashFunc(fn) {
+               reason = "type eq/hash function"
+               return
+       }
+
        if fn.Typecheck() == 0 {
                base.Fatalf("CanInline on non-typechecked function %v", fn)
        }
index fba62283d5bad34d637e96ca728cbe984509e5fb..967ebb02c2f6146d099895b8f21df74dacafcb87 100644 (file)
@@ -275,6 +275,14 @@ func PkgFuncName(f *Func) string {
        return pkg.Path + "." + s.Name
 }
 
+// IsEqOrHashFunc reports whether f is type eq/hash function.
+func IsEqOrHashFunc(f *Func) bool {
+       if f == nil || f.Nname == nil {
+               return false
+       }
+       return types.IsTypePkg(f.Sym().Pkg)
+}
+
 var CurFunc *Func
 
 // WithFunc invokes do with CurFunc and base.Pos set to curfn and
index ed7054e6411147baa13f1fc0d1b18a1c94f41215..77389495e134a034f35ebe916bcf2965270cf5da 100644 (file)
@@ -1857,6 +1857,11 @@ func IsReflectPkg(p *Pkg) bool {
        return p.Path == "reflect"
 }
 
+// IsTypePkg reports whether p is pesudo package type.
+func IsTypePkg(p *Pkg) bool {
+       return p == typepkg
+}
+
 // ReceiverBaseType returns the underlying type, if any,
 // that owns methods with receiver parameter t.
 // The result is either a named type or an anonymous struct.