diff options
author | Dan Scales <danscales@google.com> | 2021-06-01 10:49:14 -0700 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2021-06-04 17:48:10 +0000 |
commit | de614651561c6d5bfe1e68bddaf0dedab9a0ecb0 (patch) | |
tree | a39ef75b81e36091467f1e09765ed4022475c1d0 /src/cmd/compile/internal/typecheck/iexport.go | |
parent | 4cf7f5f6947c1e3200d669ae7b8016f7431d718c (diff) | |
download | go-de614651561c6d5bfe1e68bddaf0dedab9a0ecb0.tar.gz go-de614651561c6d5bfe1e68bddaf0dedab9a0ecb0.zip |
[dev.typeparams] cmd/compile: allow inlining in instantiated functions
Change markType to scan generic types and methods, so that inlineable
functions inside generic functions/methods will be properly marked for
export, which means inlining inside instantiated functions will work
correctly.
Also, fix handling of closures for instantiated functions. Some code
needs to be adjusted, since instantiated functions/methods are compiled
as if in the package of the source generic function/type, rather than in
the local package. When we create the closure struct, we want to make
sure that the .F field has the same package as the other fields for the
closure variables. Also, we need to disable a check in tcCompLit() when
being done for an instantiated function, since fields of the closure
struct will be from the source package, not the local package.
Re-enabled part of the orderedmapsimp test that was disabled because of
these issues.
Change-Id: Ic4dba8917da0a36b17c0bdb69d6d6edfdf14104a
Reviewed-on: https://go-review.googlesource.com/c/go/+/324331
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iexport.go')
-rw-r--r-- | src/cmd/compile/internal/typecheck/iexport.go | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/src/cmd/compile/internal/typecheck/iexport.go b/src/cmd/compile/internal/typecheck/iexport.go index f635b79ada..236f6ed789 100644 --- a/src/cmd/compile/internal/typecheck/iexport.go +++ b/src/cmd/compile/internal/typecheck/iexport.go @@ -1332,24 +1332,9 @@ func (w *exportWriter) funcExt(n *ir.Name) { } } - // Inline body. - if n.Type().HasTParam() { - if n.Func.Inl != nil { - // n.Func.Inl may already be set on a generic function if - // we imported it from another package, but shouldn't be - // set for a generic function in the local package. - if n.Sym().Pkg == types.LocalPkg { - base.FatalfAt(n.Pos(), "generic function is marked inlineable") - } - } else { - // Populate n.Func.Inl, so body of exported generic function will - // be written out. - n.Func.Inl = &ir.Inline{ - Cost: 1, - Dcl: n.Func.Dcl, - Body: n.Func.Body, - } - } + // Write out inline body or body of a generic function/method. + if n.Type().HasTParam() && n.Func.Body != nil && n.Func.Inl == nil { + base.FatalfAt(n.Pos(), "generic function is not marked inlineable") } if n.Func.Inl != nil { w.uint64(1 + uint64(n.Func.Inl.Cost)) |