Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/xgo-dev/llgo/cl/blocks"
"github.com/xgo-dev/llgo/cl/ssawrap"
"github.com/xgo-dev/llgo/internal/genmethod"
"github.com/xgo-dev/llgo/internal/goembed"
"github.com/xgo-dev/llgo/internal/typepatch"
"golang.org/x/tools/go/ssa"
Expand Down Expand Up @@ -370,6 +371,9 @@ func (p *context) compileMethodsIf(pkg llssa.Package, typ types.Type, keep func(
mthds := prog.MethodSets.MethodSet(typ)
for i, n := 0, mthds.Len(); i < n; i++ {
mthd := mthds.At(i)
if genmethod.SupportsGenericMethods && genmethod.IsGenericMethod(mthd.Type()) {
continue
}
if ssaMthd := p.methodValue(mthd); ssaMthd != nil {
if keep != nil && !keep(ssaMthd) {
continue
Expand Down
6 changes: 6 additions & 0 deletions cl/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/xgo-dev/llgo/internal/directive"
"github.com/xgo-dev/llgo/internal/env"
"github.com/xgo-dev/llgo/internal/genmethod"
"github.com/xgo-dev/llgo/internal/locality"
llssa "github.com/xgo-dev/llgo/ssa"
)
Expand Down Expand Up @@ -555,6 +556,11 @@ func funcName(pkg *types.Package, fn *ssa.Function, org bool) string {
// will diverge for promoted unexported methods.
if method, ok := fn.Object().(*types.Func); ok {
fnName = llssa.MethodSymbolName(pkg, method, fnName)
if genmethod.SupportsGenericMethods && genmethod.IsGenericMethod(method.Type()) {
if targs := fn.TypeArgs(); len(targs) > 0 {
fnName += llssa.TypeArgs(targs)
}
}
}
// Synthesized $thunk/$bound functions have no Object. Their references
// are produced through this same funcName path, so the wrapper name is
Expand Down
10 changes: 9 additions & 1 deletion cl/instr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"golang.org/x/tools/go/ssa"

"github.com/xgo-dev/llgo/internal/genmethod"
llssa "github.com/xgo-dev/llgo/ssa"
)

Expand Down Expand Up @@ -1476,7 +1477,11 @@ func collectRuntimeCallerMethods(pkg *ssa.Package, runtimeTypes []types.Type) []
addMethods := func(typ types.Type) {
methodSet := pkg.Prog.MethodSets.MethodSet(typ)
for i := 0; i < methodSet.Len(); i++ {
fn := pkg.Prog.MethodValue(methodSet.At(i))
meth := methodSet.At(i)
if genmethod.SupportsGenericMethods && genmethod.IsGenericMethod(meth.Type()) {
continue
}
fn := pkg.Prog.MethodValue(meth)
if fn != nil && !seen[fn] {
seen[fn] = true
methods = append(methods, fn)
Expand Down Expand Up @@ -1788,6 +1793,9 @@ func (a *runtimeCallerAnalysis) methodTargetsForType(typ types.Type, method *typ
if sel.Obj().Name() != method.Name() {
continue
}
if genmethod.SupportsGenericMethods && genmethod.IsGenericMethod(sel.Type()) {
continue
}
fn := a.pkg.Prog.MethodValue(sel)
if fn == nil {
return nil, false
Expand Down
5 changes: 5 additions & 0 deletions internal/genmethod/method.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !go1.27

package genmethod

const SupportsGenericMethods = false
5 changes: 5 additions & 0 deletions internal/genmethod/method_go127.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build go1.27

package genmethod

const SupportsGenericMethods = true
7 changes: 7 additions & 0 deletions internal/genmethod/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package genmethod

import "go/types"

func IsGenericMethod(typ types.Type) bool {
return typ.(*types.Signature).TypeParams().Len() > 0
}
4 changes: 4 additions & 0 deletions ssa/abitype.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go/types"
"sort"

"github.com/xgo-dev/llgo/internal/genmethod"
"github.com/xgo-dev/llgo/ssa/abi"
"github.com/xgo-dev/llvm"
)
Expand Down Expand Up @@ -571,6 +572,9 @@ func (b Builder) abiInterfaceMethods(mset *types.MethodSet) []*types.Selection {
methods := make([]*types.Selection, 0, n)
for i := 0; i < n; i++ {
m := mset.At(i)
if genmethod.SupportsGenericMethods && genmethod.IsGenericMethod(m.Type()) {
continue
}
fn, _ := m.Obj().(*types.Func)
if b.Prog.isNoInterfaceMethod(fn) {
continue
Expand Down
Loading