Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,17 @@ void __wasm_export_{ns}_{snake}_dtor({ns}_{snake}_t* arg) {{
self.finish_typedef_struct(id);
}

fn type_fixed_length_list(
&mut self,
_id: TypeId,
_name: &str,
_ty: &Type,
_size: u32,
_docs: &Docs,
) {
todo!("named fixed-length list types are not yet supported in the C backend")
}

fn type_future(&mut self, id: TypeId, _name: &str, _ty: &Option<Type>, docs: &Docs) {
self.src.h_defs("\n");
self.docs(docs, SourceType::HDefs);
Expand Down
5 changes: 4 additions & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub trait InterfaceGenerator<'a> {
fn type_enum(&mut self, id: TypeId, name: &str, enum_: &Enum, docs: &Docs);
fn type_alias(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs);
fn type_list(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs);
fn type_fixed_length_list(&mut self, id: TypeId, name: &str, ty: &Type, size: u32, docs: &Docs);
fn type_builtin(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs);
fn type_future(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs);
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs);
Expand Down Expand Up @@ -199,7 +200,9 @@ where
TypeDefKind::Future(t) => generator.type_future(id, name, t, &ty.docs),
TypeDefKind::Stream(t) => generator.type_stream(id, name, t, &ty.docs),
TypeDefKind::Handle(_) => panic!("handle types do not require definition"),
TypeDefKind::FixedLengthList(..) => todo!(),
TypeDefKind::FixedLengthList(t, size) => {
generator.type_fixed_length_list(id, name, t, *size, &ty.docs)
}
TypeDefKind::Map(..) => todo!(),
TypeDefKind::Unknown => unreachable!(),
}
Expand Down
11 changes: 11 additions & 0 deletions crates/cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,17 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for CppInterfaceGenerator<'a>
// nothing to do here
}

fn type_fixed_length_list(
&mut self,
_id: TypeId,
_name: &str,
_ty: &wit_bindgen_core::wit_parser::Type,
_size: u32,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
todo!("named fixed-length list types are not yet supported in the C++ backend")
}

fn type_builtin(
&mut self,
_id: TypeId,
Expand Down
11 changes: 11 additions & 0 deletions crates/csharp/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,17 @@ impl<'a> CoreInterfaceGenerator<'a> for InterfaceGenerator<'a> {
self.type_name(&Type::Id(id));
}

fn type_fixed_length_list(
&mut self,
_id: TypeId,
_name: &str,
_ty: &Type,
_size: u32,
_docs: &Docs,
) {
todo!("named fixed-length list types are not yet supported in the C# backend")
}

fn type_builtin(&mut self, _id: TypeId, _name: &str, _ty: &Type, _docs: &Docs) {
unimplemented!();
}
Expand Down
7 changes: 7 additions & 0 deletions crates/go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2873,6 +2873,13 @@ const (
uwriteln!(self.src, "{docs}type {name} = []{ty}");
}

fn type_fixed_length_list(&mut self, _: TypeId, name: &str, ty: &Type, size: u32, docs: &Docs) {
let name = name.to_upper_camel_case();
let ty = self.type_name(self.resolve, *ty);
let docs = format_docs(docs);
uwriteln!(self.src, "{docs}type {name} = [{size}]{ty}");
}

fn type_builtin(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs) {
_ = (id, name, ty, docs);
todo!()
Expand Down
11 changes: 11 additions & 0 deletions crates/markdown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,17 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
self.type_alias(id, name, &Type::Id(id), docs);
}

fn type_fixed_length_list(
&mut self,
id: TypeId,
name: &str,
_ty: &Type,
_size: u32,
docs: &Docs,
) {
self.type_alias(id, name, &Type::Id(id), docs);
}

fn type_future(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
_ = (id, name, ty, docs);
todo!()
Expand Down
11 changes: 11 additions & 0 deletions crates/moonbit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,17 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
// Not needed. They will become `Array[T]` or `FixedArray[T]` in Moonbit
}

fn type_fixed_length_list(
&mut self,
_id: TypeId,
_name: &str,
_ty: &Type,
_size: u32,
_docs: &Docs,
) {
// Not needed. They will become `FixedArray[T]` in Moonbit
}

fn type_future(&mut self, _id: TypeId, _name: &str, _ty: &Option<Type>, _docs: &Docs) {
unimplemented!() // Not needed
}
Expand Down
18 changes: 18 additions & 0 deletions crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2889,6 +2889,24 @@ impl<'a> {camel}Borrow<'a>{{
}
}

fn type_fixed_length_list(
&mut self,
id: TypeId,
_name: &str,
ty: &Type,
size: u32,
docs: &Docs,
) {
for (name, mode) in self.modes_of(id) {
self.rustdoc(docs);
self.push_str(&format!("pub type {name}"));
self.print_generics(mode.lifetime);
self.push_str(" = [");
self.print_ty(ty, mode);
self.push_str(&format!("; {size}];\n"));
}
}

fn type_future(&mut self, _id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
let async_support = self.r#gen.async_support_path();
let mode = TypeMode {
Expand Down
4 changes: 2 additions & 2 deletions crates/test/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ impl LanguageMethods for C {

fn should_fail_verify(
&self,
_name: &str,
name: &str,
config: &crate::config::WitConfig,
_args: &[String],
) -> bool {
config.error_context
config.error_context || name.starts_with("named-fixed-length-list.wit")
}

fn codegen_test_variants(&self) -> &[(&str, &[&str])] {
Expand Down
4 changes: 2 additions & 2 deletions crates/test/src/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl LanguageMethods for Cpp {

fn should_fail_verify(
&self,
_name: &str,
name: &str,
config: &crate::config::WitConfig,
_args: &[String],
) -> bool {
config.async_
config.async_ || name == "named-fixed-length-list.wit"
}

fn prepare(&self, runner: &mut Runner) -> anyhow::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions crates/test/src/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl LanguageMethods for Csharp {
| "issue-1432.wit"
| "issue-1433.wit"
| "future-same-type-different-names.wit"
| "named-fixed-length-list.wit"
)
}

Expand Down
4 changes: 3 additions & 1 deletion crates/test/src/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ impl LanguageMethods for Go {
// patch](https://github.com/dicej/go/commit/40fc123d5bce6448fc4e4601fd33bad4250b36a5).
// Once we upstream something equivalent, we can remove the ` || name ==
// "async-trait-function.wit"` here.
config.error_context || name == "async-trait-function.wit"
config.error_context
|| name == "async-trait-function.wit"
|| name == "named-fixed-length-list.wit"
}

fn default_bindgen_args_for_codegen(&self) -> &[&str] {
Expand Down
5 changes: 5 additions & 0 deletions crates/test/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ impl LanguageMethods for Rust {
return true;
}

// Named fixed-length lists don't work with async yet.
if name == "named-fixed-length-list.wit-async" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be curious to see the error (message) as these features should be orthogonal. Should be easy to fix (as should be a C++ implementation using std::array<>, C might be more tricky as it could require adding a struct).

return true;
}

false
}

Expand Down
12 changes: 12 additions & 0 deletions tests/codegen/named-fixed-length-list.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package test:named-fll;

interface types {
type my-array = list<u32, 4>;
type byte-buf = list<u8, 16>;
use-my-array: func(a: my-array) -> my-array;
}

world test {
import types;
export types;
}
Loading