Make CompileModule actually compile (#469)
This commit makes it possible for functions to be compiled before instantiation. Notably, this adds CompileModule method on Engine interface where we pass wasm.Module (which is the decoded module) to engines, and engines compile all the module functions and caches them keyed on *wasm.Module. In order to achieve that, this stops the compiled native code from embedding typeID which is assigned for all the function types in a store. Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
22
builder.go
22
builder.go
@@ -247,17 +247,18 @@ func (b *moduleBuilder) Build() (*CompiledCode, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if module, err := wasm.NewHostModule(
|
||||
b.moduleName,
|
||||
b.nameToGoFunc,
|
||||
b.nameToMemory,
|
||||
b.nameToGlobal,
|
||||
b.r.enabledFeatures,
|
||||
); err != nil {
|
||||
module, err := wasm.NewHostModule(b.moduleName, b.nameToGoFunc, b.nameToMemory, b.nameToGlobal, b.r.enabledFeatures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &CompiledCode{module: module}, nil
|
||||
}
|
||||
|
||||
if err = b.r.store.Engine.CompileModule(module); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := &CompiledCode{module: module}
|
||||
ret.addCacheEntry(module, b.r.store.Engine)
|
||||
return &CompiledCode{module: module}, nil
|
||||
}
|
||||
|
||||
// Instantiate implements ModuleBuilder.Instantiate
|
||||
@@ -265,6 +266,9 @@ func (b *moduleBuilder) Instantiate() (api.Module, error) {
|
||||
if module, err := b.Build(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if err = b.r.store.Engine.CompileModule(module.module); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// *wasm.ModuleInstance cannot be tracked, so we release the cache inside of this function.
|
||||
defer module.Close()
|
||||
return b.r.InstantiateModuleWithConfig(module, NewModuleConfig().WithName(b.moduleName))
|
||||
|
||||
Reference in New Issue
Block a user