Skip to content

Commit

Permalink
Removes unnecessary Engine.CreateElementInstance (#1134)
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake committed Feb 17, 2023
1 parent b7a7570 commit add6458
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 38 deletions.
14 changes: 0 additions & 14 deletions internal/engine/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,20 +588,6 @@ func (e *moduleEngine) FunctionInstanceReference(funcIndex wasm.Index) wasm.Refe
return uintptr(unsafe.Pointer(&e.functions[funcIndex]))
}

// CreateFuncElementInstance implements the same method as documented on wasm.ModuleEngine.
func (e *moduleEngine) CreateFuncElementInstance(indexes []*wasm.Index) *wasm.ElementInstance {
refs := make([]wasm.Reference, len(indexes))
for i, index := range indexes {
if index != nil {
refs[i] = uintptr(unsafe.Pointer(&e.functions[*index]))
}
}
return &wasm.ElementInstance{
References: refs,
Type: wasm.RefTypeFuncref,
}
}

func (e *moduleEngine) NewCallEngine(_ *wasm.CallContext, f *wasm.FunctionInstance) (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.
Expand Down
14 changes: 0 additions & 14 deletions internal/engine/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,20 +737,6 @@ func (e *moduleEngine) Name() string {
return e.name
}

// CreateFuncElementInstance implements the same method as documented on wasm.ModuleEngine.
func (e *moduleEngine) CreateFuncElementInstance(indexes []*wasm.Index) *wasm.ElementInstance {
refs := make([]wasm.Reference, len(indexes))
for i, index := range indexes {
if index != nil {
refs[i] = uintptr(unsafe.Pointer(&e.functions[*index]))
}
}
return &wasm.ElementInstance{
References: refs,
Type: wasm.RefTypeFuncref,
}
}

// 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]))
Expand Down
4 changes: 0 additions & 4 deletions internal/wasm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ type ModuleEngine interface {
// LookupFunction returns the index of the function in the function table.
LookupFunction(t *TableInstance, typeId FunctionTypeID, tableOffset Index) (Index, error)

// CreateFuncElementInstance creates an ElementInstance whose references are engine-specific function pointers
// corresponding to the given `indexes`.
CreateFuncElementInstance(indexes []*Index) *ElementInstance

// FunctionInstanceReference returns Reference for the given Index for a FunctionInstance. The returned values are used by
// the initialization via ElementSegment.
FunctionInstanceReference(funcIndex Index) Reference
Expand Down
11 changes: 10 additions & 1 deletion internal/wasm/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@ func (m *ModuleInstance) buildElementInstances(elements []*ElementSegment) {
if elm.Type == RefTypeFuncref && elm.Mode == ElementModePassive {
// Only passive elements can be access as element instances.
// See https://www.w3.org/TR/2022/WD-wasm-core-2-20220419/syntax/modules.html#element-segments
m.ElementInstances[i] = *m.Engine.CreateFuncElementInstance(elm.Init)
inits := elm.Init
elemInst := &m.ElementInstances[i]
elemInst.References = make([]Reference, len(inits))
elemInst.Type = RefTypeFuncref
for j, idxPtr := range inits {
if idxPtr != nil {
idx := *idxPtr
elemInst.References[j] = m.Engine.FunctionInstanceReference(idx)
}
}
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions internal/wasm/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,6 @@ func (e *mockModuleEngine) NewCallEngine(callCtx *CallContext, f *FunctionInstan
return &mockCallEngine{f: f, callFailIndex: e.callFailIndex}, nil
}

// CreateFuncElementInstance implements the same method as documented on wasm.ModuleEngine.
func (e *mockModuleEngine) CreateFuncElementInstance([]*Index) *ElementInstance {
return nil
}

// InitializeFuncrefGlobals implements the same method as documented on wasm.ModuleEngine.
func (e *mockModuleEngine) InitializeFuncrefGlobals(globals []*GlobalInstance) {}

Expand Down

0 comments on commit add6458

Please sign in to comment.