Skip to content

Commit 7135b63

Browse files
authored
Merge pull request #1429 from visualfc/runtime_unique
refactor runtime instantiation type checking to support "unique" pkg
2 parents a029650 + 103944a commit 7135b63

File tree

20 files changed

+411
-124
lines changed

20 files changed

+411
-124
lines changed

_demo/go/netip/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/netip"
6+
)
7+
8+
func main() {
9+
s := netip.MustParseAddrPort("127.0.0.1:80")
10+
fmt.Println(s, s.Port())
11+
}

cl/_testgo/tpinst/out.ll

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -168,34 +168,6 @@ _llgo_0:
168168
ret void
169169
}
170170

171-
define linkonce double @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[float64]).Value"(ptr %0) {
172-
_llgo_0:
173-
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", ptr %0, i32 0, i32 0
174-
%2 = load double, ptr %1, align 8
175-
ret double %2
176-
}
177-
178-
define linkonce double @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[float64]).value"(ptr %0) {
179-
_llgo_0:
180-
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", ptr %0, i32 0, i32 0
181-
%2 = load double, ptr %1, align 8
182-
ret double %2
183-
}
184-
185-
define linkonce i64 @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[int]).Value"(ptr %0) {
186-
_llgo_0:
187-
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[int]", ptr %0, i32 0, i32 0
188-
%2 = load i64, ptr %1, align 4
189-
ret i64 %2
190-
}
191-
192-
define linkonce i64 @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[int]).value"(ptr %0) {
193-
_llgo_0:
194-
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[int]", ptr %0, i32 0, i32 0
195-
%2 = load i64, ptr %1, align 4
196-
ret i64 %2
197-
}
198-
199171
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
200172

201173
define void @"github.com/goplus/llgo/cl/_testgo/tpinst.init$after"() {
@@ -439,6 +411,20 @@ _llgo_26: ; preds = %_llgo_25, %_llgo_24
439411

440412
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String", i64, i64, i64, i64)
441413

414+
define linkonce i64 @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[int]).Value"(ptr %0) {
415+
_llgo_0:
416+
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[int]", ptr %0, i32 0, i32 0
417+
%2 = load i64, ptr %1, align 4
418+
ret i64 %2
419+
}
420+
421+
define linkonce i64 @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[int]).value"(ptr %0) {
422+
_llgo_0:
423+
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[int]", ptr %0, i32 0, i32 0
424+
%2 = load i64, ptr %1, align 4
425+
ret i64 %2
426+
}
427+
442428
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)
443429

444430
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String", i64, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
@@ -463,6 +449,20 @@ declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"gi
463449

464450
declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface")
465451

452+
define linkonce double @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[float64]).Value"(ptr %0) {
453+
_llgo_0:
454+
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", ptr %0, i32 0, i32 0
455+
%2 = load double, ptr %1, align 8
456+
ret double %2
457+
}
458+
459+
define linkonce double @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[float64]).value"(ptr %0) {
460+
_llgo_0:
461+
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", ptr %0, i32 0, i32 0
462+
%2 = load double, ptr %1, align 8
463+
ret double %2
464+
}
465+
466466
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface")
467467

468468
declare i1 @"github.com/goplus/llgo/runtime/internal/runtime.Implements"(ptr, ptr)

cl/_testrt/tpabi/out.ll

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -114,42 +114,6 @@ _llgo_2: ; preds = %_llgo_0
114114
unreachable
115115
}
116116

