Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit f497d55

Browse files
authored
[Overview] Update segment initialization text (#57)
See issue #56.
1 parent 79bf48c commit f497d55

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

proposals/bulk-memory-operations/Overview.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ An `elem_expr` is like an `init_expr`, but can only contain expressions of the f
241241

242242
TODO: coordinate with other proposals to determine the binary encoding for `ref.null` and `ref.func`.
243243

244+
### Segment Initialization
245+
246+
In the MVP, segments are initialized during module instantiation. If any segment
247+
would be initialized out-of-bounds, then the memory or table instance is not
248+
modified.
249+
250+
This behavior is changed in the bulk memory proposal.
251+
252+
Each active segment is initialized in module-definition order. For each
253+
segment, each byte in the data segment is copied into the memory, in order of
254+
lowest to highest addresses. If, for a given byte, the copy is out-of-bounds,
255+
instantiation fails and no further bytes in this segment nor further segments
256+
are copied. Bytes written before this point stay written.
257+
258+
The behavior of element segment initialization is changed similarly, with the
259+
difference that elements are copied from element segments into tables, instead
260+
of bytes being copied from data segments into memories.
261+
244262
### `memory.init` instruction
245263

246264
The `memory.init` instruction copies data from a given passive segment into a target
@@ -252,12 +270,6 @@ The instruction has the signature `[i32 i32 i32] -> []`. The parameters are, in
252270
- top-1: offset into the source segment
253271
- top-0: size of memory region in bytes
254272

255-
When `memory.init` is executed, its behavior matches the steps described in
256-
step 11 of
257-
[instantiation](https://webassembly.github.io/spec/exec/modules.html#instantiation),
258-
but it behaves as though the segment were specified with the source offset,
259-
target offset, and length as given by the `memory.init` operands.
260-
261273
It is a validation error to use `memory.init` with an out-of-bounds segment index.
262274

263275
A trap occurs if:

0 commit comments

Comments
 (0)