Update go version

This commit is contained in:
dwrz
2026-08-21 10:23:37 +00:00
parent 78248a6145
commit c2e2d9ea02
466 changed files with 67766 additions and 2881 deletions

View File

@@ -19,13 +19,13 @@ type generic struct {
}
// instance returns a Function that is the instantiation of generic
// origin function fn with the type arguments targs.
// origin function fn with the type arguments rtargs and targs.
//
// Any created instance is added to cr.
//
// Acquires fn.generic.instancesMu.
func (fn *Function) instance(targs []types.Type, b *builder) *Function {
key := fn.Prog.canon.List(targs)
func (fn *Function) instance(rtargs, targs []types.Type, b *builder) *Function {
key := fn.Prog.canon.List(slices.Concat(rtargs, targs))
gen := fn.generic
@@ -33,7 +33,7 @@ func (fn *Function) instance(targs []types.Type, b *builder) *Function {
defer gen.instancesMu.Unlock()
inst, ok := gen.instances[key]
if !ok {
inst = createInstance(fn, targs)
inst = createInstance(fn, rtargs, targs)
inst.buildshared = b.shared()
b.enqueue(inst)
@@ -48,20 +48,46 @@ func (fn *Function) instance(targs []types.Type, b *builder) *Function {
}
// createInstance returns the instantiation of generic function fn using targs.
// If fn is a method on a generic type, fn's receiver type will be instantiated
// using rtargs.
//
// Requires fn.generic.instancesMu.
func createInstance(fn *Function, targs []types.Type) *Function {
func createInstance(fn *Function, rtargs, targs []types.Type) *Function {
prog := fn.Prog
// Compute signature.
var sig *types.Signature
var obj *types.Func
if recv := fn.Signature.Recv(); recv != nil {
// method
obj = prog.canon.instantiateMethod(fn.object, targs, prog.ctxt)
sig = obj.Type().(*types.Signature)
// method, len(rtargs) > 0 || len(targs) > 0
if len(rtargs) > 0 {
// possibly generic method on generic type
obj = prog.canon.instantiateMethod(fn.object, rtargs, prog.ctxt)
} else {
// generic method on non-generic type
obj = fn.object // instantiation does not exist yet
}
if len(targs) > 0 {
// generic method
instSig, err := types.Instantiate(prog.ctxt, obj.Signature(), targs, false)
if err != nil {
panic(err)
}
instance, ok := instSig.(*types.Signature)
if !ok {
panic("Instantiate of a Signature returned a non-signature")
}
// Do not canonicalize generic methods, because the receiver is not
// part of a Signature's type identity. For example,
// (*G[int]).m[int] and (G[int]).n[int] may be identical types even
// though their receiver types differ.
sig = instance
} else {
// non-generic method on generic type
sig = obj.Signature()
}
} else {
// function
// function, len(rtargs) == 0 && len(targs) > 0
instSig, err := types.Instantiate(prog.ctxt, fn.Signature, targs, false)
if err != nil {
panic(err)
@@ -80,10 +106,10 @@ func createInstance(fn *Function, targs []types.Type) *Function {
subst *subster
build buildFunc
)
if prog.mode&InstantiateGenerics != 0 && !prog.isParameterized(targs...) {
if prog.mode&InstantiateGenerics != 0 && !prog.isParameterized(slices.Concat(rtargs, targs)...) {
synthetic = fmt.Sprintf("instance of %s", fn.Name())
if fn.syntax != nil {
subst = makeSubster(prog.ctxt, obj, fn.typeparams, targs)
subst = makeSubster(prog.ctxt, obj, fn.recvtypeparams, rtargs, fn.typeparams, targs)
build = (*builder).buildFromSyntax
} else {
build = (*builder).buildParamsOnly
@@ -93,9 +119,14 @@ func createInstance(fn *Function, targs []types.Type) *Function {
build = (*builder).buildInstantiationWrapper
}
name := fn.Name()
if len(targs) > 0 {
name = fmt.Sprintf("%s%s", name, targstr(targs)) // may not be unique
}
/* generic instance or instantiation wrapper */
return &Function{
name: fmt.Sprintf("%s%s", fn.Name(), targs), // may not be unique
name: name,
object: obj,
Signature: sig,
Synthetic: synthetic,
@@ -107,6 +138,8 @@ func createInstance(fn *Function, targs []types.Type) *Function {
pos: obj.Pos(),
Pkg: nil,
Prog: fn.Prog,
recvtypeparams: fn.recvtypeparams, // share with origin
recvtypeargs: rtargs,
typeparams: fn.typeparams, // share with origin
typeargs: targs,
subst: subst,