117-
define linkonce void @"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int].Info"(%"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]" %0) {
118-
_llgo_0:
119-
%1 = alloca %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", align 8
120-
call void @llvm.memset(ptr %1, i8 0, i64 24, i1 false)
121-
store %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]" %0, ptr %1, align 8
122-
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %1, i32 0, i32 0
123-
%3 = load %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %2, align 8
124-
%4 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %1, i32 0, i32 1
125-
%5 = load i64, ptr %4, align 4
126-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %3)
127-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
128-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %5)
129-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
130-
ret void
131-
}
132-
133-
define linkonce void @"github.com/goplus/llgo/cl/_testrt/tpabi.(*T[string,int]).Demo"(ptr %0) {
134-
_llgo_0:
135-
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %0, i32 0, i32 0
136-
%2 = load %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %1, align 8
137-
%3 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %0, i32 0, i32 1
138-
%4 = load i64, ptr %3, align 4
139-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %2)
140-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
141-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %4)
142-
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
143-
ret void
144-
}
145-
146-
define void @"github.com/goplus/llgo/cl/_testrt/tpabi.(*T[string,int]).Info"(ptr %0) {
147-
_llgo_0:
148-
%1 = load %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %0, align 8
149-
call void @"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int].Info"(%"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]" %1)
150-
ret void
151-
}
152-
153117
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
154118
declare void @llvm.memset(ptr nocapture writeonly, i8, i64, i1 immarg) #0
155119

@@ -288,6 +252,42 @@ _llgo_14: ; preds = %_llgo_13, %_llgo_12
288252

289253
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String", i64, i64, i64, i64)
290254

255+
define linkonce void @"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int].Info"(%"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]" %0) {
256+
_llgo_0:
257+
%1 = alloca %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", align 8
258+
call void @llvm.memset(ptr %1, i8 0, i64 24, i1 false)
259+
store %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]" %0, ptr %1, align 8
260+
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %1, i32 0, i32 0
261+
%3 = load %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %2, align 8
262+
%4 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %1, i32 0, i32 1
263+
%5 = load i64, ptr %4, align 4
264+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %3)
265+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
266+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %5)
267+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
268+
ret void
269+
}
270+
271+
define linkonce void @"github.com/goplus/llgo/cl/_testrt/tpabi.(*T[string,int]).Demo"(ptr %0) {
272+
_llgo_0:
273+
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %0, i32 0, i32 0
274+
%2 = load %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %1, align 8
275+
%3 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %0, i32 0, i32 1
276+
%4 = load i64, ptr %3, align 4
277+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %2)
278+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
279+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %4)
280+
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
281+
ret void
282+
}
283+
284+
define linkonce void @"github.com/goplus/llgo/cl/_testrt/tpabi.(*T[string,int]).Info"(ptr %0) {
285+
_llgo_0:
286+
%1 = load %"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", ptr %0, align 8
287+
call void @"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int].Info"(%"github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]" %1)
288+
ret void
289+
}
290+
291291
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)
292292

293293
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String", i64, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")

cl/_testrt/tpmethod/out.ll

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,6 @@ _llgo_0:
9595
ret void
9696
}
9797

98-
define linkonce %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error].Get"(%"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]" %0) {
99-
_llgo_0:
100-
%1 = alloca %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]", align 8
101-
call void @llvm.memset(ptr %1, i8 0, i64 16, i1 false)
102-
store %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]" %0, ptr %1, align 8
103-
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]", ptr %1, i32 0, i32 0
104-
%3 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %2, align 8
105-
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %3
106-
}
107-
108-
define %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.(*Tuple[error]).Get"(ptr %0) {
109-
_llgo_0:
110-
%1 = load %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]", ptr %0, align 8
111-
%2 = call %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error].Get"(%"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]" %1)
112-
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %2
113-
}
114-
115-
define linkonce void @"github.com/goplus/llgo/cl/_testrt/tpmethod.(*future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]).Then"(ptr %0, { ptr, ptr } %1) {
116-
_llgo_0:
117-
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpmethod.future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", ptr %0, i32 0, i32 0
118-
%3 = load { ptr, ptr }, ptr %2, align 8
119-
%4 = extractvalue { ptr, ptr } %3, 1
120-
%5 = extractvalue { ptr, ptr } %3, 0
121-
call void %5(ptr %4, { ptr, ptr } %1)
122-
ret void
123-
}
124-
12598
define linkonce %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.Async[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]"({ ptr, ptr } %0) {
12699
_llgo_0:
127100
%1 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
@@ -156,6 +129,16 @@ _llgo_0:
156129
ret void
157130
}
158131

