aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/crawler.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2022-01-11 09:14:38 -0800
committerDan Scales <danscales@google.com>2022-01-11 21:51:51 +0000
commitad7eae21d5e75a0b1fe89db5f299490d6273c4cf (patch)
treeba67e0511a9092b6c532ad9fce91ec6521125d70 /src/cmd/compile/internal/typecheck/crawler.go
parenta20724d63425ccb871c57d45e2401af2401518bc (diff)
downloadgo-ad7eae21d5e75a0b1fe89db5f299490d6273c4cf.tar.gz
go-ad7eae21d5e75a0b1fe89db5f299490d6273c4cf.zip
cmd/compile: resolve dictionaries/shape methods in markInlBody, if needed
Issue #50552 is due to a problem with my recent improvement in the interaction between generics and inlining. In markInlBody(), we now mark dictionaries and shape methods for export, so they will be available for any package that inlines the current inlineable function. But we need to make sure that the dictionary and method symbols have actually been resolved into Nodes (looked up in the import data), if they are not already defined, so we can then mark them for export. Improved header comment on Resolve(). Fixes #50552 Change-Id: I89e52d39d3b9894591d2ad6eb3a8ed3bb5f1e0a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/377714 Reviewed-by: Keith Randall <khr@golang.org> Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/crawler.go')
-rw-r--r--src/cmd/compile/internal/typecheck/crawler.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/typecheck/crawler.go b/src/cmd/compile/internal/typecheck/crawler.go
index cdb1c46509..87dc5165fd 100644
--- a/src/cmd/compile/internal/typecheck/crawler.go
+++ b/src/cmd/compile/internal/typecheck/crawler.go
@@ -8,6 +8,7 @@ import (
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/types"
+ "cmd/internal/src"
)
// crawlExports crawls the type/object graph rooted at the given list of exported
@@ -241,11 +242,12 @@ func (p *crawler) markInlBody(n *ir.Name) {
if t.IsFullyInstantiated() && !t.HasShape() && !t.IsInterface() && t.Methods().Len() > 0 {
// For any fully-instantiated type, the relevant
// dictionaries and shape instantiations will have
- // already been created. Make sure that they are
- // exported, so that any other package that inlines
- // this function will have them available for import,
- // and so will not need another round of method and
- // dictionary instantiation after inlining.
+ // already been created or are in the import data.
+ // Make sure that they are exported, so that any
+ // other package that inlines this function will have
+ // them available for import, and so will not need
+ // another round of method and dictionary
+ // instantiation after inlining.
baseType := t.OrigSym().Def.(*ir.Name).Type()
shapes := make([]*types.Type, len(t.RParams()))
for i, t1 := range t.RParams() {
@@ -254,8 +256,16 @@ func (p *crawler) markInlBody(n *ir.Name) {
for j := range t.Methods().Slice() {
baseNname := baseType.Methods().Slice()[j].Nname.(*ir.Name)
dictsym := MakeDictSym(baseNname.Sym(), t.RParams(), true)
+ if dictsym.Def == nil {
+ in := Resolve(ir.NewIdent(src.NoXPos, dictsym))
+ dictsym = in.Sym()
+ }
Export(dictsym.Def.(*ir.Name))
methsym := MakeFuncInstSym(baseNname.Sym(), shapes, false, true)
+ if methsym.Def == nil {
+ in := Resolve(ir.NewIdent(src.NoXPos, methsym))
+ methsym = in.Sym()
+ }
methNode := methsym.Def.(*ir.Name)
Export(methNode)
if HaveInlineBody(methNode.Func) {