Skip to content

Commit 0a9375c

Browse files
committed
Also clarify acyclicy of component definitions
1 parent 36e6475 commit 0a9375c

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

design/mvp/Explainer.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ explicitly mark where a `core` token might be required. The exception in
155155
`core-prefix` for `<idx>` means that, for example, `core-prefix(<core:funcidx>)`
156156
accepts both `(core func $foo)` and plain `$foo`.
157157

158+
158159
### Component Definitions
159160

160161
At the top-level, a `component` is a sequence of definitions of various kinds:
@@ -173,10 +174,38 @@ definition ::= core-prefix(<core:module>)
173174
| <export>
174175
| <value> 🪙
175176
```
176-
Components are like Core WebAssembly modules in that their contained
177-
definitions are acyclic: definitions can only refer to preceding definitions
178-
(in the AST, text format and binary format). However, unlike modules,
179-
components can arbitrarily interleave different kinds of definitions.
177+
178+
As suggested by this grammar, unlike in Core WebAssembly modules, component
179+
`definition`s can be in any order and a single kind of `definition` can appear
180+
multiple times, interleaved with other kinds of `definition`s. Moreover, the
181+
order of `definition`s in the text format is significant and, unlike Core
182+
WebAssembly, `definition`s are not reordered and grouped by the text format.
183+
Furthermore, component `definition`s are strictly *acyclic*, such that a given
184+
`definition` (in the text or binary format) can only refer to identifiers or
185+
indices introduced by preceding definitions. Based on this, while the following
186+
two core modules are both valid and equivalent (with the first being "desugared"
187+
into the second):
188+
```wat
189+
(module
190+
(import "" "f" (func (type $FT)))
191+
(type $FT (func))
192+
)
193+
(module
194+
(type (func))
195+
(import "" "f" (func (type 0)))
196+
)
197+
```
198+
only the latter component is valid:
199+
```wat
200+
;;(component
201+
;; (import "f" (func (type $FT))) ❌ $FT not defined
202+
;; (type $FT (func))
203+
;;)
204+
(component
205+
(type $FT (func))
206+
(import "f" (func (type $FT)))
207+
)
208+
```
180209

181210
As defined in the previous section, `core-prefix(<X>)` adds a `core` token after
182211
the leftmost parenthesis of `<X>` and so, e.g., `core-prefix(<core:module>)`

0 commit comments

Comments
 (0)