compiler: canonicalize generic instance identities

x/tools SSA names and go/types strings can preserve the source spelling of
type arguments, so aliases can make distinct instances collide. Use the
canonical type encoding for function names, synthetic local type owners,
instantiated named types, and method sets.
This commit is contained in:
Jake Bailey
2026-07-12 14:12:54 -07:00
committed by Ron Evans
parent 73db9776b1
commit c7923d1c64
5 changed files with 51 additions and 46 deletions
+5 -19
View File
@@ -320,13 +320,7 @@ func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
}
info := functionInfo{
// Pick the default linkName.
linkName: f.RelString(nil),
}
// RelString is not unique for local type arguments, so add a suffix
// when needed.
if suffix := c.localTypeArgsSuffix(f); suffix != "" {
info.linkName += suffix
linkName: c.canonicalFunctionName(f),
}
// Check for a few runtime functions that are treated specially.
@@ -353,24 +347,16 @@ func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
return info
}
func (c *compilerContext) localTypeArgsSuffix(f *ssa.Function) string {
func (c *compilerContext) canonicalFunctionName(f *ssa.Function) string {
typeArgs := f.TypeArgs()
if len(typeArgs) == 0 {
return ""
return f.RelString(nil)
}
var hasLocal bool
parts := make([]string, len(typeArgs))
for i, ta := range typeArgs {
name, isLocal := c.getTypeCodeName(ta)
if isLocal {
hasLocal = true
}
parts[i] = name
parts[i], _ = c.getTypeCodeName(ta)
}
if !hasLocal {
return ""
}
return "$localtype:" + strings.Join(parts, ",")
return f.Origin().RelString(nil) + "[" + strings.Join(parts, ",") + "]"
}
// parsePragmas is used by getFunctionInfo to parse function pragmas such as