Removes context parameter from instruction-scoped operations (#923)
We originally had a `context.Context` for anything that might be traced, but it turned out to be only useful for lifecycle and host functions. For instruction-scoped aspects like memory updates, a context parameter is too fine-grained and also invisible in practice. For example, most users will use the compiler engine, and its memory, global or table access will never use go's context. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
48
api/wasm.go
48
api/wasm.go
@@ -350,7 +350,7 @@ type GoModuleFunction interface {
|
||||
// api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
|
||||
// offset := api.DecodeU32(stack[0]) // read the parameter from the stack
|
||||
//
|
||||
// ret, ok := mod.Memory().ReadUint32Le(ctx, offset)
|
||||
// ret, ok := mod.Memory().ReadUint32Le(offset)
|
||||
// if !ok {
|
||||
// panic("out of memory")
|
||||
// }
|
||||
@@ -413,8 +413,8 @@ type Global interface {
|
||||
|
||||
// Get returns the last known value of this global.
|
||||
//
|
||||
// See Type for how to encode this value from a Go type.
|
||||
Get(context.Context) uint64
|
||||
// See Type for how to decode this value to a Go type.
|
||||
Get() uint64
|
||||
}
|
||||
|
||||
// MutableGlobal is a Global whose value can be updated at runtime (variable).
|
||||
@@ -423,8 +423,8 @@ type MutableGlobal interface {
|
||||
|
||||
// Set updates the value of this global.
|
||||
//
|
||||
// See Global.Type for how to decode this value to a Go type.
|
||||
Set(ctx context.Context, v uint64)
|
||||
// See Global.Type for how to encode this value from a Go type.
|
||||
Set(v uint64)
|
||||
}
|
||||
|
||||
// Memory allows restricted access to a module's memory. Notably, this does not allow growing.
|
||||
@@ -443,7 +443,7 @@ type Memory interface {
|
||||
// has 1 page: 65536
|
||||
//
|
||||
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#-hrefsyntax-instr-memorymathsfmemorysize%E2%91%A0
|
||||
Size(context.Context) uint32
|
||||
Size() uint32
|
||||
|
||||
// Grow increases memory by the delta in pages (65536 bytes per page).
|
||||
// The return val is the previous memory size in pages, or false if the
|
||||
@@ -456,39 +456,39 @@ type Memory interface {
|
||||
// - When this returns true, any shared views via Read must be refreshed.
|
||||
//
|
||||
// See MemorySizer Read and https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#grow-mem
|
||||
Grow(ctx context.Context, deltaPages uint32) (previousPages uint32, ok bool)
|
||||
Grow(deltaPages uint32) (previousPages uint32, ok bool)
|
||||
|
||||
// ReadByte reads a single byte from the underlying buffer at the offset or returns false if out of range.
|
||||
ReadByte(ctx context.Context, offset uint32) (byte, bool)
|
||||
ReadByte(offset uint32) (byte, bool)
|
||||
|
||||
// ReadUint16Le reads a uint16 in little-endian encoding from the underlying buffer at the offset in or returns
|
||||
// false if out of range.
|
||||
ReadUint16Le(ctx context.Context, offset uint32) (uint16, bool)
|
||||
ReadUint16Le(offset uint32) (uint16, bool)
|
||||
|
||||
// ReadUint32Le reads a uint32 in little-endian encoding from the underlying buffer at the offset in or returns
|
||||
// false if out of range.
|
||||
ReadUint32Le(ctx context.Context, offset uint32) (uint32, bool)
|
||||
ReadUint32Le(offset uint32) (uint32, bool)
|
||||
|
||||
// ReadFloat32Le reads a float32 from 32 IEEE 754 little-endian encoded bits in the underlying buffer at the offset
|
||||
// or returns false if out of range.
|
||||
// See math.Float32bits
|
||||
ReadFloat32Le(ctx context.Context, offset uint32) (float32, bool)
|
||||
ReadFloat32Le(offset uint32) (float32, bool)
|
||||
|
||||
// ReadUint64Le reads a uint64 in little-endian encoding from the underlying buffer at the offset or returns false
|
||||
// if out of range.
|
||||
ReadUint64Le(ctx context.Context, offset uint32) (uint64, bool)
|
||||
ReadUint64Le(offset uint32) (uint64, bool)
|
||||
|
||||
// ReadFloat64Le reads a float64 from 64 IEEE 754 little-endian encoded bits in the underlying buffer at the offset
|
||||
// or returns false if out of range.
|
||||
//
|
||||
// See math.Float64bits
|
||||
ReadFloat64Le(ctx context.Context, offset uint32) (float64, bool)
|
||||
ReadFloat64Le(offset uint32) (float64, bool)
|
||||
|
||||
// Read reads byteCount bytes from the underlying buffer at the offset or
|
||||
// returns false if out of range.
|
||||
//
|
||||
// For example, to search for a NUL-terminated string:
|
||||
// buf, _ = memory.Read(ctx, offset, byteCount)
|
||||
// buf, _ = memory.Read(offset, byteCount)
|
||||
// n := bytes.IndexByte(buf, 0)
|
||||
// if n < 0 {
|
||||
// // Not found!
|
||||
@@ -501,7 +501,7 @@ type Memory interface {
|
||||
// Wasm are visible reading the returned slice.
|
||||
//
|
||||
// For example:
|
||||
// buf, _ = memory.Read(ctx, offset, byteCount)
|
||||
// buf, _ = memory.Read(offset, byteCount)
|
||||
// buf[1] = 'a' // writes through to memory, meaning Wasm code see 'a'.
|
||||
//
|
||||
// If you don't intend-write through, make a copy of the returned slice.
|
||||
@@ -515,40 +515,40 @@ type Memory interface {
|
||||
// shared. Those who need a stable view must set Wasm memory min=max, or
|
||||
// use wazero.RuntimeConfig WithMemoryCapacityPages to ensure max is always
|
||||
// allocated.
|
||||
Read(ctx context.Context, offset, byteCount uint32) ([]byte, bool)
|
||||
Read(offset, byteCount uint32) ([]byte, bool)
|
||||
|
||||
// WriteByte writes a single byte to the underlying buffer at the offset in or returns false if out of range.
|
||||
WriteByte(ctx context.Context, offset uint32, v byte) bool
|
||||
WriteByte(offset uint32, v byte) bool
|
||||
|
||||
// WriteUint16Le writes the value in little-endian encoding to the underlying buffer at the offset in or returns
|
||||
// false if out of range.
|
||||
WriteUint16Le(ctx context.Context, offset uint32, v uint16) bool
|
||||
WriteUint16Le(offset uint32, v uint16) bool
|
||||
|
||||
// WriteUint32Le writes the value in little-endian encoding to the underlying buffer at the offset in or returns
|
||||
// false if out of range.
|
||||
WriteUint32Le(ctx context.Context, offset, v uint32) bool
|
||||
WriteUint32Le(offset, v uint32) bool
|
||||
|
||||
// WriteFloat32Le writes the value in 32 IEEE 754 little-endian encoded bits to the underlying buffer at the offset
|
||||
// or returns false if out of range.
|
||||
//
|
||||
// See math.Float32bits
|
||||
WriteFloat32Le(ctx context.Context, offset uint32, v float32) bool
|
||||
WriteFloat32Le(offset uint32, v float32) bool
|
||||
|
||||
// WriteUint64Le writes the value in little-endian encoding to the underlying buffer at the offset in or returns
|
||||
// false if out of range.
|
||||
WriteUint64Le(ctx context.Context, offset uint32, v uint64) bool
|
||||
WriteUint64Le(offset uint32, v uint64) bool
|
||||
|
||||
// WriteFloat64Le writes the value in 64 IEEE 754 little-endian encoded bits to the underlying buffer at the offset
|
||||
// or returns false if out of range.
|
||||
//
|
||||
// See math.Float64bits
|
||||
WriteFloat64Le(ctx context.Context, offset uint32, v float64) bool
|
||||
WriteFloat64Le(offset uint32, v float64) bool
|
||||
|
||||
// Write writes the slice to the underlying buffer at the offset or returns false if out of range.
|
||||
Write(ctx context.Context, offset uint32, v []byte) bool
|
||||
Write(offset uint32, v []byte) bool
|
||||
|
||||
// WriteString writes the string to the underlying buffer at the offset or returns false if out of range.
|
||||
WriteString(ctx context.Context, offset uint32, v string) bool
|
||||
WriteString(offset uint32, v string) bool
|
||||
}
|
||||
|
||||
// EncodeExternref encodes the input as a ValueTypeExternref.
|
||||
|
||||
Reference in New Issue
Block a user