@@ -62,7 +62,8 @@ referencing:
62
62
63
63
* each ` importdesc ` is valid according to import section
64
64
* Types can only reference preceding type definitions. This forces everything to
65
- be a DAG and forbids cyclic types.
65
+ be a DAG and forbids cyclic types. TODO: with type imports we may need cyclic
66
+ types, so this validation will likely change in some form.
66
67
67
68
## Import Section updates
68
69
@@ -89,12 +90,12 @@ importdesc ::=
89
90
* the ` module x ` production ensures the type ` x ` is indeed a module type
90
91
* the ` instance x ` production ensures the type ` x ` is indeed an instance type
91
92
92
- ## Module section (100 )
93
+ ## Module section (14 )
93
94
94
95
A new module section is added
95
96
96
97
```
97
- modulesec ::= t*:section_100 (vec(typeidx)) -> t*
98
+ modulesec ::= t*:section_14 (vec(typeidx)) -> t*
98
99
```
99
100
100
101
** Validation**
@@ -103,12 +104,12 @@ modulesec ::= t*:section_100(vec(typeidx)) -> t*
103
104
* This defines the locally defined set of modules, adding to the module index
104
105
space.
105
106
106
- ## Instance section (101 )
107
+ ## Instance section (15 )
107
108
108
109
A new section defining local instances
109
110
110
111
```
111
- instancesec ::= i*:section_101 (vec(instancedef)) -> i*
112
+ instancesec ::= i*:section_15 (vec(instancedef)) -> i*
112
113
113
114
instancedef ::= 0x00 m:moduleidx e*:vec(exportdesc) -> {instantiate m, imports e*}
114
115
```
@@ -125,21 +126,25 @@ the future we'll likely want this binary value to match that.
125
126
* The type index ` m ` must point to a module type.
126
127
* Indices of items referred to by ` exportdesc ` are all in-bounds. Can only refer
127
128
to imports/previous aliases, since only those sections can precede.
128
- * The precise rules of how ` e* ` is validated against the module type's declare
129
- list of imports is being hashed out in
130
- [ #7 ] ( https://github.com/WebAssembly/module-linking/issues/7 ) . For now
131
- conservative order-dependent rules are used where the length of ` e* ` must be
132
- the same as the number of imports the module type has. Additionally the type
133
- of each element of ` e* ` must be a subtype of the type that it's being matched
134
- with. Matching happens pairwise with the list of imports on the module type
135
- for ` m ` .
129
+ * The ` e* ` list is validated against the module type's declared list
130
+ of [ imports pairwise and in-order] ( Explainer.md#module-imports-and-nested-instances ) .
131
+ The type of each item must be a supertype of the expected type listed in the
132
+ module's type.
136
133
137
- ## Alias section (102)
134
+ ** Execution notes**
135
+
136
+ * The actual module being instantiated does not need to list imports in the
137
+ exact same order as its type declaration. The ` e* ` has names based on the
138
+ local module type's declaration.
139
+ * Be sure to read up on [ subtyping] ( ./Subtyping.md ) to ensure that instances
140
+ with a single name can be used to match imports with a two-level namespace.
141
+
142
+ ## Alias section (16)
138
143
139
144
A new module section is added
140
145
141
146
```
142
- aliassec ::= a*:section_102 (vec(alias)) -> a*
147
+ aliassec ::= a*:section_16 (vec(alias)) -> a*
143
148
144
149
alias ::=
145
150
0x00 i:instanceidx 0x00 e:exportidx -> (alias (instance $i) (func $e))
@@ -154,9 +159,10 @@ alias ::=
154
159
155
160
** Validation**
156
161
157
- * Aliased instance indexes are all in bounds
162
+ * Aliased instance indexes are all in bounds. Remember "in bounds" here means it
163
+ can't refer to instances defined after the ` alias ` item.
158
164
* Aliased instance export indices are in bounds relative to the instance's
159
- * locally-declared* (via module or instance type) list of exports
165
+ * locally-declared* (via module or instance type) list of exports.
160
166
* Export indices match the actual type of the export
161
167
* Aliases append to the respective index space.
162
168
* Parent aliases can only happen in submodules (not the top-level module) and
@@ -169,6 +175,12 @@ alias ::=
169
175
items were declared after the module's type in the corresponding module
170
176
section.
171
177
178
+ ** Execution notes**
179
+
180
+ * Note for child aliases that while the export is referred to by index it's
181
+ actually loaded from the specified instance by name. The name loaded
182
+ corresponds to the ` i ` th export's name in the locally defined type.
183
+
172
184
## Function section
173
185
174
186
** Validation**
@@ -191,10 +203,10 @@ exportdesc ::=
191
203
192
204
* Module/instance indexes must be in-bounds.
193
205
194
- ## Module Code Section (103 )
206
+ ## Module Code Section (17 )
195
207
196
208
```
197
- modulecodesec ::= m*:section_103 (vec(modulecode)) -> m*
209
+ modulecodesec ::= m*:section_17 (vec(modulecode)) -> m*
198
210
199
211
modulecode ::= size:u32 mod:module -> mod, size = ||mod||
200
212
```
@@ -208,31 +220,9 @@ the top-level
208
220
* Module definitions must match their module type exactly, no subtyping (or
209
221
maybe subtyping, see WebAssembly/module-linking #9 ).
210
222
* Modules themselves validate recursively.
211
- * Must have the same number of modules as the count of all local module
212
- sections.
213
- * Each submodule is validated with a subset of the parent's context, for example
214
- the set of types and instances the current module has defined are available
215
- for aliasing in the submodule.
216
-
217
- ## Subtyping
218
-
219
- Subtyping will extend what's currently [ "import
220
- matching"] ( https://webassembly.github.io/spec/core/exec/modules.html#import-matching )
221
-
222
- ** Instances**
223
-
224
- Instance ` {exports e1} ` is a subtype of ` {exports e2} ` if and only if:
225
-
226
- * Each name in ` e1 ` is present in ` e2 `
227
- * For each corresponding name ` n ` in the sets
228
- * ` e1[n] ` is a subtype of ` e2[n] `
229
-
230
- ** Instances**
231
-
232
- Module ` {imports i1, exports e1} ` is a subtype of ` {imports i2, exports e2} ` if and only if:
233
-
234
- * Each name in ` e1 ` is present in ` e2 `
235
- * For each corresponding name ` n ` in the sets
236
- * ` e1[n] ` is a subtype of ` e2[n] `
237
- * ... And some condition on imports. For now this is a bit up for debate on
238
- WebAssembly/module-linking #7
223
+ * The module code section must have the same number of modules as the count of
224
+ all local module sections.
225
+ * Each submodule is validated with the parent's context at the time of
226
+ declaration. For example the set of types and modules the current module
227
+ has defined are available for aliasing in the submodule, but only those
228
+ defined before the corresponding module's type declaration.
0 commit comments