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>
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)
}
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
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.