Stream: general

Topic: Tooling for Component Model’s Donut Wrapping


view this post on Zulip Salman Saghafi (Jun 11 2024 at 20:51):

Hi All,

I’ve started looking into tooling support for donut wrapping, where a component A imports another component B and instantiates B inside A. This allows A to both provide B’s imports and use its exports. Donut wrapping is already supported by the component model but not by tooling. Here’s an example (by Luke Wagner) of how it’s done in WAT:

(component
  (core module $M ...)
  (core instance $m (instantiate $M ...))
  (core table $core_tbl (alias export $m "tbl"))
  (core func $core_f (alias export $m "f"))
  (func $f (canon lift ... (func $core_f))))
  (import "guest" (component $Guest ...))
  (instance $guest (instantiate $Guest (with "f" (func $f))))
  (func $g (alias export $guest "g"))
  (core func $core_g (canon lower ... (func $g)))
  (core module $Util
     (import "" "tbl" (table $t funcref 0))
     (import "" "g" (func $g ...))
     (elem (table $t) $g)
  )
  (core instance $util (instantiate $Util (with "" (instance
    (export "tbl" (table $core_tbl))
    (export "g" (func $core_g))
  ))
)

Here, a core instance $m is providing imports to $guest and calls its exports through a core table via $Util.

Approach

I’m thinking about following these steps:

Questions

I’d like to hear your thoughts and get your feedback before starting the implementation. Some questions are:

Thanks!


Last updated: Nov 22 2024 at 16:03 UTC