compiler: don't push X onto the stack for inlined method calls

Regular methods need this, because it'll be packed into parameters, but
inlined ones should deal with it in inlining code itself because method
receiver will be some local (aliased) variable anyway.
This commit is contained in:
Roman Khimov 2022-07-06 17:41:39 +03:00
parent 2ba9017207
commit 6014dd720f

View file

@ -914,15 +914,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil return nil
} }
case *ast.SelectorExpr: case *ast.SelectorExpr:
// If this is a method call we need to walk the AST to load the struct locally.
// Otherwise, this is a function call from an imported package and we can call it
// directly.
name, isMethod := c.getFuncNameFromSelector(fun) name, isMethod := c.getFuncNameFromSelector(fun)
if isMethod {
ast.Walk(c, fun.X)
// Don't forget to add 1 extra argument when its a method.
numArgs++
}
f, ok = c.funcs[name] f, ok = c.funcs[name]
if ok { if ok {
@ -938,6 +930,14 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
c.emitExplicitConvert(c.typeOf(n.Args[0]), typ) c.emitExplicitConvert(c.typeOf(n.Args[0]), typ)
return nil return nil
} }
if isMethod {
// If this is a method call we need to walk the AST to load the struct locally.
// Otherwise, this is a function call from an imported package and we can call it
// directly.
ast.Walk(c, fun.X)
// Don't forget to add 1 extra argument when it's a method.
numArgs++
}
case *ast.ArrayType: case *ast.ArrayType:
// For now we will assume that there are only byte slice conversions. // For now we will assume that there are only byte slice conversions.
// E.g. []byte("foobar") or []byte(scriptHash). // E.g. []byte("foobar") or []byte(scriptHash).