Refactors store and adds ReleaseModuleInstance (#294)

This commit refactors store.go and adds store.ReleaseModuleInstance.
Notably, this removes the "rollback" functions in InstantiateModule
which we had used to rollback the mutated state when we encounter
the initialization failure. Instead, we separate out the validation from
initialization and migrate most of the validation logics into module.go

As for ReleaseModuleInstance, that is necessary to complete #293,
will be leveraged to make it possible for store to be used for long-running
processes and environment.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2022-03-01 11:45:59 +09:00
committed by GitHub
parent d37ac9e5ff
commit 31a69e8538
18 changed files with 2160 additions and 1024 deletions

14
wasm.go
View File

@@ -74,8 +74,14 @@ type ModuleConfig struct {
//
// This is used to pre-flight check and cache the module for later instantiation.
func (m *ModuleConfig) Validate() (err error) {
_, err = decodeModule(m)
return err
mod, err := decodeModule(m)
if err != nil {
return
}
// TODO: decoders should validate before returning, as that allows
// them to err with the correct source position.
err = mod.Validate()
return
}
// WithName returns a new instance which overrides the Name, but keeps any internal cache made by Validate.
@@ -103,6 +109,10 @@ func InstantiateModule(store wasm.Store, module *ModuleConfig) (wasm.ModuleExpor
if err != nil {
return nil, err
}
if err = m.Validate(); err != nil {
return nil, err
}
return internal.Instantiate(m, getModuleName(module.Name, m))
}