From 7fb075ddc00cf73810f0032734ad1ac5f09fbbe1 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 17 Feb 2023 11:19:32 +0700 Subject: [PATCH] cmd/compile: mark type eq/hash functions non-inlineable 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 Auto-Submit: Cuong Manh Le Reviewed-by: Keith Randall Reviewed-by: Matthew Dempsky Run-TryBot: Cuong Manh Le Reviewed-by: Keith Randall --- src/cmd/compile/internal/inline/inl.go | 7 +++++++ src/cmd/compile/internal/ir/func.go | 8 ++++++++ src/cmd/compile/internal/types/type.go | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 5b855252c0..03f565e9d3 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -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) } diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go index fba62283d5..967ebb02c2 100644 --- a/src/cmd/compile/internal/ir/func.go +++ b/src/cmd/compile/internal/ir/func.go @@ -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 diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index ed7054e641..77389495e1 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -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. -- 2.48.1