Skip to content

Commit b41185c

Browse files
committed
cmd/compile: add call to ImportedBody() when exporting shape inst body
When we export a shape instantiation, because a particular fully-instantiated type is needed by an inlineable function, we possibly export the body of the instantiation, if it is inlineable. In this case, we should have been calling ImportedBody() to make sure that the function body had already been read in (if it is actually imported from another package). Fixes #50598 Change-Id: I512d2bcc745faa6ff3a97e25bc8f46e2c2643d23 Reviewed-on: https://go-review.googlesource.com/c/go/+/378494 Trust: Dan Scales <[email protected]> Run-TryBot: Dan Scales <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent e550c30 commit b41185c

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed

src/cmd/compile/internal/typecheck/crawler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func (p *crawler) checkForFullyInst(t *types.Type) {
252252
if HaveInlineBody(methNode.Func) {
253253
// Export the body as well if
254254
// instantiation is inlineable.
255+
ImportedBody(methNode.Func)
255256
methNode.Func.SetExportInline(true)
256257
}
257258
}

test/typeparam/issue50598.dir/a0.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a0
6+
7+
type Builder[T any] struct{}
8+
9+
func (r Builder[T]) New1() T {
10+
var v T
11+
return v
12+
}
13+
14+
func (r Builder[T]) New2() T {
15+
var v T
16+
return v
17+
}
18+
19+
type IntBuilder struct{}
20+
21+
func (b IntBuilder) New() int {
22+
return Builder[int]{}.New2()
23+
}

test/typeparam/issue50598.dir/a1.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a1
6+
7+
import "a0"
8+
9+
func New() int {
10+
return a0.IntBuilder{}.New()
11+
}

test/typeparam/issue50598.dir/a2.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a2
6+
7+
import "a0"
8+
9+
func New() int {
10+
return a0.Builder[int]{}.New1()
11+
}

test/typeparam/issue50598.dir/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"fmt"
9+
10+
"a1"
11+
"a2"
12+
)
13+
14+
func New() int {
15+
return a1.New() + a2.New()
16+
}
17+
18+
func main() {
19+
if got, want := New(), 0; got != want {
20+
panic(fmt.Sprintf("got %d, want %d", got, want))
21+
}
22+
}

test/typeparam/issue50598.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rundir -G=3
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package ignored

0 commit comments

Comments
 (0)