Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Unclear how adapting imports and acyclic instantiation works #129

@alexcrichton

Description

@alexcrichton

I was thinking about this a bit more today about how you would take an imported function that takes/returns a strings, and then connect that to a core wasm module which takes/returns pointers/lengths. The current explainer has an example which it claims shows how to do this:

(adapter_module
  (import "print" (adapter_func $print (param string)))
  (adapter_module $ADAPTER
    (import "print" (adapter_func $originalPrint (param string)))
    (adapter_func $print (export "print") (param i32 i32)
      ...
      call_adapter $originalPrint
    )
  )
  (adapter_instance $adapter (instantiate $ADAPTER (adapter_func $print)))
  (module $CORE
    (import "print" (func $print (param i32 i32) (result i32 i32)))
    (func $run (export "run")
      ;; core code
    )
  )
  (instance $core (instantiate $CORE (adapter_func $adapter.$print)))
  (adapter_func (export "run")
    call $core.$run
  )
)

I don't think this examples works, however. The $ADAPTER module receives a pointer/length, but it has no memory to load values from. Similarly if adapter_func $print wanted to return a string there's no way for $ADAPTER to call malloc to allocate space for the return string.

I think this may have been an accidental mistake from rebasing on top of module linking? I may also be missing something about how this is expected to work. For adapting imports though it seems like you need to first instantiate the module in question to have access to memory/malloc/etc, and then afterwards you can create adapters referencing those items. The problem though is that instantiation of the module requires the imported functions (e.g. "print" in this case), which is a cyclical dependency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions