From e8748fa7b517b1d775c1f6578e1b703ed95fd8de Mon Sep 17 00:00:00 2001 From: Matthew Suozzo Date: Tue, 3 Nov 2026 22:22:38 +0000 Subject: [PATCH 1/2] Store linear memory in a local variable across non-growing spans. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generated functions address linear memory as `m.memory` (or `*m.memory`) on every access, so Go reloads the slice header after every store and cannot reuse bounds checks across adjacent loads and stores. Instead of loading the slice on every read, store `mem := m.memory` in a local variable (an overhead of one load) and re-assign it it only after calls that may grow the underlying memory slice. Apply this when it reduces slice loads outright, or when a call-free function has a loop. Benchmarks on `go-sqlite3` (`wasm2go -unsafe`): goos: linux goarch: amd64 cpu: AMD EPYC 7B13 pkg: github.com/ncruces/go-sqlite3/driver │ before │ after │ │ sec/op │ sec/op vs base │ _loop 582.1m ± 0% 537.1m ± 1% -7.72% (p=0.000 n=8) pkg: github.com/ncruces/go-sqlite3/ext/stats │ before │ after │ │ sec/op │ sec/op vs base │ _average 92.19n ± 0% 84.03n ± 0% -8.85% (p=0.000 n=8) _variance 108.65n ± 1% 99.46n ± 2% -8.45% (p=0.000 n=8) geomean 100.1n 91.42n -8.65% pkg: github.com/ncruces/go-sqlite3/vfs/tests/speedtest1 │ before │ after │ │ sec/op │ sec/op vs base │ _speedtest1 72.40m ± 1% 70.13m ± 1% -3.15% (p=0.000 n=8) --- fncompiler.go | 28 ++ ids.go | 1 + internal/passes/memory.go | 153 ++++++++ internal/passes/memory_test.go | 337 ++++++++++++++++++ regression_test.go | 6 + testdata/loops/loops.go | 3 +- testdata/regression/store_grow/store_grow.go | 16 +- .../regression/store_grow/store_grow.wasm | Bin 78 -> 114 bytes testdata/regression/store_grow/store_grow.wat | 4 + 9 files changed, 545 insertions(+), 3 deletions(-) create mode 100644 internal/passes/memory.go create mode 100644 internal/passes/memory_test.go diff --git a/fncompiler.go b/fncompiler.go index 3096dd8f..7bf21538 100644 --- a/fncompiler.go +++ b/fncompiler.go @@ -620,6 +620,34 @@ func (fn *funcCompiler) cleanup() { passes.InlineGotoEnd(fn.decl) passes.InlineGotoReturn(fn.decl) passes.UnnestSimple(fn.decl) + // Switch from LoadOnRead to LoadOnWrite before RemoveReceiver, + // since loading m.memory into mem uses m. + if fn.memory != nil && !fn.memory.shared { + if passes.SelectMemoryMode(fn.decl, fn.memory.selector, fn.mayGrowMemory) == passes.LoadOnWrite { + passes.LoadMemoryOnWrite(fn.decl, fn.memory.selector, newID("mem"), fn.mayGrowMemory) + } + } +} + +// Reports whether ce may grow linear memory. +func (fn *funcCompiler) mayGrowMemory(ce *ast.CallExpr) bool { + switch f := ce.Fun.(type) { + case *ast.ParenExpr: + // Module, provided, or imported function call: (m.fnN)(...) + // Receiverless (fnN)(...) calls cannot access m or grow memory. + _, ok := f.X.(*ast.SelectorExpr) + return ok + case *ast.TypeAssertExpr: + // Indirect table call: m.t0[i].(func(...))(...) + return true + case *ast.Ident: + return f.Name == "memory_grow" + case *ast.SelectorExpr: + // Imported memory.grow: m.memImp.Grow(...) + _, ok := f.X.(*ast.SelectorExpr) + return ok && f.Sel.Name == "Grow" + } + return false } type funcBlock struct { diff --git a/ids.go b/ids.go index c360fc41..efba8c0f 100644 --- a/ids.go +++ b/ids.go @@ -27,6 +27,7 @@ import ( // // Method code may have: // - module selector (m) +// - local memory slice (mem) // - local variables, arguments (v+number) // - materialized temporaries (t+number) // - temporary variables (p+number) diff --git a/internal/passes/memory.go b/internal/passes/memory.go new file mode 100644 index 00000000..2f92f580 --- /dev/null +++ b/internal/passes/memory.go @@ -0,0 +1,153 @@ +package passes + +import ( + "go/ast" + "go/token" + "slices" + + "golang.org/x/tools/go/ast/astutil" +) + +// MemoryMode controls how a function loads the linear memory slice. +type MemoryMode int + +const ( + // LoadOnRead loads the memory slice on every memory access. + LoadOnRead MemoryMode = iota + // LoadOnWrite stores the memory slice in a local variable and reloads it + // after calls that may grow memory. + LoadOnWrite +) + +// SelectMemoryMode chooses between LoadOnRead and LoadOnWrite for fn. +// +// LoadOnWrite has an overhead of one load to initialize mem plus a reload +// after each call that may grow memory, so it is chosen when it reduces slice +// loads relative to LoadOnRead. A single read in a call-free function with a +// loop also uses LoadOnWrite so the load is hoisted out of the loop (when calls +// are present, a reload could itself run inside the loop). +func SelectMemoryMode(fn *ast.FuncDecl, slice ast.Expr, mayGrow func(*ast.CallExpr) bool) MemoryMode { + reads, hasLoop, start, end := memorySpan(fn, slice) + if reads == 0 { + return LoadOnRead + } + + calls := 0 + postApplyStmts(&ast.BlockStmt{List: fn.Body.List[start:end]}, func(stmts []ast.Stmt) []ast.Stmt { + for _, s := range stmts { + if stmtHasCall(s, mayGrow) { + calls++ + } + } + return stmts + }) + + if calls == 0 && hasLoop { + return LoadOnWrite + } + if 1+calls < reads { + return LoadOnWrite + } + return LoadOnRead +} + +// LoadMemoryOnWrite rewrites fn to store the memory slice in mem across its +// active span and reload it after calls that may grow memory. +// +// TODO: Elide unnecessary loads e.g. mem not read between calls. +func LoadMemoryOnWrite(fn *ast.FuncDecl, slice ast.Expr, mem *ast.Ident, mayGrow func(*ast.CallExpr) bool) { + reads, _, start, end := memorySpan(fn, slice) + if reads == 0 { + return + } + + region := &ast.BlockStmt{List: slices.Clone(fn.Body.List[start:end])} + astutil.Apply(region, func(c *astutil.Cursor) bool { + if u, ok := c.Node().(*ast.UnaryExpr); ok && u.Op == token.AND && u.X == slice { + return false + } + if c.Node() == slice { + c.Replace(mem) + return false + } + return true + }, nil) + postApplyStmts(region, func(stmts []ast.Stmt) []ast.Stmt { + for i := len(stmts) - 1; i >= 0; i-- { + if stmtHasCall(stmts[i], mayGrow) { + reload := &ast.AssignStmt{Tok: token.ASSIGN, Lhs: []ast.Expr{mem}, Rhs: []ast.Expr{slice}} + stmts = slices.Insert(stmts, i+1, ast.Stmt(reload)) + } + } + return stmts + }) + init := &ast.AssignStmt{Tok: token.DEFINE, Lhs: []ast.Expr{mem}, Rhs: []ast.Expr{slice}} + fn.Body.List = slices.Concat(fn.Body.List[:start], []ast.Stmt{init}, region.List, fn.Body.List[end:]) +} + +// Bounds [start:end] to the top-level span of memory reads, labels, and gotos. +// Declaring mem at start skips leading guards and calls, prevents any goto from +// jumping over the declaration, and avoids reloading after calls in trailing +// read-free statements. +func memorySpan(fn *ast.FuncDecl, slice ast.Expr) (reads int, hasLoop bool, start, end int) { + start = -1 + if fn.Body == nil { + return 0, false, -1, 0 + } + labels := set[string]{} + for i, s := range fn.Body.List { + r, br, loop := inspectMemStmt(s, slice, labels) + reads += r + hasLoop = hasLoop || loop + if r > 0 || br { + if start < 0 { + start = i + } + end = i + 1 + } + } + return reads, hasLoop, start, end +} + +// Inspects s for direct reads of the memory slice, labels or gotos, and backward-goto loops. +func inspectMemStmt(s ast.Stmt, slice ast.Expr, labels set[string]) (reads int, branch, loop bool) { + ast.Inspect(s, func(n ast.Node) bool { + switch x := n.(type) { + case *ast.UnaryExpr: + return !(x.Op == token.AND && x.X == slice) + case *ast.LabeledStmt: + labels.add(x.Label.Name) + branch = true + case *ast.BranchStmt: + if x.Tok == token.GOTO { + branch = true + loop = loop || labels.has(x.Label.Name) + } + } + if n == slice { + reads++ + return false + } + return true + }) + return reads, branch, loop +} + +// Reports whether s is an elementary statement containing a call matching pred. +// Compound statements are skipped because calls are materialized into their own +// ExprStmt or AssignStmt and visited at their inner statement list. +func stmtHasCall(s ast.Stmt, pred func(*ast.CallExpr) bool) (found bool) { + for ls, ok := s.(*ast.LabeledStmt); ok; ls, ok = s.(*ast.LabeledStmt) { + s = ls.Stmt + } + if !is[*ast.ExprStmt](s) && !is[*ast.AssignStmt](s) { + return false + } + ast.Inspect(s, func(n ast.Node) bool { + if ce, ok := n.(*ast.CallExpr); ok && pred(ce) { + found = true + } + return !found + }) + return found +} diff --git a/internal/passes/memory_test.go b/internal/passes/memory_test.go new file mode 100644 index 00000000..5bed68ee --- /dev/null +++ b/internal/passes/memory_test.go @@ -0,0 +1,337 @@ +package passes + +import ( + "go/ast" + "testing" + + "golang.org/x/tools/go/ast/astutil" +) + +func TestSelectMemoryMode(t *testing.T) { + memSlice := &ast.SelectorExpr{X: ast.NewIdent("m"), Sel: ast.NewIdent("memory")} + impSlice := &ast.StarExpr{X: memSlice} + + tests := []struct { + name string + slice ast.Expr + src string + want MemoryMode + }{ + { + name: "address-of memory without reads", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + return int32(memory_grow(&m.memory, int64(v0), maxMem)) + }`, + want: LoadOnRead, + }, + { + name: "single read outside loop", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + return int32(load32(m.memory, uint32(v0))) + }`, + want: LoadOnRead, + }, + { + name: "forward goto with single read", + slice: impSlice, + src: `func (m *Module) f(v0 int32) int32 { + if v0 == 0 { + goto l0 + } + store32(*m.memory, 0, 1) + l0: + return 0 + }`, + want: LoadOnRead, + }, + { + name: "two reads without calls", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + store32(m.memory, uint32(v0), 1) + return int32(load32(m.memory, uint32(v0))) + }`, + want: LoadOnWrite, + }, + { + name: "single read in backward goto loop", + slice: impSlice, + src: `func (m *Module) f(v0, v1 int32) int32 { + var v2, v3 int32 + l0: + if v2 >= v1 { + return v3 + } + v3 += int32(load32(*m.memory, uint32(v0))) + v2++ + goto l0 + }`, + want: LoadOnWrite, + }, + { + name: "calls outside active span ignored", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + t0 := (m._alloc)() + store32(m.memory, uint32(v0), uint32(t0)) + v1 := int32(load32(m.memory, uint32(v0))) + _ = memory_grow(&m.memory, 1, maxMem) + return v1 + }`, + want: LoadOnWrite, + }, + { + name: "two reads with one call in span", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + store32(m.memory, 0, 1) + (m._alloc)() + return int32(load32(m.memory, 0)) + }`, + want: LoadOnRead, + }, + { + name: "three reads with one call in span", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + store32(m.memory, 0, 1) + (m._alloc)() + store32(m.memory, 4, 2) + return int32(load32(m.memory, 0)) + }`, + want: LoadOnWrite, + }, + { + name: "two reads with call in loop stays LoadOnRead", + slice: impSlice, + src: `func (m *Module) f(v0 int32) int32 { + store32(*m.memory, 0, 1) + store32(*m.memory, 4, 2) + l0: + t0 := (m._step)() + if t0 != 0 { + goto l0 + } + return 0 + }`, + want: LoadOnRead, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + fn := parseFunc(t, tt.src) + internMemSlice(fn, tt.slice) + if got := SelectMemoryMode(fn, tt.slice, testMayGrow); got != tt.want { + t.Errorf("SelectMemoryMode() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestLoadMemoryOnWrite(t *testing.T) { + memSlice := &ast.SelectorExpr{X: ast.NewIdent("m"), Sel: ast.NewIdent("memory")} + impSlice := &ast.StarExpr{X: memSlice} + memID := ast.NewIdent("mem") + + tests := []struct { + name string + slice ast.Expr + src string + want string + }{ + { + name: "leading guards and calls skipped and trailing grow unrefreshed", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + var v1 int32 + if v0 == 0 { + return 0 + } + t0 := (m._alloc)() + store32(m.memory, uint32(v0), uint32(t0)) + v1 = int32(load32(m.memory, uint32(v0))) + _ = memory_grow(&m.memory, 1, maxMem) + return v1 + }`, + want: `func (m *Module) f(v0 int32) int32 { + var v1 int32 + if v0 == 0 { + return 0 + } + t0 := (m._alloc)() + mem := m.memory + store32(mem, uint32(v0), uint32(t0)) + v1 = int32(load32(mem, uint32(v0))) + _ = memory_grow(&m.memory, 1, maxMem) + return v1 + }`, + }, + { + name: "loop hoist for imported memory", + slice: impSlice, + src: `func (m *Module) f(v0, v1 int32) int32 { + var v2, v3 int32 + v2 = 0 + l0: + if v2 >= v1 { + return v3 + } + v3 += int32(load32(*m.memory, uint32(v0))) + v2++ + goto l0 + }`, + want: `func (m *Module) f(v0, v1 int32) int32 { + var v2, v3 int32 + v2 = 0 + mem := *m.memory + l0: + if v2 >= v1 { + return v3 + } + v3 += int32(load32(mem, uint32(v0))) + v2++ + goto l0 + }`, + }, + { + name: "grow calls reload mem while preserving address-of and pure helpers", + slice: memSlice, + src: `func (m *Module) f(v0 int32) int32 { + t0 := (fn0)(v0) + store32(m.memory, 0, uint32(t0)) + if v0 != 0 { + _ = memory_grow(&m.memory, 1, maxMem) + } + (m._alloc)() + m.t0[uint(v0)].(func())() + return int32(load32(m.memory, 0)) + }`, + want: `func (m *Module) f(v0 int32) int32 { + t0 := (fn0)(v0) + mem := m.memory + store32(mem, 0, uint32(t0)) + if v0 != 0 { + _ = memory_grow(&m.memory, 1, maxMem) + mem = m.memory + } + (m._alloc)() + mem = m.memory + m.t0[uint(v0)].(func())() + mem = m.memory + return int32(load32(mem, 0)) + }`, + }, + { + name: "switch cases and byte index and len rewrites", + slice: memSlice, + src: `func (m *Module) f(v0, v1 int32) int32 { + m.memory[uint32(v0)] = byte(v1) + t0 := int32(len(m.memory) >> 16) + switch v0 { + case 0: + (m._alloc)() + fallthrough + case 1: + m.memory[uint32(v0)+1] = byte(t0) + } + return int32(m.memory[uint32(v0)]) + }`, + want: `func (m *Module) f(v0, v1 int32) int32 { + mem := m.memory + mem[uint32(v0)] = byte(v1) + t0 := int32(len(mem) >> 16) + switch v0 { + case 0: + (m._alloc)() + mem = m.memory + fallthrough + case 1: + mem[uint32(v0)+1] = byte(t0) + } + return int32(mem[uint32(v0)]) + }`, + }, + { + name: "forward goto and labeled grow keep mem in scope", + slice: impSlice, + src: `func (m *Module) f(v0 int32) int32 { + if v0 == 0 { + goto l0 + } + store32(*m.memory, 0, 1) + l0: + _ = m.memImp.Grow(1, maxMem) + return int32(load32(*m.memory, 0)) + }`, + want: `func (m *Module) f(v0 int32) int32 { + mem := *m.memory + if v0 == 0 { + goto l0 + } + store32(mem, 0, 1) + l0: + _ = m.memImp.Grow(1, maxMem) + mem = *m.memory + return int32(load32(mem, 0)) + }`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + fn := parseFunc(t, tt.src) + internMemSlice(fn, tt.slice) + LoadMemoryOnWrite(fn, tt.slice, memID, testMayGrow) + got := formatFunc(t, fn) + want := normalizeFunc(t, tt.want) + if got != want { + t.Errorf("got:\n%s\n\nwant:\n%s", got, want) + } + }) + } +} + +func testMayGrow(ce *ast.CallExpr) bool { + switch fn := ce.Fun.(type) { + case *ast.ParenExpr: + _, ok := fn.X.(*ast.SelectorExpr) + return ok + case *ast.TypeAssertExpr: + return true + case *ast.Ident: + return fn.Name == "memory_grow" + case *ast.SelectorExpr: + _, ok := fn.X.(*ast.SelectorExpr) + return ok && fn.Sel.Name == "Grow" + } + return false +} + +func internMemSlice(fn *ast.FuncDecl, slice ast.Expr) { + isMemSel := func(n ast.Node) bool { + s, ok := n.(*ast.SelectorExpr) + if !ok { + return false + } + x, ok := s.X.(*ast.Ident) + return ok && x.Name == "m" && s.Sel.Name == "memory" + } + astutil.Apply(fn.Body, func(c *astutil.Cursor) bool { + switch slice.(type) { + case *ast.StarExpr: + if st, ok := c.Node().(*ast.StarExpr); ok && isMemSel(st.X) { + c.Replace(slice) + return false + } + case *ast.SelectorExpr: + if isMemSel(c.Node()) { + c.Replace(slice) + return false + } + } + return true + }, nil) +} diff --git a/regression_test.go b/regression_test.go index 72e10d06..d5fa9225 100644 --- a/regression_test.go +++ b/regression_test.go @@ -41,6 +41,12 @@ func Test_regression_store_grow(t *testing.T) { if got := m.Xsize(); got != 2 { t.Errorf("size = %d, want 2", got) } + if got := m.Xgrow_mid(); got != 12345 { + t.Errorf("grow_mid() = %d, want 12345 (local mem must reload after memory.grow)", got) + } + if got := m.Xsize(); got != 3 { + t.Errorf("size = %d, want 3", got) + } } func Test_regression_oob_trap(t *testing.T) { diff --git a/testdata/loops/loops.go b/testdata/loops/loops.go index 5c8f6882..0de3f826 100644 --- a/testdata/loops/loops.go +++ b/testdata/loops/loops.go @@ -44,13 +44,14 @@ func (m *Module) fn1() int32 { func (m *Module) Xadd_all(v0, v1 int32) int32 { var v2, v3, v4 int32 v2 = i32(0) + mem := *m.memory l1: { if v2 >= v1 { return v4 } v3 = v0 + v2*i32(4) - t0 := int32(load32(*m.memory, uint32(v3))) + t0 := int32(load32(mem, uint32(v3))) v4 = v4 + t0 v2 = v2 + i32(1) goto l1 diff --git a/testdata/regression/store_grow/store_grow.go b/testdata/regression/store_grow/store_grow.go index af060001..1c70d2ff 100644 --- a/testdata/regression/store_grow/store_grow.go +++ b/testdata/regression/store_grow/store_grow.go @@ -30,10 +30,22 @@ func (m *Module) fn0() int32 { } func (m *Module) Xtest() int32 { t0 := m.fn0() - store32(m.memory, uint32(i32(0)), uint32(t0)) - t1 := int32(load32(m.memory, uint32(i32(0)))) + mem := m.memory + store32(mem, uint32(i32(0)), uint32(t0)) + t1 := int32(load32(mem, uint32(i32(0)))) return t1 } +func (m *Module) Xgrow_mid() int32 { + var v0 int32 + mem := m.memory + t0 := int32(len(mem) >> 16) + v0 = t0 << 16 + t1 := m.fn0() + mem = m.memory + store32(mem, uint32(v0), uint32(t1)) + t2 := int32(load32(mem, uint32(v0))) + return t2 +} func (m *Module) Xsize() int32 { t0 := int32(len(m.memory) >> 16) return t0 diff --git a/testdata/regression/store_grow/store_grow.wasm b/testdata/regression/store_grow/store_grow.wasm index 08ff5aea18ce85e5c56d4565b1658c6a86216a4b..b755236f8bdcb6c4618b0c9e3d191ac7c20948a0 100644 GIT binary patch delta 94 zcmeY(vSLUq&Shj^U|?irOkiNFXJ%yqau`^d85tParI=YtQj1F%7&+35^2_6MGgBCt uSc)^NQW==JELkS%Ny~~eGS=HOI0}>~GAJ+zFqkm`DGeqDZWac625tb;*A7hp delta 58 zcmXT&(_=_1&Shj^U|?irOkiNFXJ%mra#)!e85r65nOI6vi%S?7S&B2OQW==I6qzSl MNwcyr*fVeg0QCn5F#rGn diff --git a/testdata/regression/store_grow/store_grow.wat b/testdata/regression/store_grow/store_grow.wat index 545aa84d..a305e48a 100644 --- a/testdata/regression/store_grow/store_grow.wat +++ b/testdata/regression/store_grow/store_grow.wat @@ -6,5 +6,9 @@ (func (export "test") (result i32) (i32.store (i32.const 0) (call $alloc)) (i32.load (i32.const 0))) + (func (export "grow_mid") (result i32) (local $off i32) + (local.set $off (i32.shl (memory.size) (i32.const 16))) + (i32.store (local.get $off) (call $alloc)) + (i32.load (local.get $off))) (func (export "size") (result i32) (memory.size))) From 0c6280f78256d4185a5bb44c5aa15d97b815e1f5 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Wed, 11 Nov 2026 17:48:45 +0000 Subject: [PATCH 2/2] Be conservative. --- fncompiler.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/fncompiler.go b/fncompiler.go index 7bf21538..799d8192 100644 --- a/fncompiler.go +++ b/fncompiler.go @@ -623,31 +623,23 @@ func (fn *funcCompiler) cleanup() { // Switch from LoadOnRead to LoadOnWrite before RemoveReceiver, // since loading m.memory into mem uses m. if fn.memory != nil && !fn.memory.shared { - if passes.SelectMemoryMode(fn.decl, fn.memory.selector, fn.mayGrowMemory) == passes.LoadOnWrite { - passes.LoadMemoryOnWrite(fn.decl, fn.memory.selector, newID("mem"), fn.mayGrowMemory) + if passes.SelectMemoryMode(fn.decl, fn.memory.selector, mayGrowMemory) == passes.LoadOnWrite { + passes.LoadMemoryOnWrite(fn.decl, fn.memory.selector, newID("mem"), mayGrowMemory) } } } // Reports whether ce may grow linear memory. -func (fn *funcCompiler) mayGrowMemory(ce *ast.CallExpr) bool { +func mayGrowMemory(ce *ast.CallExpr) bool { switch f := ce.Fun.(type) { - case *ast.ParenExpr: - // Module, provided, or imported function call: (m.fnN)(...) - // Receiverless (fnN)(...) calls cannot access m or grow memory. - _, ok := f.X.(*ast.SelectorExpr) - return ok - case *ast.TypeAssertExpr: - // Indirect table call: m.t0[i].(func(...))(...) - return true case *ast.Ident: - return f.Name == "memory_grow" + return f.Name == "memory_grow" || f.Name == "atomic_memory_grow" case *ast.SelectorExpr: - // Imported memory.grow: m.memImp.Grow(...) - _, ok := f.X.(*ast.SelectorExpr) - return ok && f.Sel.Name == "Grow" + id, ok := f.X.(*ast.Ident) + return !ok || stdlib[id.Name] == "" + default: + return true } - return false } type funcBlock struct {