Skip to content

Rework the function and local names section. #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions BinaryEncoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,44 +233,63 @@ This section must be preceded by a [Functions](#functions-section) section.
| count | `varuint32` | count of entries to follow |
| entries | `uint16*` | repeated indexes into the function table |

### Names section
### Function Names section

ID: `names`
ID: `function_names`

This section may occur 0 or 1 times and does not change execution semantics. A
validation error in this section does not cause validation for the whole module
to fail and is instead treated as if the section was absent. The expectation is
to fail and may be treated as if the section was absent. The expectation is
that, when a binary WebAssembly module is viewed in a browser or other
development environment, the names in this section will be used as the names of
functions and locals in the [text format](TextFormat.md).
development environment, the names in this section will be used as the name
prefixes of functions in the [text format](TextFormat.md) and that when there
are duplicates that a unique suffix will be added.

| Field | Type | Description |
| ----- | ----- | ----- |
| count | `varuint32` | count of entries to follow |
| entries | `function_names*` | sequence of names |
| fun_name_lens | `varuint32*` | sequence of name lengths in bytes |
| fun_name_strs | `bytes*` | valid utf8 encoding for all the names |

The sequence of `function_name` assigns names to the corresponding
function index. The count may be greater or less than the actual number of
functions.
The sequence of `fun_name_lens` gives the lengths for each function name in the
same order as in the function signatures section, and then for the import
functions in the order in the imports section. All names must have a name
length, however the length may be zero in which case no name is defined for the
respective function. The `fun_name_strs` are the bytes for all these string in
the same order.

#### Function names
The lengths are first in a block to provide a directory to lookup names and to
help compression. Blocks of unnamed functions are blocks of zeros and are
expected to compress well so it is not expected to be a burden to have to supply
a length for all function names.

| Field | Type | Description |
| ----- | ----- | ----- |
| fun_name_len | `varuint32` | string length, in bytes |
| fun_name_str | `bytes` | valid utf8 encoding |
| local_count | `varuint32` | count of local names to follow |
| local_names | `local_name*` | sequence of local names |
### Local Names section

The sequence of `local_name` assigns names to the corresponding local index. The
count may be greater or less than the actual number of locals.
ID: `local_names`

#### Local name
This section may occur 0 or 1 times and does not change execution semantics. A
validation error in this section does not cause validation for the whole module
to fail and may be treated as if the section was absent. The expectation is
that, when a binary WebAssembly module is viewed in a browser or other
development environment, the names in this section will be used as the name
prefixes of locals in the [text format](TextFormat.md) and that when there are
duplicates that a unique suffix will be added.

| Field | Type | Description |
| ----- | ----- | ----- |
| local_name_len | `varuint32` | string length, in bytes |
| local_name_str | `bytes` | valid utf8 encoding |
| local_name_lens | `varuint32*` | sequence of name lengths in bytes |
| local_name_strs | `bytes*` | valid utf8 encoding for all the names |

The sequence of `local_name_lens` gives the lengths for each local name of each
function in the same order as in the function signatures section and the same
order as the locals are defined in the function bodies. All names must have a
name length, however the length may be zero in which case no name is defined for
the respective local. The `fun_name_strs` are the bytes for all these string in
the same order.

The lengths are first in a block to provide a directory to lookup names and to
help compression. Blocks of unnamed locals are blocks of zeros and are expected
to compress well so it is not expected to be a burden to have to supply a length
for all function names.

### End section

Expand Down