@@ -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,24 @@ 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, with superfluous ` inlineexport ` s ignored like
121+ superfluous ` with ` arguments.
122+ * If a ` typeidx ` is not given to the ` instanceexpr ` , the resulting
123+ ` instanceidx ` 's type is inferred from the ` componentidx ` or ` inlineexport* ` .
112124
113125
114126## Alias Definitions
@@ -221,13 +233,21 @@ labellit ::= len:<u32> l:<label> => "l" (if len = |l|
221233valtype ::= i:<typeidx> => i
222234 | pvt:<primvaltype> => pvt
223235resourcetype ::= 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)
236+ functype ::= 0x40 pr:<paramsresult> => (func pr)
237+ | 0x43 pr:<paramsresult> => (func async pr) 🔀
238+ | 0x44 i*:<funcimms> pr:<paramsresult> => (func i* pr) ❓
239+ paramsresult ::= p*:vec(<labelvaltype>) r:<result> => (param p)* r
240+ result ::= 0x00 t:<valtype> => (result t)
228241 | 0x01 0x00 =>
242+ funcimms ::= 0x00 =>
243+ | 0x01 => optional ❓
244+ | 0x02 => async 🔀
245+ | 0x03 => optional async ❓🔀
229246componenttype ::= 0x41 cd*:vec(<componentdecl>) => (component cd*)
230247instancetype ::= 0x42 id*:vec(<instancedecl>) => (instance id*)
248+ | 0x45 o?:<opt?> id*:vec(<instancedecl>) => (instance o? id*) ❓
249+ opt? ::= 0x00 =>
250+ | 0x01 => optional ❓
231251componentdecl ::= 0x03 id:<importdecl> => id
232252 | id:<instancedecl> => id
233253instancedecl ::= 0x00 t:<core:type> => t
@@ -244,8 +264,9 @@ externtype ::= 0x00 0x11 i:<core:typeidx> => (core module (type
244264 | 0x05 i:<typeidx> => (instance (type i))
245265typebound ::= 0x00 i:<typeidx> => (eq i)
246266 | 0x01 => (sub resource)
267+ | 0x02 o?:<opt?> => (sub o? resource) ❓
247268valuebound ::= 0x00 i:<valueidx> => (eq i) 🪙
248- | 0x01 t:<valtype> => t 🪙
269+ | 0x01 o?:<opt?> t:<valtype> => o? t 🪙❓
249270```
250271Notes:
251272* The type opcodes follow the same negative-SLEB128 scheme as Core WebAssembly,
@@ -307,9 +328,10 @@ canon ::= 0x00 0x00 f:<core:funcidx> opts:<opts> ft:<typeidx> => (canon lift
307328 | 0x02 rt:<typeidx> => (canon resource.new rt (core func))
308329 | 0x03 rt:<typeidx> => (canon resource.drop rt (core func))
309330 | 0x04 rt:<typeidx> => (canon resource.rep rt (core func))
331+ | 0x07 si:<sortidx> => (canon optional.present si (core global)) ❓
310332 | 0x24 => (canon backpressure.inc (core func)) 🔀
311333 | 0x25 => (canon backpressure.dec (core func)) 🔀
312- | 0x09 rs:<resultlist > opts:<opts> => (canon task.return rs opts (core func)) 🔀
334+ | 0x09 r:<result > opts:<opts> => (canon task.return r opts (core func)) 🔀
313335 | 0x05 => (canon task.cancel (core func)) 🔀
314336 | 0x0a t:<core:valtype> i:<u32> => (canon context.get t i (core func)) 🔀
315337 | 0x0b t:<core:valtype> i:<u32> => (canon context.set t i (core func)) 🔀
@@ -372,7 +394,8 @@ Notes:
372394* When there is no ` string-encoding ` present, the default value is ` utf8 ` .
373395 For all other values, the default value is "none".
374396* Validation of the individual canonical definitions is described in
375- [ ` CanonicalABI.md ` ] ( CanonicalABI.md#canonical-definitions ) .
397+ [ ` CanonicalABI.md ` ] ( CanonicalABI.md#canonical-definitions ) or,
398+ for ` optional.present ` , in [ ` Text.md ` ] ( Text.md#-optionality ) .
376399
377400
378401## 🪙 Start Definitions
@@ -435,7 +458,8 @@ Notes:
435458* Validation requires that, for ` plainname ` s annotated with ` [constructor] ` ,
436459 ` [method] ` , or ` [static] ` , the first ` label ` matches the ` plainname ` of a
437460 preceding ` resource ` import or export, respectively, in the same scope
438- (component, component type or instance type).
461+ (component, component type or instance type) and that, if the ` resource `
462+ type is ` optional ` , so is the ` func ` type.
439463* 🏷️ Validation requires that ` implements ` -annotated imports or exports are
440464 ` instance ` -typed and have a ` plainname ` name.
441465* 🏷️/🔗 Validation requires that a ` vec(<attribute>) ` contains each kind of
@@ -571,6 +595,7 @@ named once.
571595* The opcodes (for types, canon built-ins, etc) should be re-sorted
572596* The two ` list ` type codes should be merged into one with an optional immediate
573597 and similarly for ` func ` .
598+ * The redundant opcodes introduced for ` optional ` should be merged.
574599* The redundant ` 0x00 ` and ` 0x01 ` opcodes of ` nameattributes ` will be merged.
575600* The vestigial ` 0x00 ` in ` thread.* ` and ` waitable-set.* ` built-ins may be
576601 removed.
@@ -602,6 +627,7 @@ named once.
602627
603628[ Strongly-unique ] : Text.md#name-uniqueness
604629[ Canonical Interface Name ] : Text.md#-canonical-interface-name
630+ [ Optionality ] : Text.md#-optionality
605631
606632[ type-imports ] : https://github.com/WebAssembly/proposal-type-imports/blob/master/proposals/type-imports/Overview.md
607633[ module-linking ] : https://github.com/WebAssembly/module-linking/blob/main/proposals/module-linking/Explainer.md
0 commit comments