Stream: git-wasmtime

Topic: wasmtime / issue #6645 bindgen generates borrowed type wh...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 27 2023 at 09:17):

xxchan opened issue #6645:

I have WIT definitions like this:

default world w {
  export abc: self.abc
}

interface abc {
  type column = list<u8>

  record record-batch {
    schema: schema,
    // columns: list<array-data>,
    columns: list<column>,
    // row-count: u32,
  }

  enum data-type {
    dt-i16,
    dt-i32,
    dt-i64,
    dt-bool,
    dt-string,
  }

  record field {
    name: string,
    data-type: data-type,
  }

  record schema {
    fields: list<field>,
  }

  enum eval-errno {
    err1
  }

  eval: func(batch: record-batch) -> result<column, eval-errno>
}

wasmtime generates RecordBatch<'a>,

    #[derive(wasmtime::component::ComponentType, wasmtime::component::Lower)]
    #[component(record)]
    #[derive(Clone)]
    pub struct Field<'a> {
        #[component(name = "name")]
        pub name: &'a str,
        #[component(name = "data-type")]
        pub data_type: DataType,
    }

    #[derive(wasmtime::component::ComponentType, wasmtime::component::Lower)]
    #[component(record)]
    #[derive(Clone)]
    pub struct Schema<'a> {
        #[component(name = "fields")]
        pub fields: &'a [Field<'a>],
    }
    pub type Column = Vec<u8>;

    #[derive(wasmtime::component::ComponentType, wasmtime::component::Lower)]
    #[component(record)]
    #[derive(Clone)]
    pub struct RecordBatch<'a> {
        #[component(name = "schema")]
        pub schema: Schema<'a>,
        #[component(name = "columns")]
        pub columns: &'a [&'a Column],
    }

while wit-bindgen generates RecordBatch

    #[derive(Clone)]
    pub struct Field {
      pub name:wit_bindgen::rt::string::String,pub data_type:DataType,
    }
    #[derive(Clone)]
    pub struct Schema {
      pub fields:wit_bindgen::rt::vec::Vec::<Field>,
    }
    pub type Column = wit_bindgen::rt::vec::Vec<u8>;
    #[derive(Clone)]
    pub struct RecordBatch {
        pub schema: Schema,
        pub columns: wit_bindgen::rt::vec::Vec<Column>,
    }

Is this expected? I don't quite understand the reason and the lifetimes are not easy to work with :oh_no:

view this post on Zulip Wasmtime GitHub notifications bot (Jun 27 2023 at 09:19):

xxchan commented on issue #6645:

I found if I change the function interface

// from
eval: func(batch: record-batch) -> result<column, eval-errno>
// to
eval: func(batch: record-batch) -> result<record-batch, eval-errno>

wasmtime will also generate

    #[derive(
        wasmtime::component::ComponentType, wasmtime::component::Lift, wasmtime::component::Lower,
    )]
    #[component(record)]
    #[derive(Clone)]
    pub struct RecordBatch {
        #[component(name = "schema")]
        pub schema: Schema,
        #[component(name = "columns")]
        pub columns: Vec<Column>,
    }

I become more confused about the difference :eyes:


Last updated: Oct 23 2024 at 20:03 UTC