From 6014dd720fbfddf5a20883e25c09e2a116db4cd3 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 6 Jul 2022 17:41:39 +0300 Subject: [PATCH] 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. --- pkg/compiler/codegen.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index f1d86748a..693bd7efd 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -914,15 +914,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { return nil } 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) - 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] if ok { @@ -938,6 +930,14 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { c.emitExplicitConvert(c.typeOf(n.Args[0]), typ) 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: // For now we will assume that there are only byte slice conversions. // E.g. []byte("foobar") or []byte(scriptHash).