132+
define linkonce %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error].Get"(%"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]" %0) {
133+
_llgo_0:
134+
%1 = alloca %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]", align 8
135+
call void @llvm.memset(ptr %1, i8 0, i64 16, i1 false)
136+
store %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]" %0, ptr %1, align 8
137+
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]", ptr %1, i32 0, i32 0
138+
%3 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %2, align 8
139+
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %3
140+
}
141+
159142
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintIface"(%"github.com/goplus/llgo/runtime/internal/runtime.iface")
160143

161144
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
@@ -548,6 +531,23 @@ _llgo_22: ; preds = %_llgo_21, %_llgo_20
548531

549532
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String", i64, i64, i64, i64)
550533

534+
define linkonce void @"github.com/goplus/llgo/cl/_testrt/tpmethod.(*future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]).Then"(ptr %0, { ptr, ptr } %1) {
535+
_llgo_0:
536+
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/tpmethod.future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", ptr %0, i32 0, i32 0
537+
%3 = load { ptr, ptr }, ptr %2, align 8
538+
%4 = extractvalue { ptr, ptr } %3, 1
539+
%5 = extractvalue { ptr, ptr } %3, 0
540+
call void %5(ptr %4, { ptr, ptr } %1)
541+
ret void
542+
}
543+
544+
define linkonce %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.(*Tuple[error]).Get"(ptr %0) {
545+
_llgo_0:
546+
%1 = load %"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]", ptr %0, align 8
547+
%2 = call %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error].Get"(%"github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]" %1)
548+
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %2
549+
}
550+
551551
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
552552

553553
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)

