Skip to content

Commit d7a2c26

Browse files
authored
Add subsection describing Index Spaces (#264)
* Add subsection describing Index Spaces Resolves #261 * Distinguish the core index spaces in WebAssembly 1.0 * Remove angle brackets in production names for consistency
1 parent e945a85 commit d7a2c26

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

design/mvp/Explainer.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ JavaScript runtimes. For a more user-focussed explanation, take a look at the
77

88
* [Grammar](#grammar)
99
* [Component definitions](#component-definitions)
10+
* [Index spaces](#index-spaces)
1011
* [Instance definitions](#instance-definitions)
1112
* [Alias definitions](#alias-definitions)
1213
* [Type definitions](#type-definitions)
@@ -129,6 +130,63 @@ next), nothing will be instantiated or executed at runtime; everything here is
129130
dead code.
130131

131132

133+
#### Index Spaces
134+
135+
[Like Core WebAssembly][Core Indices], the Component Model places each
136+
`definition` into one of a fixed set of *index spaces*, allowing the
137+
definition to be referred to by subsequent definitions (in the text and binary
138+
format) via a nonnegative integral *index*. When defining, validating and
139+
executing a component, there are 5 component-level index spaces:
140+
* (component) functions
141+
* (component) values
142+
* (component) types
143+
* component instances
144+
* components
145+
146+
5 core index spaces that also exist in WebAssembly 1.0:
147+
* (core) functions
148+
* (core) tables
149+
* (core) memories
150+
* (core) globals
151+
* (core) types
152+
153+
and 2 additional core index spaces that contain core definition introduced by
154+
the Component Model that are not in WebAssembly 1.0 (yet: the [module-linking]
155+
proposal would add them):
156+
* module instances
157+
* modules
158+
159+
for a total of 12 index spaces that need to be maintained by an implementation
160+
when, e.g., validating a component. These 12 index spaces correspond 1:1 with
161+
the terminals of the `sort` production defined below and thus "sort" and
162+
"index space" can be used interchangeably.
163+
164+
Also [like Core WebAssembly][Core Identifiers], the Component Model text format
165+
allows *identifiers* to be used in place of these indices, which are resolved
166+
when parsing into indices in the AST (upon which validation and execution is
167+
defined). Thus, the following two components are equivalent:
168+
```wasm
169+
(component
170+
(core module (; empty ;))
171+
(component (; empty ;))
172+
(core module (; empty ;))
173+
(export "C" (component 0))
174+
(export "M1" (core module 0))
175+
(export "M2" (core module 1))
176+
)
177+
```
178+
```wasm
179+
(component
180+
(core module $M1 (; empty ;))
181+
(component $C (; empty ;))
182+
(core module $M2 (; empty ;))
183+
(export "C" (component $C))
184+
(export "M1" (core module $M1))
185+
(export "M2" (core module $M2))
186+
)
187+
```
188+
189+
132190
### Instance Definitions
133191

134192
Whereas modules and components represent immutable *code*, instances associate
@@ -1800,6 +1858,8 @@ and will be added over the coming months to complete the MVP proposal:
18001858
[Structure Section]: https://webassembly.github.io/spec/core/syntax/index.html
18011859
[Text Format Section]: https://webassembly.github.io/spec/core/text/index.html
18021860
[Binary Format Section]: https://webassembly.github.io/spec/core/binary/index.html
1861+
[Core Indices]: https://webassembly.github.io/spec/core/syntax/modules.html#indices
1862+
[Core Identifiers]: https://webassembly.github.io/spec/core/text/values.html#text-id
18031863

18041864
[Index Space]: https://webassembly.github.io/spec/core/syntax/modules.html#indices
18051865
[Abbreviations]: https://webassembly.github.io/spec/core/text/conventions.html#abbreviations

0 commit comments

Comments
 (0)