mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 03:03:27 +00:00
compiler: disambiguate generic instance link names with local type args
This commit is contained in:
@@ -97,7 +97,7 @@ func (b *builder) createGo(instr *ssa.Go) {
|
|||||||
funcType = b.getLLVMFunctionType(instr.Call.Value.Type().Underlying().(*types.Signature))
|
funcType = b.getLLVMFunctionType(instr.Call.Value.Type().Underlying().(*types.Signature))
|
||||||
params = append(params, context, funcPtr)
|
params = append(params, context, funcPtr)
|
||||||
hasContext = true
|
hasContext = true
|
||||||
prefix = b.fn.RelString(nil)
|
prefix = b.getFunctionInfo(b.fn).linkName
|
||||||
}
|
}
|
||||||
|
|
||||||
paramBundle := b.emitPointerPack(params)
|
paramBundle := b.emitPointerPack(params)
|
||||||
@@ -139,7 +139,7 @@ func (b *builder) createWasmExport() {
|
|||||||
// Declare the exported function.
|
// Declare the exported function.
|
||||||
paramTypes := b.llvmFnType.ParamTypes()
|
paramTypes := b.llvmFnType.ParamTypes()
|
||||||
exportedFnType := llvm.FunctionType(b.llvmFnType.ReturnType(), paramTypes[:len(paramTypes)-1], false)
|
exportedFnType := llvm.FunctionType(b.llvmFnType.ReturnType(), paramTypes[:len(paramTypes)-1], false)
|
||||||
exportedFn := llvm.AddFunction(b.mod, b.fn.RelString(nil)+suffix, exportedFnType)
|
exportedFn := llvm.AddFunction(b.mod, b.getFunctionInfo(b.fn).linkName+suffix, exportedFnType)
|
||||||
b.addStandardAttributes(exportedFn)
|
b.addStandardAttributes(exportedFn)
|
||||||
llvmutil.AppendToGlobal(b.mod, "llvm.used", exportedFn)
|
llvmutil.AppendToGlobal(b.mod, "llvm.used", exportedFn)
|
||||||
exportedFn.AddFunctionAttr(b.ctx.CreateStringAttribute("wasm-export-name", b.info.wasmExport))
|
exportedFn.AddFunctionAttr(b.ctx.CreateStringAttribute("wasm-export-name", b.info.wasmExport))
|
||||||
|
|||||||
@@ -323,6 +323,12 @@ func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
|
|||||||
linkName: f.RelString(nil),
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// Check for a few runtime functions that are treated specially.
|
// Check for a few runtime functions that are treated specially.
|
||||||
if info.linkName == "runtime.wasmEntryReactor" && c.BuildMode == "c-shared" {
|
if info.linkName == "runtime.wasmEntryReactor" && c.BuildMode == "c-shared" {
|
||||||
info.linkName = "_initialize"
|
info.linkName = "_initialize"
|
||||||
@@ -347,6 +353,26 @@ func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *compilerContext) localTypeArgsSuffix(f *ssa.Function) string {
|
||||||
|
typeArgs := f.TypeArgs()
|
||||||
|
if len(typeArgs) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if !hasLocal {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "$localtype:" + strings.Join(parts, ",")
|
||||||
|
}
|
||||||
|
|
||||||
// parsePragmas is used by getFunctionInfo to parse function pragmas such as
|
// parsePragmas is used by getFunctionInfo to parse function pragmas such as
|
||||||
// //export or //go:noinline.
|
// //export or //go:noinline.
|
||||||
func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
|
func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
|
||||||
|
|||||||
Vendored
+3
-3
@@ -42,8 +42,8 @@ ok: doublyNestedInGeneric[string].Y accepts own
|
|||||||
ok: doublyNestedInGeneric[int].Y rejects [string].Y
|
ok: doublyNestedInGeneric[int].Y rejects [string].Y
|
||||||
ok: doublyNestedInGeneric[string].Y rejects [int].Y
|
ok: doublyNestedInGeneric[string].Y rejects [int].Y
|
||||||
issue4931A labels: 0
|
issue4931A labels: 0
|
||||||
issue4931B labels: 1
|
issue4931B labels: 0
|
||||||
issue4931PairA labels: 0
|
issue4931PairA labels: 0
|
||||||
issue4931PairB labels: 1
|
issue4931PairB labels: 0
|
||||||
issue4931MethodA labels: 0
|
issue4931MethodA labels: 0
|
||||||
issue4931MethodB labels: 1
|
issue4931MethodB labels: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user