Repository: tetratelabs/wazero
Pull request #1291 (2023-03-27 00:23:54)

Refactors NewModuleEngine and NewCallEngine
This drops the unnecessary parameters from `NewModuleEngine` and `NewCallEngine` 
interface methods.


Patch:
diff --git a/internal/engine/compiler/engine.go b/internal/engine/compiler/engine.go
index d21db5c8..8d7ac900 100644
--- a/internal/engine/compiler/engine.go
+++ b/internal/engine/compiler/engine.go
@@ -41,9 +41,6 @@ type (
 	moduleEngine struct {
 		// See note at top of file before modifying this struct.
 
-		// name is the name the module was instantiated with used for error handling.
-		name string
-
 		// functions are the functions in a module instances.
 		// The index is module instance-scoped. We intentionally avoid using map
 		// as the underlying memory region is accessed by assembly directly by using
@@ -309,7 +306,7 @@ type (
 // See TestVerifyOffsetValue for how to derive these values.
 const (
 	// Offsets for moduleEngine.functions
-	moduleEngineFunctionsOffset = 16
+	moduleEngineFunctionsOffset = 0
 
 	// Offsets for callEngine moduleContext.
 	callEngineModuleContextFnOffset                              = 0
@@ -550,9 +547,8 @@ func (e *engine) CompileModule(_ context.Context, module *wasm.Module, listeners
 }
 
 // NewModuleEngine implements the same method as documented on wasm.Engine.
-func (e *engine) NewModuleEngine(name string, module *wasm.Module, functions []wasm.FunctionInstance) (wasm.ModuleEngine, error) {
+func (e *engine) NewModuleEngine(module *wasm.Module, functions []wasm.FunctionInstance) (wasm.ModuleEngine, error) {
 	me := &moduleEngine{
-		name:      name,
 		functions: make([]function, len(functions)),
 	}
 
@@ -564,7 +560,7 @@ func (e *engine) NewModuleEngine(name string, module *wasm.Module, functions []w
 
 	codes, ok, err := e.getCodes(module)
 	if !ok {
-		return nil, fmt.Errorf("source module for %s must be compiled before instantiation", name)
+		return nil, errors.New("source module must be compiled before instantiation")
 	} else if err != nil {
 		return nil, err
 	}
@@ -582,20 +578,15 @@ func (e *engine) NewModuleEngine(name string, module *wasm.Module, functions []w
 	return me, nil
 }
 
-// Name implements the same method as documented on wasm.ModuleEngine.
-func (e *moduleEngine) Name() string {
-	return e.name
-}
-
 // FunctionInstanceReference implements the same method as documented on wasm.ModuleEngine.
 func (e *moduleEngine) FunctionInstanceReference(funcIndex wasm.Index) wasm.Reference {
 	return uintptr(unsafe.Pointer(&e.functions[funcIndex]))
 }
 
-func (e *moduleEngine) NewCallEngine(_ *wasm.ModuleInstance, f *wasm.FunctionInstance) (ce wasm.CallEngine, err error) {
+func (e *moduleEngine) NewCallEngine(index wasm.Index) (ce wasm.CallEngine, err error) {
 	// Note: The input parameters are pre-validated, so a compiled function is only absent on close. Updates to
 	// code on close aren't locked, neither is this read.
-	compiled := &e.functions[f.Definition.Index()]
+	compiled := &e.functions[index]
 
 	initStackSize := initialStackSize
 	if initialStackSize < compiled.parent.stackPointerCeil {
diff --git a/internal/engine/interpreter/interpreter.go b/internal/engine/interpreter/interpreter.go
index 2eb8a2c1..3148f529 100644
--- a/internal/engine/interpreter/interpreter.go
+++ b/internal/engine/interpreter/interpreter.go
@@ -3,6 +3,7 @@ package interpreter
 import (
 	"context"
 	"encoding/binary"
+	"errors"
 	"fmt"
 	"math"
 	"math/bits"
@@ -98,12 +99,10 @@ type callEngine struct {
 
 	// compiled is the initial function for this call engine.
 	compiled *function
-	// source is the FunctionInstance from which compiled is created from.
-	source *wasm.FunctionInstance
 }
 
-func (e *moduleEngine) newCallEngine(source *wasm.FunctionInstance, compiled *function) *callEngine {
-	return &callEngine{source: source, compiled: compiled}
+func (e *moduleEngine) newCallEngine(compiled *function) *callEngine {
+	return &callEngine{compiled: compiled}
 }
 
 func (ce *callEngine) pushValue(v uint64) {
@@ -258,9 +257,8 @@ func (e *engine) CompileModule(ctx context.Context, module *wasm.Module, listene
 }
 
 // NewModuleEngine implements the same method as documented on wasm.Engine.
-func (e *engine) NewModuleEngine(name string, module *wasm.Module, functions []wasm.FunctionInstance) (wasm.ModuleEngine, error) {
+func (e *engine) NewModuleEngine(module *wasm.Module, functions []wasm.FunctionInstance) (wasm.ModuleEngine, error) {
 	me := &moduleEngine{
-		name:         name,
 		parentEngine: e,
 		functions:    make([]function, len(functions)),
 	}
@@ -273,7 +271,7 @@ func (e *engine) NewModuleEngine(name string, module *wasm.Module, functions []w
 
 	codes, ok := e.getCodes(module)
 	if !ok {
-		return nil, fmt.Errorf("source module for %s must be compiled before instantiation", name)
+		return nil, errors.New("source module must be compiled before instantiation")
 	}
 
 	for i, c := range codes {
@@ -740,11 +738,11 @@ func (e *moduleEngine) FunctionInstanceReference(funcIndex wasm.Index) wasm.Refe
 }
 
 // NewCallEngine implements the same method as documented on wasm.ModuleEngine.
-func (e *moduleEngine) NewCallEngine(_ *wasm.ModuleInstance, f *wasm.FunctionInstance) (ce wasm.CallEngine, err error) {
+func (e *moduleEngine) NewCallEngine(index wasm.Index) (ce wasm.CallEngine, err error) {
 	// Note: The input parameters are pre-validated, so a compiled function is only absent on close. Updates to
 	// code on close aren't locked, neither is this read.
-	compiled := &e.functions[f.Definition.Index()]
-	return e.newCallEngine(f, compiled), nil
+	compiled := &e.functions[index]
+	return e.newCallEngine(compiled), nil
 }
 
 // LookupFunction implements the same method as documented on wasm.ModuleEngine.
diff --git a/internal/wasm/engine.go b/internal/wasm/engine.go
index a34858af..666cf540 100644
--- a/internal/wasm/engine.go
+++ b/internal/wasm/engine.go
@@ -25,22 +25,18 @@ type Engine interface {
 
 	// NewModuleEngine compiles down the function instances in a module, and returns ModuleEngine for the module.
 	//
-	// * name is the name the module was instantiated with used for error handling.
 	// * module is the source module from which moduleFunctions are instantiated. This is used for caching.
 	// * functions: the list of FunctionInstance which exists in this module, including the imported ones.
 	//
 	// Note: Input parameters must be pre-validated with wasm.Module Validate, to ensure no fields are invalid
 	// due to reasons such as out-of-bounds.
-	NewModuleEngine(name string, module *Module, functions []FunctionInstance) (ModuleEngine, error)
+	NewModuleEngine(module *Module, functions []FunctionInstance) (ModuleEngine, error)
 }
 
 // ModuleEngine implements function calls for a given module.
 type ModuleEngine interface {
-	// Name returns the name of the module this engine was compiled for.
-	Name() string
-
 	// NewCallEngine returns a CallEngine for the given FunctionInstance.
-	NewCallEngine(m *ModuleInstance, f *FunctionInstance) (CallEngine, error)
+	NewCallEngine(index Index) (CallEngine, error)
 
 	// LookupFunction returns the index of the function in the function table.
 	LookupFunction(t *TableInstance, typeId FunctionTypeID, tableOffset Index) (Index, error)
diff --git a/internal/wasm/module_instance.go b/internal/wasm/module_instance.go
index ee68d2d1..9d40cca0 100644
--- a/internal/wasm/module_instance.go
+++ b/internal/wasm/module_instance.go
@@ -160,7 +160,7 @@ func (m *ModuleInstance) ExportedFunction(name string) api.Function {
 		return nil
 	}
 
-	return m.function(&m.Functions[exp.Index])
+	return m.function(exp.Index)
 }
 
 // ExportedFunctionDefinitions implements the same method as documented on
@@ -179,32 +179,33 @@ func (m *ModuleInstance) Function(funcIdx Index) api.Function {
 	if uint32(len(m.Functions)) < funcIdx {
 		return nil
 	}
-	return m.function(&m.Functions[funcIdx])
+	return m.function(funcIdx)
 }
 
-func (m *ModuleInstance) function(f *FunctionInstance) api.Function {
-	ce, err := f.Module.Engine.NewCallEngine(m, f)
+func (m *ModuleInstance) function(index Index) api.Function {
+	ce, err := m.Engine.NewCallEngine(index)
 	if err != nil {
 		return nil
 	}
-	return &function{fi: f, ce: ce}
+	return &function{index: index, ce: ce, m: m}
 }
 
 // function implements api.Function. This couples FunctionInstance with CallEngine so that
 // it can be used to make function calls originating from the FunctionInstance.
 type function struct {
-	fi *FunctionInstance
-	ce CallEngine
+	index Index
+	m     *ModuleInstance
+	ce    CallEngine
 }
 
 // Definition implements the same method as documented on api.FunctionDefinition.
 func (f *function) Definition() api.FunctionDefinition {
-	return f.fi.Definition
+	return &f.m.definitions[f.index]
 }
 
 // Call implements the same method as documented on api.Function.
 func (f *function) Call(ctx context.Context, params ...uint64) (ret []uint64, err error) {
-	return f.ce.Call(ctx, f.fi.Module, params)
+	return f.ce.Call(ctx, f.m, params)
 }
 
 // GlobalVal is an internal hack to get the lower 64 bits of a global.
diff --git a/internal/wasm/store.go b/internal/wasm/store.go
index 2ca03ce3..81012fb3 100644
--- a/internal/wasm/store.go
+++ b/internal/wasm/store.go
@@ -106,7 +106,10 @@ type (
 		// CodeCloser is non-nil when the code should be closed after this module.
 		CodeCloser api.Closer
 
+		// s is the Store on which this module is instantiated.
 		s *Store
+		// definitions is derived from *Module, and is constructed during compilation phrase.
+		definitions []FunctionDefinition
 	}
 
 	// DataInstance holds bytes corresponding to the data segment in a module.
@@ -337,7 +340,7 @@ func (s *Store) instantiate(
 	modules map[string]*ModuleInstance,
 	typeIDs []FunctionTypeID,
 ) (*ModuleInstance, error) {
-	m := &ModuleInstance{ModuleName: name, TypeIDs: typeIDs, Sys: sysCtx, s: s}
+	m := &ModuleInstance{ModuleName: name, TypeIDs: typeIDs, Sys: sysCtx, s: s, definitions: module.FunctionDefinitionSection}
 
 	m.Functions = make([]FunctionInstance, int(module.ImportFunctionCount)+len(module.FunctionSection))
 	m.Tables = make([]*TableInstance, int(module.ImportTableCount)+len(module.TableSection))
@@ -357,7 +360,7 @@ func (s *Store) instantiate(
 	m.BuildFunctions(module)
 
 	// Plus, we are ready to compile functions.
-	m.Engine, err = s.Engine.NewModuleEngine(name, module, m.Functions)
+	m.Engine, err = s.Engine.NewModuleEngine(module, m.Functions)
 	if err != nil {
 		return nil, err
 	}
@@ -388,9 +391,7 @@ func (s *Store) instantiate(
 	// Execute the start function.
 	if module.StartSection != nil {
 		funcIdx := *module.StartSection
-		f := &m.Functions[funcIdx]
-
-		ce, err := f.Module.Engine.NewCallEngine(m, f)
+		ce, err := m.Engine.NewCallEngine(funcIdx)
 		if err != nil {
 			return nil, fmt.Errorf("create call engine for start function[%s]: %v",
 				module.funcDesc(SectionIDFunction, funcIdx), err)


Test patch:
diff --git a/internal/engine/interpreter/interpreter_test.go b/internal/engine/interpreter/interpreter_test.go
index 6ed14805..c811b31f 100644
--- a/internal/engine/interpreter/interpreter_test.go
+++ b/internal/engine/interpreter/interpreter_test.go
@@ -498,11 +498,11 @@ func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) {
 func TestInterpreter_Compile(t *testing.T) {
 	t.Run("uncompiled", func(t *testing.T) {
 		e := et.NewEngine(api.CoreFeaturesV1).(*engine)
-		_, err := e.NewModuleEngine("foo",
+		_, err := e.NewModuleEngine(
 			&wasm.Module{},
 			nil, // functions
 		)
-		require.EqualError(t, err, "source module for foo must be compiled before instantiation")
+		require.EqualError(t, err, "source module must be compiled before instantiation")
 	})
 	t.Run("fail", func(t *testing.T) {
 		e := et.NewEngine(api.CoreFeaturesV1).(*engine)
diff --git a/internal/integration_test/bench/hostfunc_bench_test.go b/internal/integration_test/bench/hostfunc_bench_test.go
index 04c9e43e..3ec73359 100644
--- a/internal/integration_test/bench/hostfunc_bench_test.go
+++ b/internal/integration_test/bench/hostfunc_bench_test.go
@@ -4,7 +4,6 @@ import (
 	"context"
 	_ "embed"
 	"encoding/binary"
-	"fmt"
 	"math"
 	"testing"
 
@@ -115,13 +114,7 @@ func TestBenchmarkFunctionCall(t *testing.T) {
 
 func getCallEngine(m *wasm.ModuleInstance, name string) (ce wasm.CallEngine, err error) {
 	exp := m.Exports[name]
-	f := &m.Functions[exp.Index]
-	if f == nil {
-		err = fmt.Errorf("%s not found", name)
-		return
-	}
-
-	ce, err = m.Engine.NewCallEngine(m, f)
+	ce, err = m.Engine.NewCallEngine(exp.Index)
 	return
 }
 
@@ -182,7 +175,7 @@ func setupHostCallBench(requireNoError func(error)) *wasm.ModuleInstance {
 	err := eng.CompileModule(testCtx, hostModule, nil, false)
 	requireNoError(err)
 
-	hostME, err := eng.NewModuleEngine(host.ModuleName, hostModule, host.Functions)
+	hostME, err := eng.NewModuleEngine(hostModule, host.Functions)
 	requireNoError(err)
 	linkModuleToEngine(host, hostME)
 
@@ -224,7 +217,7 @@ func setupHostCallBench(requireNoError func(error)) *wasm.ModuleInstance {
 	importing.BuildFunctions(importingModule)
 	importing.Exports = importingModule.Exports
 
-	importingMe, err := eng.NewModuleEngine(importing.ModuleName, importingModule, importing.Functions)
+	importingMe, err := eng.NewModuleEngine(importingModule, importing.Functions)
 	requireNoError(err)
 	linkModuleToEngine(importing, importingMe)
 
diff --git a/internal/testing/enginetest/enginetest.go b/internal/testing/enginetest/enginetest.go
index 09dac228..3eb0d0dc 100644
--- a/internal/testing/enginetest/enginetest.go
+++ b/internal/testing/enginetest/enginetest.go
@@ -125,17 +125,8 @@ func RunTestEngine_NewModuleEngine(t *testing.T, et EngineTester) {
 	e := et.NewEngine(api.CoreFeaturesV1)
 
 	t.Run("error before instantiation", func(t *testing.T) {
-		_, err := e.NewModuleEngine("mymod", &wasm.Module{}, nil)
-		require.EqualError(t, err, "source module for mymod must be compiled before instantiation")
-	})
-
-	t.Run("sets module name", func(t *testing.T) {
-		m := &wasm.Module{}
-		err := e.CompileModule(testCtx, m, nil, false)
-		require.NoError(t, err)
-		me, err := e.NewModuleEngine(t.Name(), m, nil)
-		require.NoError(t, err)
-		require.Equal(t, t.Name(), me.Name())
+		_, err := e.NewModuleEngine(&wasm.Module{}, nil)
+		require.EqualError(t, err, "source module must be compiled before instantiation")
 	})
 }
 
@@ -172,14 +163,14 @@ func RunTestModuleEngine_Call(t *testing.T, et EngineTester) {
 	module.BuildFunctions(m)
 
 	// Compile the module
-	me, err := e.NewModuleEngine(module.ModuleName, m, module.Functions)
+	me, err := e.NewModuleEngine(m, module.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(module, me)
 
 	// Ensure the base case doesn't fail: A single parameter should work as that matches the function signature.
 	fn := &module.Functions[0]
 
-	ce, err := me.NewCallEngine(module, fn)
+	ce, err := me.NewCallEngine(fn.Definition.Index())
 	require.NoError(t, err)
 
 	results, err := ce.Call(testCtx, module, []uint64{1, 2})
@@ -187,7 +178,7 @@ func RunTestModuleEngine_Call(t *testing.T, et EngineTester) {
 	require.Equal(t, []uint64{1, 2}, results)
 
 	t.Run("errs when not enough parameters", func(t *testing.T) {
-		ce, err := me.NewCallEngine(module, fn)
+		ce, err := me.NewCallEngine(fn.Definition.Index())
 		require.NoError(t, err)
 
 		_, err = ce.Call(testCtx, module, nil)
@@ -195,7 +186,7 @@ func RunTestModuleEngine_Call(t *testing.T, et EngineTester) {
 	})
 
 	t.Run("errs when too many parameters", func(t *testing.T) {
-		ce, err := me.NewCallEngine(module, fn)
+		ce, err := me.NewCallEngine(fn.Definition.Index())
 		require.NoError(t, err)
 
 		_, err = ce.Call(testCtx, module, []uint64{1, 2, 3})
@@ -230,7 +221,7 @@ func RunTestModuleEngine_LookupFunction(t *testing.T, et EngineTester) {
 	}
 	m.BuildFunctions(mod)
 
-	me, err := e.NewModuleEngine(m.ModuleName, mod, m.Functions)
+	me, err := e.NewModuleEngine(mod, m.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(m, me)
 
@@ -305,7 +296,7 @@ func runTestModuleEngine_Call_HostFn_Mem(t *testing.T, et EngineTester, readMem
 		tc := tt
 
 		t.Run(tc.name, func(t *testing.T) {
-			ce, err := tc.fn.Module.Engine.NewCallEngine(tc.fn.Module, tc.fn)
+			ce, err := tc.fn.Module.Engine.NewCallEngine(tc.fn.Definition.Index())
 			require.NoError(t, err)
 
 			results, err := ce.Call(testCtx, importing, nil)
@@ -360,7 +351,7 @@ func runTestModuleEngine_Call_HostFn(t *testing.T, et EngineTester, hostDivBy *w
 			m := tc.module
 			f := tc.fn
 
-			ce, err := f.Module.Engine.NewCallEngine(m, f)
+			ce, err := f.Module.Engine.NewCallEngine(f.Definition.Index())
 			require.NoError(t, err)
 
 			results, err := ce.Call(testCtx, m, []uint64{1})
@@ -464,7 +455,7 @@ wasm stack trace:
 			m := tc.module
 			f := tc.fn
 
-			ce, err := f.Module.Engine.NewCallEngine(m, f)
+			ce, err := f.Module.Engine.NewCallEngine(f.Definition.Index())
 			require.NoError(t, err)
 
 			_, err = ce.Call(testCtx, m, tc.input)
@@ -546,7 +537,7 @@ func RunTestModuleEngine_Memory(t *testing.T, et EngineTester) {
 	grow, init := &module.Functions[0], &module.Functions[1]
 
 	// Compile the module
-	me, err := e.NewModuleEngine(module.ModuleName, m, module.Functions)
+	me, err := e.NewModuleEngine(m, module.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(module, me)
 
@@ -555,7 +546,7 @@ func RunTestModuleEngine_Memory(t *testing.T, et EngineTester) {
 	require.Equal(t, make([]byte, wasmPhraseSize), buf)
 
 	// Initialize the memory using Wasm. This copies the test phrase.
-	initCallEngine, err := me.NewCallEngine(module, init)
+	initCallEngine, err := me.NewCallEngine(init.Definition.Index())
 	require.NoError(t, err)
 	_, err = initCallEngine.Call(testCtx, module, nil)
 	require.NoError(t, err)
@@ -587,7 +578,7 @@ func RunTestModuleEngine_Memory(t *testing.T, et EngineTester) {
 	require.Equal(t, hostPhraseTruncated, string(buf2))
 
 	// Now, we need to prove the other direction, that when Wasm changes the capacity, the host's buffer is unaffected.
-	growCallEngine, err := me.NewCallEngine(module, grow)
+	growCallEngine, err := me.NewCallEngine(grow.Definition.Index())
 	require.NoError(t, err)
 	_, err = growCallEngine.Call(testCtx, module, []uint64{1})
 	require.NoError(t, err)
@@ -596,7 +587,7 @@ func RunTestModuleEngine_Memory(t *testing.T, et EngineTester) {
 	require.Equal(t, hostPhraseTruncated, string(buf2))
 
 	// Re-initialize the memory in wasm, which overwrites the region.
-	initCallEngine2, err := me.NewCallEngine(module, init)
+	initCallEngine2, err := me.NewCallEngine(init.Definition.Index())
 	require.NoError(t, err)
 	_, err = initCallEngine2.Call(testCtx, module, nil)
 	require.NoError(t, err)
@@ -672,7 +663,7 @@ func setupCallTests(t *testing.T, e wasm.Engine, divBy *wasm.Code, fnlf experime
 	host.Exports = exportMap(hostModule)
 	hostFn := &host.Functions[host.Exports[divByGoName].Index]
 
-	hostME, err := e.NewModuleEngine(host.ModuleName, hostModule, host.Functions)
+	hostME, err := e.NewModuleEngine(hostModule, host.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(host, hostME)
 
@@ -713,7 +704,7 @@ func setupCallTests(t *testing.T, e wasm.Engine, divBy *wasm.Code, fnlf experime
 	callHostFn := &imported.Functions[imported.Exports[callDivByGoName].Index]
 
 	// Compile the imported module
-	importedMe, err := e.NewModuleEngine(imported.ModuleName, importedModule, imported.Functions)
+	importedMe, err := e.NewModuleEngine(importedModule, imported.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(imported, importedMe)
 
@@ -749,7 +740,7 @@ func setupCallTests(t *testing.T, e wasm.Engine, divBy *wasm.Code, fnlf experime
 	importing.Exports = exportMap(importingModule)
 
 	// Compile the importing module
-	importingMe, err := e.NewModuleEngine(importing.ModuleName, importingModule, importing.Functions)
+	importingMe, err := e.NewModuleEngine(importingModule, importing.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(importing, importingMe)
 
@@ -787,7 +778,7 @@ func setupCallMemTests(t *testing.T, e wasm.Engine, readMem *wasm.Code, fnlf exp
 	host.Exports = exportMap(hostModule)
 	readMemFn := &host.Functions[host.Exports[readMemName].Index]
 
-	hostME, err := e.NewModuleEngine(host.ModuleName, hostModule, host.Functions)
+	hostME, err := e.NewModuleEngine(hostModule, host.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(host, hostME)
 
@@ -829,7 +820,7 @@ func setupCallMemTests(t *testing.T, e wasm.Engine, readMem *wasm.Code, fnlf exp
 	importing.Exports = exportMap(importingModule)
 
 	// Compile the importing module
-	importingMe, err := e.NewModuleEngine(importing.ModuleName, importingModule, importing.Functions)
+	importingMe, err := e.NewModuleEngine(importingModule, importing.Functions)
 	require.NoError(t, err)
 	linkModuleToEngine(importing, importingMe)
 
diff --git a/internal/wasm/store_test.go b/internal/wasm/store_test.go
index 6424e062..996b9f9e 100644
--- a/internal/wasm/store_test.go
+++ b/internal/wasm/store_test.go
@@ -403,7 +403,7 @@ type mockModuleEngine struct {
 }
 
 type mockCallEngine struct {
-	f             *FunctionInstance
+	index         Index
 	callFailIndex int
 }
 
@@ -433,7 +433,7 @@ func (e *mockEngine) CompiledModuleCount() uint32 { return 0 }
 func (e *mockEngine) DeleteCompiledModule(*Module) {}
 
 // NewModuleEngine implements the same method as documented on wasm.Engine.
-func (e *mockEngine) NewModuleEngine(_ string, _ *Module, _ []FunctionInstance) (ModuleEngine, error) {
+func (e *mockEngine) NewModuleEngine(_ *Module, _ []FunctionInstance) (ModuleEngine, error) {
 	if e.shouldCompileFail {
 		return nil, fmt.Errorf("some engine creation error")
 	}
@@ -446,8 +446,8 @@ func (e *mockModuleEngine) FunctionInstanceReference(i Index) Reference {
 }
 
 // NewCallEngine implements the same method as documented on wasm.ModuleEngine.
-func (e *mockModuleEngine) NewCallEngine(_ *ModuleInstance, f *FunctionInstance) (CallEngine, error) {
-	return &mockCallEngine{f: f, callFailIndex: e.callFailIndex}, nil
+func (e *mockModuleEngine) NewCallEngine(index Index) (CallEngine, error) {
+	return &mockCallEngine{index: index, callFailIndex: e.callFailIndex}, nil
 }
 
 // InitializeFuncrefGlobals implements the same method as documented on wasm.ModuleEngine.
@@ -464,7 +464,7 @@ func (e *mockModuleEngine) Close(context.Context) {
 
 // Call implements the same method as documented on wasm.ModuleEngine.
 func (ce *mockCallEngine) Call(_ context.Context, _ *ModuleInstance, _ []uint64) (results []uint64, err error) {
-	if ce.callFailIndex >= 0 && ce.f.Definition.Index() == Index(ce.callFailIndex) {
+	if ce.callFailIndex >= 0 && ce.index == Index(ce.callFailIndex) {
 		err = errors.New("call failed")
 		return
 	}
@@ -903,7 +903,7 @@ func TestModuleInstance_applyTableInits(t *testing.T) {
 	})
 	t.Run("funcref", func(t *testing.T) {
 		e := &mockEngine{}
-		me, err := e.NewModuleEngine("", nil, nil)
+		me, err := e.NewModuleEngine(nil, nil)
 		me.(*mockModuleEngine).functionRefs = map[Index]Reference{0: 0xa, 1: 0xaa, 2: 0xaaa, 3: 0xaaaa}
 		require.NoError(t, err)
 		m := &ModuleInstance{Engine: me}
diff --git a/runtime_test.go b/runtime_test.go
index a7158d8c..4fd5a989 100644
--- a/runtime_test.go
+++ b/runtime_test.go
@@ -796,7 +796,7 @@ func (e *mockEngine) DeleteCompiledModule(module *wasm.Module) {
 }
 
 // NewModuleEngine implements the same method as documented on wasm.Engine.
-func (e *mockEngine) NewModuleEngine(_ string, _ *wasm.Module, _ []wasm.FunctionInstance) (wasm.ModuleEngine, error) {
+func (e *mockEngine) NewModuleEngine(_ *wasm.Module, _ []wasm.FunctionInstance) (wasm.ModuleEngine, error) {
 	return nil, nil
 }