@@ -77,6 +77,7 @@ core:inlineexport ::= n:<core:name> si:<core:sortidx> => (e
7777instance ::= ie:<instanceexpr> => (instance ie)
7878instanceexpr ::= 0x00 c:<componentidx> arg*:vec(<instantiatearg>) => (instantiate c arg*)
7979 | 0x01 e*:vec(<inlineexport>) => e*
80+ | 0x02 i:<typeidx> e*:vec(<inlineexport>) => (type i) e*
8081instantiatearg ::= n:<name> si:<sortidx> => (with n si)
8182name ::= n:<core:name> => n
8283sortidx ::= sort:<sort> idx:<u32> => (sort idx)
@@ -102,13 +103,23 @@ Notes:
102103 sort, but would be extended to accept other sorts as core wasm is extended.
103104* Validation of ` instantiate ` requires each ` <externname> ` in ` c ` to match a
104105 ` name ` in a ` with ` argument (using plain string equality) and for the types to
105- match.
106+ match unless the ` <externname> ` 's type is ` optional ` , in which case no ` with `
107+ argument need be given.
106108* When validating ` instantiate ` , after each individual type-import is supplied
107109 via ` with ` , the actual type supplied is immediately substituted for all uses
108110 of the import, so that subsequent imports and all exports are now specialized
109111 to the actual type.
110112* The indices in ` sortidx ` are validated according to their ` sort ` 's index
111113 spaces, which are built incrementally as each definition is validated.
114+ * Validation of an ` instanceexpr ` with an ascribed ` typeidx ` requires that the
115+ ` typeidx ` refer to an ` instance ` type and the given ` inlineexport* ` match the
116+ ` export ` s of that ` instance ` type with the additional allowances that:
117+ ` optional ` definitions can be supplied for non-` optional ` ` export ` s of an
118+ ` optional ` instance; and the ` optional ` ` export ` s in an ` instance ` type can be
119+ omitted (see [ optionality] ). The resulting ` instanceidx ` 's type is then
120+ exactly the ascribed type, and thus superfluous ` inlineexport ` s are ignored.
121+ * If a ` typeidx ` is not given to the ` instanceexpr ` , the resulting
122+ ` instanceidx ` 's type is inferred from the ` componentidx ` or ` inlineexport* ` .
112123
113124
114125## Alias Definitions
@@ -221,13 +232,21 @@ labellit ::= len:<u32> l:<label> => "l" (if len = |l|
221232valtype ::= i:<typeidx> => i
222233 | pvt:<primvaltype> => pvt
223234resourcetype ::= 0x3f t:<core:valtype> f?:<core:funcidx>? => (resource (rep t) (dtor f)?)
224- functype ::= 0x40 ps:<paramlist> rs:<resultlist> => (func ps rs)
225- | 0x43 ps:<paramlist> rs:<resultlist> => (func async ps rs)
226- paramlist ::= lt*:vec(<labelvaltype>) => (param lt)*
227- resultlist ::= 0x00 t:<valtype> => (result t)
235+ functype ::= 0x40 pr:<paramsresult> => (func pr)
236+ | 0x43 pr:<paramsresult> => (func async pr) 🔀
237+ | 0x44 i*:<funcimms> pr:<paramsresult> => (func i* pr) ❓
238+ paramsresult ::= p*:vec(<labelvaltype>) r:<result> => (param p)* r
239+ result ::= 0x00 t:<valtype> => (result t)
228240 | 0x01 0x00 =>
241+ funcimms ::= 0x00 =>
242+ | 0x01 => optional ❓
243+ | 0x02 => async 🔀
244+ | 0x03 => optional async ❓🔀
229245componenttype ::= 0x41 cd*:vec(<componentdecl>) => (component cd*)
230246instancetype ::= 0x42 id*:vec(<instancedecl>) => (instance id*)
247+ | 0x45 o?:<opt?> id*:vec(<instancedecl>) => (instance o? id*) ❓
248+ opt? ::= 0x00 =>
249+ | 0x01 => optional ❓
231250componentdecl ::= 0x03 id:<importdecl> => id
232251 | id:<instancedecl> => id
233252instancedecl ::= 0x00 t:<core:type> => t
@@ -244,8 +263,9 @@ externtype ::= 0x00 0x11 i:<core:typeidx> => (core module (type
244263 | 0x05 i:<typeidx> => (instance (type i))
245264typebound ::= 0x00 i:<typeidx> => (eq i)
246265 | 0x01 => (sub resource)
266+ | 0x02 o?:<opt?> => (sub o? resource) ❓
247267valuebound ::= 0x00 i:<valueidx> => (eq i) 🪙
248- | 0x01 t:<valtype> => t 🪙
268+ | 0x01 o?:<opt?> t:<valtype> => o? t 🪙❓
249269```
250270Notes:
251271* The type opcodes follow the same negative-SLEB128 scheme as Core WebAssembly,
@@ -307,9 +327,10 @@ canon ::= 0x00 0x00 f:<core:funcidx> opts:<opts> ft:<typeidx> => (canon lift
307327 | 0x02 rt:<typeidx> => (canon resource.new rt (core func))
308328 | 0x03 rt:<typeidx> => (canon resource.drop rt (core func))
309329 | 0x04 rt:<typeidx> => (canon resource.rep rt (core func))
330+ | 0x07 si:<sortidx> => (canon optional.present si (core global)) ❓
310331 | 0x24 => (canon backpressure.inc (core func)) 🔀
311332 | 0x25 => (canon backpressure.dec (core func)) 🔀
312- | 0x09 rs:<resultlist > opts:<opts> => (canon task.return rs opts (core func)) 🔀
333+ | 0x09 r:<result > opts:<opts> => (canon task.return r opts (core func)) 🔀
313334 | 0x05 => (canon task.cancel (core func)) 🔀
314335 | 0x0a t:<core:valtype> i:<u32> => (canon context.get t i (core func)) 🔀
315336 | 0x0b t:<core:valtype> i:<u32> => (canon context.set t i (core func)) 🔀
@@ -435,7 +456,8 @@ Notes:
435456* Validation requires that, for ` plainname ` s annotated with ` [constructor] ` ,
436457 ` [method] ` , or ` [static] ` , the first ` label ` matches the ` plainname ` of a
437458 preceding ` resource ` import or export, respectively, in the same scope
438- (component, component type or instance type).
459+ (component, component type or instance type) and that, if the ` resource `
460+ type is ` optional ` , so is the ` func ` type.
439461* 🏷️ Validation requires that ` implements ` -annotated imports or exports are
440462 ` instance ` -typed and have a ` plainname ` name.
441463* 🏷️/🔗 Validation requires that a ` vec(<attribute>) ` contains each kind of
@@ -571,6 +593,7 @@ named once.
571593* The opcodes (for types, canon built-ins, etc) should be re-sorted
572594* The two ` list ` type codes should be merged into one with an optional immediate
573595 and similarly for ` func ` .
596+ * The redundant opcodes introduced for ` optional ` should be merged.
574597* The redundant ` 0x00 ` and ` 0x01 ` opcodes of ` nameattributes ` will be merged.
575598* The vestigial ` 0x00 ` in ` thread.* ` and ` waitable-set.* ` built-ins may be
576599 removed.
@@ -602,6 +625,7 @@ named once.
602625
603626[ Strongly-unique ] : Text.md#name-uniqueness
604627[ Canonical Interface Name ] : Text.md#-canonical-interface-name
628+ [ Optionality ] : Text.md#-optionality
605629
606630[ type-imports ] : https://github.com/WebAssembly/proposal-type-imports/blob/master/proposals/type-imports/Overview.md
607631[ module-linking ] : https://github.com/WebAssembly/module-linking/blob/main/proposals/module-linking/Explainer.md
0 commit comments