cl/builtin_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package cl
2222
import (
2323
"go/ast"
2424
"go/constant"
25+
"go/token"
2526
"go/types"
2627
"strings"
2728
"testing"
@@ -207,6 +208,25 @@ func TestRecvTypeName(t *testing.T) {
207208
recvTypeName(&ast.BadExpr{})
208209
}
209210

211+
func TestRecvType(t *testing.T) {
212+
pkg := types.NewPackage("", "main")
213+
obj := types.NewTypeName(token.NoPos, pkg, "T", nil)
214+
named := types.NewNamed(obj, types.Typ[types.Int], nil)
215+
if ret := recvNamed(named); ret != named {
216+
t.Fatal("error")
217+
}
218+
if ret := recvNamed(types.NewPointer(named)); ret != named {
219+
t.Fatal("error")
220+
}
221+
defer func() {
222+
err := recover()
223+
if err == nil {
224+
t.Fatal("must panic")
225+
}
226+
}()
227+
recvNamed(types.NewPointer(types.Typ[types.Int]))
228+
}
229+
210230
/*
211231
func TestErrCompileValue(t *testing.T) {
212232
defer func() {

cl/compile.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ func isCgoVar(name string) bool {
284284
return strings.HasPrefix(name, "__cgo_")
285285
}
286286

287+
// isInstance reports whether f is an instance method or generic instantiation.
288+
func isInstance(f *ssa.Function) bool {
289+
if f.Origin() != nil {
290+
return true
291+
}
292+
if recv := f.Type().(*types.Signature).Recv(); recv != nil {
293+
return recv.Origin() != recv
294+
}
295+
return false
296+
}
297+
287298
func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Function, llssa.PyObjRef, int) {
288299
pkgTypes, name, ftype := p.funcName(f)
289300
if ftype != goFunc {
@@ -317,7 +328,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
317328
}
318329
}
319330
if fn == nil {
320-
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx, f.Origin() != nil)
331+
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx, isInstance(f))
321332
if disableInline {
322333
fn.Inline(llssa.NoInline)
323334
}
@@ -1128,6 +1139,7 @@ func NewPackageEx(prog llssa.Program, patches Patches, rewrites map[string]strin
11281139
ctx.initPyModule()
11291140
ctx.initFiles(pkgPath, files, pkgName == "C")
11301141
ctx.prog.SetPatch(ctx.patchType)
1142+
ctx.prog.SetCheckRuntimeNamed(ctx.checkRuntimeNamed)
11311143
ret.SetPatch(ctx.patchType)
11321144
ret.SetResolveLinkname(ctx.resolveLinkname)
11331145

@@ -1273,21 +1285,6 @@ func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) {
12731285
}
12741286
}
12751287
}
1276-
1277-
// check instantiate named in RuntimeTypes
1278-
var typs []*types.Named
1279-
for _, T := range pkg.Prog.RuntimeTypes() {
1280-
if typ, ok := T.(*types.Named); ok && typ.TypeArgs() != nil && typ.Obj().Pkg() == pkg.Pkg {
1281-
typs = append(typs, typ)
1282-
}
1283-
}
1284-
sort.Slice(typs, func(i, j int) bool {
1285-
return typs[i].String() < typs[j].String()
1286-
})
1287-
for _, typ := range typs {
1288-
ctx.compileMethods(ret, typ)
1289-
ctx.compileMethods(ret, types.NewPointer(typ))
1290-
}
12911288
}
12921289

12931290
func (p *context) type_(typ types.Type, bg llssa.Background) llssa.Type {
@@ -1356,4 +1353,15 @@ func (p *context) resolveLinkname(name string) string {
13561353
return name
13571354
}
13581355

1356+
// checkRuntimeNamed compiles methods for generic type instantiations.
1357+
// Only types with type arguments (instantiated generics) need method compilation
1358+
// here, as non-generic types have their methods compiled elsewhere.
1359+
func (p *context) checkRuntimeNamed(pkg llssa.Package, typ *types.Named) {
1360+
if typ.TypeArgs() == nil {
1361+
return
1362+
}
1363+
p.compileMethods(pkg, typ)
1364+
p.compileMethods(pkg, types.NewPointer(typ))
1365+
}
1366+
13591367
// -----------------------------------------------------------------------------

cl/import.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,18 @@ const (
516516
llgoAtomicOpLast = llgoAtomicOpBase + int(llssa.OpUMin)
517517
)
518518

519+
func recvNamed(typ types.Type) *types.Named {
520+
retry:
521+
switch t := types.Unalias(typ).(type) {
522+
case *types.Named:
523+
return t
524+
case *types.Pointer:
525+
typ = t.Elem()
526+
goto retry
527+
}
528+
panic(fmt.Errorf("invalid recv type: %v", typ))
529+
}
530+
519531
func (p *context) funcName(fn *ssa.Function) (*types.Package, string, int) {
520532
var pkg *types.Package
521533
var orgName string
@@ -538,6 +550,9 @@ func (p *context) funcName(fn *ssa.Function) (*types.Package, string, int) {
538550
}
539551
if fnPkg := fn.Pkg; fnPkg != nil {
540552
pkg = fnPkg.Pkg
553+
} else if recv := fn.Type().(*types.Signature).Recv(); recv != nil && recv.Origin() != recv {
554+
/* check if this is an instantiated generic method (receiver's origin differs from receiver itself)*/
555+
pkg = recvNamed(recv.Type()).Obj().Pkg()
541556
} else {
542557
pkg = p.goTyps
543558
}

internal/build/build.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,12 @@ func Do(args []string, conf *Config) ([]Package, error) {
259259
cfg.Mode |= packages.NeedForTest
260260
}
261261

262+
goroot, err := env.GOROOT()
263+
check(err)
262264
cfg.Overlay = make(map[string][]byte)
263265
for file, src := range llruntime.OverlayFiles {
264266
overlay := unsafe.Slice(unsafe.StringData(src), len(src))
265-
cfg.Overlay[filepath.Join(env.GOROOT(), "src", file)] = overlay
267+
cfg.Overlay[filepath.Join(goroot, "src", file)] = overlay
266268
}
267269

268270
cl.EnableDebug(IsDbgEnabled())

0 commit comments

Comments
 (0)