From 3cc92afe9fa59be70688e209c8248e25434efd6b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 16 Mar 2026 08:19:31 -0700 Subject: [PATCH] Adjust binary encoding of import/export names The purpose of this commit is to address the discrepancy between the specification and wasm-tools discovered in #622. The history here is: * #222 - historical addition of `(interface "name")` as an import/export name. * #263 - moral revert of the previous change where the kind of name was now encoded in the name instead. At this point `Binary.md` mistakenly no longer reflected what wasm-tools parsed. * #536 - addition of more metadata to import/export names with a discriminator byte that overlapped the previous. This commit is is an adjustment to `Binary.md` to fix these discrepancies. Notably `exportname` and `importname` productions, previously absent. The `exportname'` and `importname'` productions are now renamed to `exportname` and `importname`. Additioanlly the production with `versionsuffix'` have been renumbered to `0x02` while an `0x01` production was added which is the exact same as `0x00` (intended for historical compat). A note was updated in the 1.0 binary adjustments to clean this up. Closes #622 --- design/mvp/Binary.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/design/mvp/Binary.md b/design/mvp/Binary.md index 3a2fa83b..f1081e49 100644 --- a/design/mvp/Binary.md +++ b/design/mvp/Binary.md @@ -228,8 +228,8 @@ instancedecl ::= 0x00 t: => t | 0x01 t: => t | 0x02 a: => a | 0x04 ed: => ed -importdecl ::= in: ed: => (import in ed) -exportdecl ::= en: ed: => (export en ed) +importdecl ::= in: ed: => (import in ed) +exportdecl ::= en: ed: => (export en ed) externdesc ::= 0x00 0x11 i: => (core module (type i)) | 0x01 i: => (func (type i)) | 0x02 b: => (value b) 🪙 @@ -386,13 +386,15 @@ flags are set. (See [Import and Export Definitions](Explainer.md#import-and-export-definitions) in the explainer.) ```ebnf -import ::= in: ed: => (import in ed) -export ::= en: si: ed?:? => (export en si ed?) -importname' ::= 0x00 len: in: => in (if len = |in|) - | 0x01 len: in: vs: => in vs (if len = |in|) 🔗 -exportname' ::= 0x00 len: en: => en (if len = |en|) - | 0x01 len: en: vs: => in vs (if len = |in|) 🔗 -versionsuffix' ::= len: vs: => (versionsuffix vs) (if len = |vs|) 🔗 +import ::= in: ed: => (import in ed) +export ::= en: si: ed?:? => (export en si ed?) +importname ::= 0x00 len: in: => in (if len = |in|) + | 0x01 len: in: => in (if len = |in|) + | 0x02 len: in: vs: => in vs (if len = |in|) 🔗 +exoprtname ::= 0x00 len: in: => in (if len = |in|) + | 0x01 len: in: => in (if len = |in|) + | 0x02 len: in: vs: => in vs (if len = |in|) 🔗 +versionsuffix ::= len: vs: => (versionsuffix vs) (if len = |vs|) 🔗 ``` Notes: @@ -406,6 +408,8 @@ Notes: of the inferred `externdesc` of the `sortidx`. * `` and `` refer to the productions defined in the [text format](Explainer.md#import-and-export-definitions). +* `` and `` will [be cleaned up for a 1.0 + release](##binary-format-warts-to-fix-in-a-10-release). * The ``s of a component must all be [strongly-unique]. Separately, the ``s of a component must also all be [strongly-unique]. * Validation requires that annotated `plainname`s only occur on `func` imports @@ -519,9 +523,9 @@ named once. * The two `depname` cases should be merged into one (`dep=<...>`) * The two `list` type codes should be merged into one with an optional immediate and similarly for `func`. -* The `0x00` variant of `importname'` and `exportname'` will be removed. Any - remaining variant(s) will be renumbered or the prefix byte will be removed or - repurposed. +* The `0x00` and `0x01` variant of `importname` and `exportname` will be + removed. Any remaining variant(s) will be renumbered or the prefix byte will + be removed or repurposed. * Most built-ins should have a `*` immediate instead of an ad hoc subset of `canonopt`s. * Add optional `shared` immediate to all canonical definitions (explicitly or