Skip to content

Commit 6e260af

Browse files
authored
Remove support for usize and char8 (#197)
Further iteration from #195 and dropping more features that are only needed for `*.witx`, the `usize` and `char8` types were only added for backcompat with witx itself.
1 parent 4341162 commit 6e260af

File tree

17 files changed

+27
-95
lines changed

17 files changed

+27
-95
lines changed

crates/gen-c/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,8 @@ impl C {
223223
Type::S32 => self.src.h("int32_t"),
224224
Type::U64 => self.src.h("uint64_t"),
225225
Type::S64 => self.src.h("int64_t"),
226-
Type::CChar => self.src.h("char"),
227226
Type::F32 => self.src.h("float"),
228227
Type::F64 => self.src.h("double"),
229-
Type::Usize => self.src.h("size_t"),
230228
Type::Handle(id) => {
231229
self.print_namespace(iface);
232230
self.src.h(&iface.resources[*id].name.to_snake_case());
@@ -280,10 +278,8 @@ impl C {
280278
Type::S32 => self.src.h("s32"),
281279
Type::U64 => self.src.h("u64"),
282280
Type::S64 => self.src.h("s64"),
283-
Type::CChar => self.src.h("char"),
284281
Type::F32 => self.src.h("f32"),
285282
Type::F64 => self.src.h("f64"),
286-
Type::Usize => self.src.h("usize"),
287283
Type::Handle(id) => self.src.h(&iface.resources[*id].name.to_snake_case()),
288284
Type::Id(id) => {
289285
let ty = &iface.types[*id];
@@ -1297,10 +1293,8 @@ impl Bindgen for FunctionBindgen<'_> {
12971293
Instruction::U32FromI32 => results.push(format!("(uint32_t) ({})", operands[0])),
12981294
Instruction::S32FromI32 | Instruction::S64FromI64 => results.push(operands[0].clone()),
12991295
Instruction::U64FromI64 => results.push(format!("(uint64_t) ({})", operands[0])),
1300-
Instruction::UsizeFromI32 => results.push(format!("(size_t) ({})", operands[0])),
13011296

1302-
Instruction::I32FromUsize
1303-
| Instruction::I32FromU8
1297+
Instruction::I32FromU8
13041298
| Instruction::I32FromS8
13051299
| Instruction::I32FromU16
13061300
| Instruction::I32FromS16

crates/gen-js/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ impl Js {
123123

124124
fn array_ty(&self, iface: &Interface, ty: &Type) -> Option<&'static str> {
125125
match ty {
126-
Type::U8 | Type::CChar => Some("Uint8Array"),
126+
Type::U8 => Some("Uint8Array"),
127127
Type::S8 => Some("Int8Array"),
128128
Type::U16 => Some("Uint16Array"),
129129
Type::S16 => Some("Int16Array"),
130-
Type::U32 | Type::Usize => Some("Uint32Array"),
130+
Type::U32 => Some("Uint32Array"),
131131
Type::S32 => Some("Int32Array"),
132132
Type::U64 => Some("BigUint64Array"),
133133
Type::S64 => Some("BigInt64Array"),
@@ -145,12 +145,10 @@ impl Js {
145145
fn print_ty(&mut self, iface: &Interface, ty: &Type) {
146146
match ty {
147147
Type::U8
148-
| Type::CChar
149148
| Type::S8
150149
| Type::U16
151150
| Type::S16
152151
| Type::U32
153-
| Type::Usize
154152
| Type::S32
155153
| Type::F32
156154
| Type::F64 => self.src.ts("number"),
@@ -1228,7 +1226,7 @@ impl Bindgen for FunctionBindgen<'_> {
12281226
Instruction::S16FromI32 => self.clamp_guest(results, operands, i16::MIN, i16::MAX),
12291227
// Use `>>>0` to ensure the bits of the number are treated as
12301228
// unsigned.
1231-
Instruction::U32FromI32 | Instruction::UsizeFromI32 => {
1229+
Instruction::U32FromI32 => {
12321230
results.push(format!("{} >>> 0", operands[0]));
12331231
}
12341232
// All bigints coming from wasm are treated as signed, so convert
@@ -1246,7 +1244,7 @@ impl Bindgen for FunctionBindgen<'_> {
12461244
Instruction::I32FromS8 => self.clamp_host(results, operands, i8::MIN, i8::MAX),
12471245
Instruction::I32FromU16 => self.clamp_host(results, operands, u16::MIN, u16::MAX),
12481246
Instruction::I32FromS16 => self.clamp_host(results, operands, i16::MIN, i16::MAX),
1249-
Instruction::I32FromU32 | Instruction::I32FromUsize => {
1247+
Instruction::I32FromU32 => {
12501248
self.clamp_host(results, operands, u32::MIN, u32::MAX);
12511249
}
12521250
Instruction::I32FromS32 => self.clamp_host(results, operands, i32::MIN, i32::MAX),

crates/gen-markdown/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ impl Markdown {
4646
Type::F32 => self.src.push_str("`f32`"),
4747
Type::F64 => self.src.push_str("`f64`"),
4848
Type::Char => self.src.push_str("`char`"),
49-
Type::CChar => self.src.push_str("`c_char`"),
50-
Type::Usize => self.src.push_str("`usize`"),
5149
Type::Handle(id) => {
5250
self.src.push_str("handle<");
5351
self.src.push_str(&iface.resources[*id].name);

crates/gen-rust-wasm/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ impl RustGenerator for RustWasm {
123123
&mut self.types
124124
}
125125

126-
fn print_usize(&mut self) {
127-
self.src.push_str("usize");
128-
}
129-
130126
fn print_pointer(&mut self, iface: &Interface, const_: bool, ty: &Type) {
131127
self.push_str("*");
132128
if const_ {
@@ -858,11 +854,9 @@ impl Bindgen for FunctionBindgen<'_> {
858854
let s = operands.pop().unwrap();
859855
results.push(format!("wit_bindgen_rust::rt::as_i64({})", s));
860856
}
861-
Instruction::I32FromUsize
862-
| Instruction::I32FromChar
857+
Instruction::I32FromChar
863858
| Instruction::I32FromU8
864859
| Instruction::I32FromS8
865-
| Instruction::I32FromChar8
866860
| Instruction::I32FromU16
867861
| Instruction::I32FromS16
868862
| Instruction::I32FromU32
@@ -886,12 +880,11 @@ impl Bindgen for FunctionBindgen<'_> {
886880
results.push(operands.pop().unwrap());
887881
}
888882
Instruction::S8FromI32 => top_as("i8"),
889-
Instruction::Char8FromI32 | Instruction::U8FromI32 => top_as("u8"),
883+
Instruction::U8FromI32 => top_as("u8"),
890884
Instruction::S16FromI32 => top_as("i16"),
891885
Instruction::U16FromI32 => top_as("u16"),
892886
Instruction::U32FromI32 => top_as("u32"),
893887
Instruction::U64FromI64 => top_as("u64"),
894-
Instruction::UsizeFromI32 => top_as("usize"),
895888
Instruction::CharFromI32 => {
896889
if unchecked {
897890
results.push(format!(

crates/gen-rust/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub trait RustGenerator {
1414
fn push_str(&mut self, s: &str);
1515
fn info(&self, ty: TypeId) -> TypeInfo;
1616
fn types_mut(&mut self) -> &mut Types;
17-
fn print_usize(&mut self);
1817
fn print_pointer(&mut self, iface: &Interface, const_: bool, ty: &Type);
1918
fn print_borrowed_slice(
2019
&mut self,
@@ -200,10 +199,8 @@ pub trait RustGenerator {
200199
}
201200

202201
Type::U8 => self.push_str("u8"),
203-
Type::CChar => self.push_str("u8"),
204202
Type::U16 => self.push_str("u16"),
205203
Type::U32 => self.push_str("u32"),
206-
Type::Usize => self.print_usize(),
207204
Type::U64 => self.push_str("u64"),
208205
Type::S8 => self.push_str("i8"),
209206
Type::S16 => self.push_str("i16"),

crates/gen-spidermonkey/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,8 +1475,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
14751475
abi::Instruction::I32FromS16 => todo!(),
14761476
abi::Instruction::I32FromU8 => todo!(),
14771477
abi::Instruction::I32FromS8 => todo!(),
1478-
abi::Instruction::I32FromUsize => todo!(),
1479-
abi::Instruction::I32FromChar8 => todo!(),
14801478
abi::Instruction::F32FromIf32 => todo!(),
14811479
abi::Instruction::F64FromIf64 => todo!(),
14821480
abi::Instruction::S8FromI32 => todo!(),
@@ -1505,8 +1503,6 @@ impl abi::Bindgen for Bindgen<'_, '_> {
15051503
abi::Instruction::CharFromI32 => todo!(),
15061504
abi::Instruction::If32FromF32 => todo!(),
15071505
abi::Instruction::If64FromF64 => todo!(),
1508-
abi::Instruction::Char8FromI32 => todo!(),
1509-
abi::Instruction::UsizeFromI32 => todo!(),
15101506
abi::Instruction::I32FromBorrowedHandle { ty: _ } => todo!(),
15111507
abi::Instruction::I32FromOwnedHandle { ty: _ } => todo!(),
15121508
abi::Instruction::HandleOwnedFromI32 { ty: _ } => todo!(),

crates/gen-wasmtime-py/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,7 @@ impl WasmtimePy {
377377
| Type::U32
378378
| Type::S32
379379
| Type::U64
380-
| Type::S64
381-
| Type::Usize
382-
| Type::CChar => self.src.push_str("int"),
380+
| Type::S64 => self.src.push_str("int"),
383381
Type::F32 | Type::F64 => self.src.push_str("float"),
384382
Type::Char => self.src.push_str("str"),
385383
Type::Handle(id) => {
@@ -493,11 +491,11 @@ impl WasmtimePy {
493491

494492
fn array_ty(&self, iface: &Interface, ty: &Type) -> Option<&'static str> {
495493
match ty {
496-
Type::U8 | Type::CChar => Some("c_uint8"),
494+
Type::U8 => Some("c_uint8"),
497495
Type::S8 => Some("c_int8"),
498496
Type::U16 => Some("c_uint16"),
499497
Type::S16 => Some("c_int16"),
500-
Type::U32 | Type::Usize => Some("c_uint32"),
498+
Type::U32 => Some("c_uint32"),
501499
Type::S32 => Some("c_int32"),
502500
Type::U64 => Some("c_uint64"),
503501
Type::S64 => Some("c_int64"),
@@ -1346,7 +1344,7 @@ impl Bindgen for FunctionBindgen<'_> {
13461344
Instruction::U16FromI32 => self.clamp(results, operands, u16::MIN, u16::MAX),
13471345
Instruction::S16FromI32 => self.clamp(results, operands, i16::MIN, i16::MAX),
13481346
// Ensure the bits of the number are treated as unsigned.
1349-
Instruction::U32FromI32 | Instruction::UsizeFromI32 => {
1347+
Instruction::U32FromI32 => {
13501348
results.push(format!("{} & 0xffffffff", operands[0]));
13511349
}
13521350
// All bigints coming from wasm are treated as signed, so convert
@@ -1367,7 +1365,7 @@ impl Bindgen for FunctionBindgen<'_> {
13671365
Instruction::I32FromU16 => self.clamp(results, operands, u16::MIN, u16::MAX),
13681366
Instruction::I32FromS16 => self.clamp(results, operands, i16::MIN, i16::MAX),
13691367
// TODO: need to do something to get this to be represented as signed?
1370-
Instruction::I32FromU32 | Instruction::I32FromUsize => {
1368+
Instruction::I32FromU32 => {
13711369
self.clamp(results, operands, u32::MIN, u32::MAX);
13721370
}
13731371
Instruction::I32FromS32 => self.clamp(results, operands, i32::MIN, i32::MAX),

crates/gen-wasmtime/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ impl RustGenerator for Wasmtime {
266266
&mut self.types
267267
}
268268

269-
fn print_usize(&mut self) {
270-
self.src.push_str("u32");
271-
}
272-
273269
fn print_pointer(&mut self, _iface: &Interface, _const_: bool, _ty: &Type) {
274270
self.push_str("u32");
275271
}
@@ -1434,11 +1430,9 @@ impl Bindgen for FunctionBindgen<'_> {
14341430
let s = operands.pop().unwrap();
14351431
results.push(format!("wit_bindgen_wasmtime::rt::as_i64({})", s));
14361432
}
1437-
Instruction::I32FromUsize
1438-
| Instruction::I32FromChar
1433+
Instruction::I32FromChar
14391434
| Instruction::I32FromU8
14401435
| Instruction::I32FromS8
1441-
| Instruction::I32FromChar8
14421436
| Instruction::I32FromU16
14431437
| Instruction::I32FromS16
14441438
| Instruction::I32FromU32
@@ -1461,13 +1455,13 @@ impl Bindgen for FunctionBindgen<'_> {
14611455
// necessary since we could chop bits off this should be more
14621456
// forward-compatible with any future changes.
14631457
Instruction::S8FromI32 => try_from("i8", operands, results),
1464-
Instruction::Char8FromI32 | Instruction::U8FromI32 => try_from("u8", operands, results),
1458+
Instruction::U8FromI32 => try_from("u8", operands, results),
14651459
Instruction::S16FromI32 => try_from("i16", operands, results),
14661460
Instruction::U16FromI32 => try_from("u16", operands, results),
14671461

14681462
// Casts of the same bit width simply use `as` since we're just
14691463
// reinterpreting the bits already there.
1470-
Instruction::U32FromI32 | Instruction::UsizeFromI32 => top_as("u32"),
1464+
Instruction::U32FromI32 => top_as("u32"),
14711465
Instruction::U64FromI64 => top_as("u64"),
14721466

14731467
Instruction::CharFromI32 => {

crates/parser/src/abi.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ def_instruction! {
203203
I32FromU8 : [1] => [1],
204204
/// Converts an interface type `s8` value to a wasm `i32`.
205205
I32FromS8 : [1] => [1],
206-
/// Converts a language-specific `usize` value to a wasm `i32`.
207-
I32FromUsize : [1] => [1],
208-
/// Converts a language-specific C `char` value to a wasm `i32`.
209-
I32FromChar8 : [1] => [1],
210206
/// Conversion an interface type `f32` value to a wasm `f32`.
211207
///
212208
/// This may be a noop for some implementations, but it's here in case the
@@ -252,12 +248,6 @@ def_instruction! {
252248
If32FromF32 : [1] => [1],
253249
/// Converts a native wasm `f64` to an interface type `f64`.
254250
If64FromF64 : [1] => [1],
255-
/// Converts a native wasm `i32` to a language-specific C `char`.
256-
///
257-
/// This will truncate the upper bits of the `i32`.
258-
Char8FromI32 : [1] => [1],
259-
/// Converts a native wasm `i32` to a language-specific `usize`.
260-
UsizeFromI32 : [1] => [1],
261251

262252
// Handles
263253

@@ -854,9 +844,7 @@ impl Interface {
854844
| Type::S32
855845
| Type::U32
856846
| Type::Char
857-
| Type::Handle(_)
858-
| Type::CChar
859-
| Type::Usize => result.push(WasmType::I32),
847+
| Type::Handle(_) => result.push(WasmType::I32),
860848

861849
Type::U64 | Type::S64 => result.push(WasmType::I64),
862850
Type::F32 => result.push(WasmType::F32),
@@ -1303,12 +1291,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
13031291
match *ty {
13041292
Type::S8 => self.emit(&I32FromS8),
13051293
Type::U8 => self.emit(&I32FromU8),
1306-
Type::CChar => self.emit(&I32FromChar8),
13071294
Type::S16 => self.emit(&I32FromS16),
13081295
Type::U16 => self.emit(&I32FromU16),
13091296
Type::S32 => self.emit(&I32FromS32),
13101297
Type::U32 => self.emit(&I32FromU32),
1311-
Type::Usize => self.emit(&I32FromUsize),
13121298
Type::S64 => self.emit(&I64FromS64),
13131299
Type::U64 => self.emit(&I64FromU64),
13141300
Type::Char => self.emit(&I32FromChar),
@@ -1478,12 +1464,10 @@ impl<'a, B: Bindgen> Generator<'a, B> {
14781464

14791465
match *ty {
14801466
Type::S8 => self.emit(&S8FromI32),
1481-
Type::CChar => self.emit(&Char8FromI32),
14821467
Type::U8 => self.emit(&U8FromI32),
14831468
Type::S16 => self.emit(&S16FromI32),
14841469
Type::U16 => self.emit(&U16FromI32),
14851470
Type::S32 => self.emit(&S32FromI32),
1486-
Type::Usize => self.emit(&UsizeFromI32),
14871471
Type::U32 => self.emit(&U32FromI32),
14881472
Type::S64 => self.emit(&S64FromI64),
14891473
Type::U64 => self.emit(&U64FromI64),
@@ -1617,11 +1601,9 @@ impl<'a, B: Bindgen> Generator<'a, B> {
16171601
match *ty {
16181602
// Builtin types need different flavors of storage instructions
16191603
// depending on the size of the value written.
1620-
Type::U8 | Type::S8 | Type::CChar => {
1621-
self.lower_and_emit(ty, addr, &I32Store8 { offset })
1622-
}
1604+
Type::U8 | Type::S8 => self.lower_and_emit(ty, addr, &I32Store8 { offset }),
16231605
Type::U16 | Type::S16 => self.lower_and_emit(ty, addr, &I32Store16 { offset }),
1624-
Type::U32 | Type::S32 | Type::Usize | Type::Handle(_) | Type::Char => {
1606+
Type::U32 | Type::S32 | Type::Handle(_) | Type::Char => {
16251607
self.lower_and_emit(ty, addr, &I32Store { offset })
16261608
}
16271609
Type::U64 | Type::S64 => self.lower_and_emit(ty, addr, &I64Store { offset }),
@@ -1729,11 +1711,11 @@ impl<'a, B: Bindgen> Generator<'a, B> {
17291711
use Instruction::*;
17301712

17311713
match *ty {
1732-
Type::U8 | Type::CChar => self.emit_and_lift(ty, addr, &I32Load8U { offset }),
1714+
Type::U8 => self.emit_and_lift(ty, addr, &I32Load8U { offset }),
17331715
Type::S8 => self.emit_and_lift(ty, addr, &I32Load8S { offset }),
17341716
Type::U16 => self.emit_and_lift(ty, addr, &I32Load16U { offset }),
17351717
Type::S16 => self.emit_and_lift(ty, addr, &I32Load16S { offset }),
1736-
Type::U32 | Type::S32 | Type::Char | Type::Usize | Type::Handle(_) => {
1718+
Type::U32 | Type::S32 | Type::Char | Type::Handle(_) => {
17371719
self.emit_and_lift(ty, addr, &I32Load { offset })
17381720
}
17391721
Type::U64 | Type::S64 => self.emit_and_lift(ty, addr, &I64Load { offset }),

crates/parser/src/ast.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ enum Type<'a> {
8484
F32,
8585
F64,
8686
Char,
87-
#[allow(dead_code)]
88-
Usize,
89-
#[allow(dead_code)]
90-
CChar,
9187
Handle(Id<'a>),
9288
Name(Id<'a>),
9389
List(Box<Type<'a>>),

0 commit comments

Comments
 (0)