component-model icon indicating copy to clipboard operation
component-model copied to clipboard

Canonical abi: inline passing

Open oovm opened this issue 1 year ago • 2 comments

There doesn't seem to be an option right now to force parameters to be passed inline

For record, list<T, N>, tuple, flags, etc., they are all transfer forms of ptr + len.

This requires at least

  1. Know the layout defined by the type
  2. The layout has been filled and aligned correctly
  3. A little offset calculation instructions are needed to extract the field

or need

  1. realloc is required to ensure compliance with the language-defined layout
  2. A little offset calculation instructions are needed to extract the field

Is it possible to add an inline-passing option to omit these requirements?

I find this useful in languages where tuples exist.

oovm avatar Mar 02 '24 06:03 oovm

Can you clarify what you mean by "passed inline"? For example a record is already "splatted" to its parts and passed inline when it's a parameter:

$ cat foo.wit
package a:b;

world foo {
  record x {
    a: u32,
    b: f32,
    c: f64,
  }

  import foo: func(x: x);
}
$ wasm-tools component embed --dummy foo.wit -t
(module
  (type (;0;) (func (param i32 f32 f64)))
  (type (;1;) (func (param i32 i32 i32 i32) (result i32)))
  (import "$root" "foo" (func (;0;) (type 0)))
  (func (;1;) (type 1) (param i32 i32 i32 i32) (result i32)
    unreachable
  )
  (memory (;0;) 0)
  (export "memory" (memory 0))
  (export "cabi_realloc" (func 1))
)

(note the parameters to import "$root" "foo")

Lists which dynamically have a small length are not passed inline, but I'm not sure how that would be managed otherwise.

This is all a result of flattening in the canonical ABI.

So given that, can you clarify what you mean by things should be passed inline?

alexcrichton avatar Mar 02 '24 17:03 alexcrichton

Perhaps #385 solves a similar problem. At least it does with one specific definition of "inline" and "embed" (into structures).

cpetig avatar Aug 01 '24 17:08 cpetig