From f123f5c7689f8b631686f74ebcbce15a8c650e74 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Fri, 11 Aug 2023 14:22:56 -0700 Subject: [PATCH] cmd/compile: mark generated eq/hash functions as //go:noinline Instead of having the inliner specially recognize that eq/hash functions can't be inlined, change the geneq and genhash to mark them as //go:noinline. This is a prereq for a subsequent CL that will move more logic for handling rtypes from package types to package reflectdata. Change-Id: I091a9ededcc083fe8305cf5443a9af7d3a9053b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/518955 TryBot-Result: Gopher Robot Reviewed-by: Than McIntosh Auto-Submit: Matthew Dempsky Reviewed-by: Cuong Manh Le Run-TryBot: Matthew Dempsky --- src/cmd/compile/internal/inline/inl.go | 7 ------- src/cmd/compile/internal/ir/func.go | 8 -------- src/cmd/compile/internal/reflectdata/alg.go | 4 ++++ src/cmd/compile/internal/types/type.go | 5 ----- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 28cd870a54e..dfafd50dad5 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -438,13 +438,6 @@ func InlineImpossible(fn *ir.Func) string { return reason } - // 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 reason - } - return "" } diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go index a232c0fb708..dcd9e562896 100644 --- a/src/cmd/compile/internal/ir/func.go +++ b/src/cmd/compile/internal/ir/func.go @@ -301,14 +301,6 @@ func LinkFuncName(f *Func) string { return objabi.PathToPrefix(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/reflectdata/alg.go b/src/cmd/compile/internal/reflectdata/alg.go index 4489f59c26c..20b5b762653 100644 --- a/src/cmd/compile/internal/reflectdata/alg.go +++ b/src/cmd/compile/internal/reflectdata/alg.go @@ -152,6 +152,8 @@ func hashFunc(t *types.Type) *ir.Func { fn := typecheck.DeclFunc(sym, nil, args, results) sym.Def = fn.Nname + fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining. + np := ir.AsNode(fn.Type().Params().Field(0).Nname) nh := ir.AsNode(fn.Type().Params().Field(1).Nname) @@ -375,6 +377,8 @@ func eqFunc(t *types.Type) *ir.Func { []*ir.Field{ir.NewField(base.Pos, typecheck.Lookup("r"), types.Types[types.TBOOL])}, ) sym.Def = fn.Nname + fn.Pragma |= ir.Noinline // TODO(mdempsky): We need to emit this during the unified frontend instead, to allow inlining. + np := ir.AsNode(fn.Type().Params().Field(0).Nname) nq := ir.AsNode(fn.Type().Params().Field(1).Nname) nr := ir.AsNode(fn.Type().Results().Field(0).Nname) diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index c390b8194b8..2b72a9cd24a 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -1858,11 +1858,6 @@ 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 -} - // IsNoInstrumentPkg reports whether p is a package that // should not be instrumented. func IsNoInstrumentPkg(p *Pkg) bool {