Skip to content

Commit

Permalink
feat(go): remove the impl of type_list as it's a anonymous type (#925)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiaxiao Zhou (Mossaka) <duibao55328@gmail.com>
  • Loading branch information
Mossaka authored Apr 11, 2024
1 parent 17c4589 commit 90a1e54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 88 deletions.
107 changes: 20 additions & 87 deletions crates/go/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use wit_bindgen_c::{
CTypeNameInfo,
};
use wit_bindgen_core::wit_parser::{
Field, Function, FunctionKind, Handle, InterfaceId, LiveTypes, Resolve, Type, TypeDefKind,
TypeId, TypeOwner, WorldKey,
Docs, Enum, Field, Flags, Function, FunctionKind, Handle, InterfaceId, LiveTypes, Record,
Resolve, Result_, Tuple, Type, TypeDefKind, TypeId, TypeOwner, Variant, WorldKey,
};
use wit_bindgen_core::{uwriteln, Direction, InterfaceGenerator as _, Source};

Expand Down Expand Up @@ -1008,13 +1008,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
self.resolve
}

fn type_record(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
name: &str,
record: &wit_bindgen_core::wit_parser::Record,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_record(&mut self, _id: TypeId, name: &str, record: &Record, _docs: &Docs) {
let name = self.type_name(name, true);
self.src.push_str(&format!("type {name} struct {{\n",));
for field in record.fields.iter() {
Expand All @@ -1025,12 +1019,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
self.src.push_str("}\n\n");
}

fn type_resource(
&mut self,
id: TypeId,
name: &str,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_resource(&mut self, id: TypeId, name: &str, _docs: &Docs) {
let type_name = self.type_name(name, true);
let private_type_name = type_name.to_snake_case();
// for imports, generate a `int32` type for resource handle representation.
Expand Down Expand Up @@ -1166,13 +1155,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
};
}

fn type_flags(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
name: &str,
flags: &wit_bindgen_core::wit_parser::Flags,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_flags(&mut self, _id: TypeId, name: &str, flags: &Flags, _docs: &Docs) {
let name = self.type_name(name, true);

// TODO: use flags repr to determine how many flags are needed
Expand All @@ -1198,13 +1181,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
self.src.push_str(")\n\n");
}

fn type_tuple(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
name: &str,
tuple: &wit_bindgen_core::wit_parser::Tuple,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_tuple(&mut self, _id: TypeId, name: &str, tuple: &Tuple, _docs: &Docs) {
let name = self.type_name(name, true);
self.src.push_str(&format!("type {name} struct {{\n",));
for (i, case) in tuple.types.iter().enumerate() {
Expand All @@ -1214,13 +1191,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
self.src.push_str("}\n\n");
}

fn type_variant(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
name: &str,
variant: &wit_bindgen_core::wit_parser::Variant,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_variant(&mut self, _id: TypeId, name: &str, variant: &Variant, _docs: &Docs) {
let name = self.type_name(name, true);
// TODO: use variant's tag to determine how many cases are needed
// this will help to optmize the Kind type.
Expand Down Expand Up @@ -1251,33 +1222,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
}
}

fn type_option(
&mut self,
id: wit_bindgen_core::wit_parser::TypeId,
_name: &str,
_payload: &wit_bindgen_core::wit_parser::Type,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
self.get_ty(&Type::Id(id));
}

fn type_result(
&mut self,
id: wit_bindgen_core::wit_parser::TypeId,
_name: &str,
_result: &wit_bindgen_core::wit_parser::Result_,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
self.get_ty(&Type::Id(id));
}

fn type_enum(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
name: &str,
enum_: &wit_bindgen_core::wit_parser::Enum,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_enum(&mut self, _id: TypeId, name: &str, enum_: &Enum, _docs: &Docs) {
let name = self.type_name(name, true);
// TODO: use variant's tag to determine how many cases are needed
// this will help to optmize the Kind type.
Expand All @@ -1302,37 +1247,25 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
}
}

fn type_alias(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
name: &str,
ty: &wit_bindgen_core::wit_parser::Type,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_alias(&mut self, _id: TypeId, name: &str, ty: &Type, _docs: &Docs) {
let name = self.type_name(name, true);
let ty = self.get_ty(ty);
self.src.push_str(&format!("type {name} = {ty}\n"));
}

fn type_list(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
name: &str,
ty: &wit_bindgen_core::wit_parser::Type,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
let name = self.type_name(name, true);
let ty = self.get_ty(ty);
self.src.push_str(&format!("type {name} = {ty}\n"));
fn type_list(&mut self, _id: TypeId, _name: &str, _ty: &Type, _docs: &Docs) {
// no impl since these types are generated as anonymous types
}

fn type_builtin(
&mut self,
_id: wit_bindgen_core::wit_parser::TypeId,
_name: &str,
_ty: &wit_bindgen_core::wit_parser::Type,
_docs: &wit_bindgen_core::wit_parser::Docs,
) {
fn type_option(&mut self, _id: TypeId, _name: &str, _payload: &Type, _docs: &Docs) {
// no impl since these types are generated as anonymous types
}

fn type_result(&mut self, _id: TypeId, _name: &str, _result: &Result_, _docs: &Docs) {
// no impl since these types are generated as anonymous types
}

fn type_builtin(&mut self, _id: TypeId, _name: &str, _ty: &Type, _docs: &Docs) {
todo!("type_builtin")
}
}
2 changes: 1 addition & 1 deletion crates/go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::mem;
use std::process::Stdio;

use anyhow::Result;
use heck::{ToKebabCase, ToSnakeCase};
use heck::ToSnakeCase;
use wit_bindgen_c::imported_types_used_by_exported_interfaces;
use wit_bindgen_core::wit_parser::{
Function, InterfaceId, LiveTypes, Resolve, SizeAlign, Type, TypeId, WorldId, WorldKey,
Expand Down

0 comments on commit 90a1e54

Please sign in to comment.