Skip to content

Commit 90a1e54

Browse files
authored
feat(go): remove the impl of type_list as it's a anonymous type (#925)
Signed-off-by: Jiaxiao Zhou (Mossaka) <[email protected]>
1 parent 17c4589 commit 90a1e54

File tree

2 files changed

+21
-88
lines changed

2 files changed

+21
-88
lines changed

crates/go/src/interface.rs

Lines changed: 20 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use wit_bindgen_c::{
77
CTypeNameInfo,
88
};
99
use wit_bindgen_core::wit_parser::{
10-
Field, Function, FunctionKind, Handle, InterfaceId, LiveTypes, Resolve, Type, TypeDefKind,
11-
TypeId, TypeOwner, WorldKey,
10+
Docs, Enum, Field, Flags, Function, FunctionKind, Handle, InterfaceId, LiveTypes, Record,
11+
Resolve, Result_, Tuple, Type, TypeDefKind, TypeId, TypeOwner, Variant, WorldKey,
1212
};
1313
use wit_bindgen_core::{uwriteln, Direction, InterfaceGenerator as _, Source};
1414

@@ -1008,13 +1008,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
10081008
self.resolve
10091009
}
10101010

1011-
fn type_record(
1012-
&mut self,
1013-
_id: wit_bindgen_core::wit_parser::TypeId,
1014-
name: &str,
1015-
record: &wit_bindgen_core::wit_parser::Record,
1016-
_docs: &wit_bindgen_core::wit_parser::Docs,
1017-
) {
1011+
fn type_record(&mut self, _id: TypeId, name: &str, record: &Record, _docs: &Docs) {
10181012
let name = self.type_name(name, true);
10191013
self.src.push_str(&format!("type {name} struct {{\n",));
10201014
for field in record.fields.iter() {
@@ -1025,12 +1019,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
10251019
self.src.push_str("}\n\n");
10261020
}
10271021

1028-
fn type_resource(
1029-
&mut self,
1030-
id: TypeId,
1031-
name: &str,
1032-
_docs: &wit_bindgen_core::wit_parser::Docs,
1033-
) {
1022+
fn type_resource(&mut self, id: TypeId, name: &str, _docs: &Docs) {
10341023
let type_name = self.type_name(name, true);
10351024
let private_type_name = type_name.to_snake_case();
10361025
// for imports, generate a `int32` type for resource handle representation.
@@ -1166,13 +1155,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
11661155
};
11671156
}
11681157

1169-
fn type_flags(
1170-
&mut self,
1171-
_id: wit_bindgen_core::wit_parser::TypeId,
1172-
name: &str,
1173-
flags: &wit_bindgen_core::wit_parser::Flags,
1174-
_docs: &wit_bindgen_core::wit_parser::Docs,
1175-
) {
1158+
fn type_flags(&mut self, _id: TypeId, name: &str, flags: &Flags, _docs: &Docs) {
11761159
let name = self.type_name(name, true);
11771160

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

1201-
fn type_tuple(
1202-
&mut self,
1203-
_id: wit_bindgen_core::wit_parser::TypeId,
1204-
name: &str,
1205-
tuple: &wit_bindgen_core::wit_parser::Tuple,
1206-
_docs: &wit_bindgen_core::wit_parser::Docs,
1207-
) {
1184+
fn type_tuple(&mut self, _id: TypeId, name: &str, tuple: &Tuple, _docs: &Docs) {
12081185
let name = self.type_name(name, true);
12091186
self.src.push_str(&format!("type {name} struct {{\n",));
12101187
for (i, case) in tuple.types.iter().enumerate() {
@@ -1214,13 +1191,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
12141191
self.src.push_str("}\n\n");
12151192
}
12161193

1217-
fn type_variant(
1218-
&mut self,
1219-
_id: wit_bindgen_core::wit_parser::TypeId,
1220-
name: &str,
1221-
variant: &wit_bindgen_core::wit_parser::Variant,
1222-
_docs: &wit_bindgen_core::wit_parser::Docs,
1223-
) {
1194+
fn type_variant(&mut self, _id: TypeId, name: &str, variant: &Variant, _docs: &Docs) {
12241195
let name = self.type_name(name, true);
12251196
// TODO: use variant's tag to determine how many cases are needed
12261197
// this will help to optmize the Kind type.
@@ -1251,33 +1222,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
12511222
}
12521223
}
12531224

1254-
fn type_option(
1255-
&mut self,
1256-
id: wit_bindgen_core::wit_parser::TypeId,
1257-
_name: &str,
1258-
_payload: &wit_bindgen_core::wit_parser::Type,
1259-
_docs: &wit_bindgen_core::wit_parser::Docs,
1260-
) {
1261-
self.get_ty(&Type::Id(id));
1262-
}
1263-
1264-
fn type_result(
1265-
&mut self,
1266-
id: wit_bindgen_core::wit_parser::TypeId,
1267-
_name: &str,
1268-
_result: &wit_bindgen_core::wit_parser::Result_,
1269-
_docs: &wit_bindgen_core::wit_parser::Docs,
1270-
) {
1271-
self.get_ty(&Type::Id(id));
1272-
}
1273-
1274-
fn type_enum(
1275-
&mut self,
1276-
_id: wit_bindgen_core::wit_parser::TypeId,
1277-
name: &str,
1278-
enum_: &wit_bindgen_core::wit_parser::Enum,
1279-
_docs: &wit_bindgen_core::wit_parser::Docs,
1280-
) {
1225+
fn type_enum(&mut self, _id: TypeId, name: &str, enum_: &Enum, _docs: &Docs) {
12811226
let name = self.type_name(name, true);
12821227
// TODO: use variant's tag to determine how many cases are needed
12831228
// this will help to optmize the Kind type.
@@ -1302,37 +1247,25 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
13021247
}
13031248
}
13041249

1305-
fn type_alias(
1306-
&mut self,
1307-
_id: wit_bindgen_core::wit_parser::TypeId,
1308-
name: &str,
1309-
ty: &wit_bindgen_core::wit_parser::Type,
1310-
_docs: &wit_bindgen_core::wit_parser::Docs,
1311-
) {
1250+
fn type_alias(&mut self, _id: TypeId, name: &str, ty: &Type, _docs: &Docs) {
13121251
let name = self.type_name(name, true);
13131252
let ty = self.get_ty(ty);
13141253
self.src.push_str(&format!("type {name} = {ty}\n"));
13151254
}
13161255

1317-
fn type_list(
1318-
&mut self,
1319-
_id: wit_bindgen_core::wit_parser::TypeId,
1320-
name: &str,
1321-
ty: &wit_bindgen_core::wit_parser::Type,
1322-
_docs: &wit_bindgen_core::wit_parser::Docs,
1323-
) {
1324-
let name = self.type_name(name, true);
1325-
let ty = self.get_ty(ty);
1326-
self.src.push_str(&format!("type {name} = {ty}\n"));
1256+
fn type_list(&mut self, _id: TypeId, _name: &str, _ty: &Type, _docs: &Docs) {
1257+
// no impl since these types are generated as anonymous types
13271258
}
13281259

1329-
fn type_builtin(
1330-
&mut self,
1331-
_id: wit_bindgen_core::wit_parser::TypeId,
1332-
_name: &str,
1333-
_ty: &wit_bindgen_core::wit_parser::Type,
1334-
_docs: &wit_bindgen_core::wit_parser::Docs,
1335-
) {
1260+
fn type_option(&mut self, _id: TypeId, _name: &str, _payload: &Type, _docs: &Docs) {
1261+
// no impl since these types are generated as anonymous types
1262+
}
1263+
1264+
fn type_result(&mut self, _id: TypeId, _name: &str, _result: &Result_, _docs: &Docs) {
1265+
// no impl since these types are generated as anonymous types
1266+
}
1267+
1268+
fn type_builtin(&mut self, _id: TypeId, _name: &str, _ty: &Type, _docs: &Docs) {
13361269
todo!("type_builtin")
13371270
}
13381271
}

crates/go/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem;
44
use std::process::Stdio;
55

66
use anyhow::Result;
7-
use heck::{ToKebabCase, ToSnakeCase};
7+
use heck::ToSnakeCase;
88
use wit_bindgen_c::imported_types_used_by_exported_interfaces;
99
use wit_bindgen_core::wit_parser::{
1010
Function, InterfaceId, LiveTypes, Resolve, SizeAlign, Type, TypeId, WorldId, WorldKey,

0 commit comments

Comments
 (0)