wasm-tools icon indicating copy to clipboard operation
wasm-tools copied to clipboard

components: Implement automatic deduplicating of text format type sugar

Open alexcrichton opened this issue 3 years ago • 3 comments

Currently a module textually represented like so:

(component
    (import "" (func))
    (import "" (func))
)

dumps as:

  0x0 | 00 61 73 6d | version 65546 (Component)
      | 0a 00 01 00
  0x8 | 01 05       | type section
  0xa | 02          | 2 count
  0xb | 7f          | [type 0] Interface(Primitive(Unit))
  0xc | 4c 00 00    | [type 1] Function(ComponentFuncType { params: [], result: Type(0) })
  0xf | 02 03       | import section
 0x11 | 01          | 1 count
 0x12 | 00 01       | [func 0] ComponentImport { name: "", ty: 1 }
 0x14 | 01 05       | type section
 0x16 | 02          | 2 count
 0x17 | 7f          | [type 2] Interface(Primitive(Unit))
 0x18 | 4c 00 02    | [type 3] Function(ComponentFuncType { params: [], result: Type(2) })
 0x1b | 02 03       | import section
 0x1d | 01          | 1 count
 0x1e | 00 03       | [func 1] ComponentImport { name: "", ty: 3 }

Here two function types are added (type 1 and type 3 above) but instead only one should be added. There are annotated FIXME annotations for this in the codebase where hashing support needs to be added.

alexcrichton avatar May 16 '22 17:05 alexcrichton

In addition to this, we shouldn't be encoding primitive types in the type section (e.g. from above: [[type 0] Interface(Primitive(Unit))]) at all unless they're explicitly being exported.

peterhuene avatar May 28 '22 00:05 peterhuene

oh I believe that was implemented in https://github.com/bytecodealliance/wasm-tools/pull/607 (landed after I initially opened this)

Currently this input dumps as:

  0x0 | 00 61 73 6d | version 65546 (Component)
      | 0a 00 01 00
  0x8 | 01 04       | type section
  0xa | 01          | 1 count
  0xb | 4c 00 7f    | [type 0] Function(ComponentFuncType { params: [], result: Primitive(Unit) })
  0xe | 02 03       | import section
 0x10 | 01          | 1 count
 0x11 | 00 00       | [func 0] ComponentImport { name: "", ty: 0 }
 0x13 | 01 04       | type section
 0x15 | 01          | 1 count
 0x16 | 4c 00 7f    | [type 1] Function(ComponentFuncType { params: [], result: Primitive(Unit) })
 0x19 | 02 03       | import section
 0x1b | 01          | 1 count
 0x1c | 00 01       | [func 1] ComponentImport { name: "", ty: 1 }

which is still wrong though with two type sections

alexcrichton avatar May 31 '22 14:05 alexcrichton

Ah right, sorry. I was looking through wasm-tools's in-flight issues as I was going through the wast crate for the component model spec update and was just looking at the issue text rather than the output of the tool (which is currently "on the floor" of my branch as it's in progress).

peterhuene avatar May 31 '22 18:05 peterhuene