Skip to content

Commit 32db0f4

Browse files
Removed a few #[allow(dead_code)] (rustwasm#4299)
1 parent 7ad4766 commit 32db0f4

File tree

7 files changed

+73
-82
lines changed

7 files changed

+73
-82
lines changed

crates/cli-support/src/js/binding.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -704,28 +704,34 @@ fn instruction(
704704
}
705705
}
706706

707-
Instruction::IntToWasm { input, .. } => {
707+
Instruction::Int32ToWasm => {
708708
let val = js.pop();
709-
if matches!(
710-
input,
711-
AdapterType::I64 | AdapterType::S64 | AdapterType::U64
712-
) {
713-
js.assert_bigint(&val);
709+
js.assert_number(&val);
710+
js.push(val);
711+
}
712+
Instruction::WasmToInt32 { unsigned_32 } => {
713+
let val = js.pop();
714+
if *unsigned_32 {
715+
// When converting to a JS number we need to specially handle the `u32`
716+
// case because if the high bit is set then it comes out as a negative
717+
// number, but we want to switch that to an unsigned representation.
718+
js.push(format!("{} >>> 0", val))
714719
} else {
715-
js.assert_number(&val);
720+
js.push(val)
716721
}
717-
js.push(val);
718722
}
719723

720-
// When converting to a JS number we need to specially handle the `u32`
721-
// case because if the high bit is set then it comes out as a negative
722-
// number, but we want to switch that to an unsigned representation.
723-
Instruction::WasmToInt { output, .. } => {
724+
Instruction::Int64ToWasm => {
724725
let val = js.pop();
725-
match output {
726-
AdapterType::U32 | AdapterType::NonNull => js.push(format!("{} >>> 0", val)),
727-
AdapterType::U64 => js.push(format!("BigInt.asUintN(64, {val})")),
728-
_ => js.push(val),
726+
js.assert_bigint(&val);
727+
js.push(val);
728+
}
729+
Instruction::WasmToInt64 { unsigned } => {
730+
let val = js.pop();
731+
if *unsigned {
732+
js.push(format!("BigInt.asUintN(64, {val})"))
733+
} else {
734+
js.push(val)
729735
}
730736
}
731737

@@ -765,7 +771,7 @@ fn instruction(
765771
js.push(wasm_to_string_enum(name, &index))
766772
}
767773

768-
Instruction::OptionWasmToStringEnum { name, .. } => {
774+
Instruction::OptionWasmToStringEnum { name } => {
769775
// Since hole is currently variant_count+1 and the lookup is
770776
// ["a","b","c"][index], the lookup will implicitly return map
771777
// the hole to undefined, because OOB indexes will return undefined.

crates/cli-support/src/js/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::descriptor::VectorKind;
22
use crate::intrinsic::Intrinsic;
33
use crate::wit::{
4-
Adapter, AdapterId, AdapterJsImportKind, AdapterType, AuxExportedMethodKind, AuxReceiverKind,
5-
AuxStringEnum, AuxValue,
4+
Adapter, AdapterId, AdapterJsImportKind, AuxExportedMethodKind, AuxReceiverKind, AuxStringEnum,
5+
AuxValue,
66
};
77
use crate::wit::{AdapterKind, Instruction, InstructionData};
88
use crate::wit::{AuxEnum, AuxExport, AuxExportKind, AuxImport, AuxStruct};
@@ -3119,16 +3119,14 @@ __wbg_set_wasm(wasm);"
31193119

31203120
// Conversions to Wasm integers are always supported since
31213121
// they're coerced into i32/f32/f64 appropriately.
3122-
IntToWasm { .. } => {}
3122+
Int32ToWasm => {}
3123+
Int64ToWasm => {}
31233124

3124-
// Converts from Wasm to JS, however, only supports most
3125-
// integers. Converting into a u32 isn't supported because we
3125+
// Converting into a u32 isn't supported because we
31263126
// need to generate glue to change the sign.
3127-
WasmToInt {
3128-
output: AdapterType::U32,
3129-
..
3130-
} => return false,
3131-
WasmToInt { .. } => {}
3127+
WasmToInt32 { unsigned_32: false } => {}
3128+
// A Wasm `i64` is already a signed JS BigInt, so no glue needed.
3129+
WasmToInt64 { unsigned: false } => {}
31323130

31333131
// JS spec automatically coerces boolean values to i32 of 0 or 1
31343132
// depending on true/false
@@ -3279,7 +3277,6 @@ __wbg_set_wasm(wasm);"
32793277
dtor,
32803278
mutable,
32813279
adapter,
3282-
nargs: _,
32833280
} => {
32843281
assert!(kind == AdapterJsImportKind::Normal);
32853282
assert!(!variadic);

crates/cli-support/src/wit/incoming.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ impl InstructionBuilder<'_, '_> {
4343
}
4444

4545
fn _incoming(&mut self, arg: &Descriptor) -> Result<(), Error> {
46-
use walrus::ValType as WasmVT;
4746
match arg {
4847
Descriptor::Boolean => {
4948
self.instruction(
@@ -82,14 +81,14 @@ impl InstructionBuilder<'_, '_> {
8281
&[AdapterType::I32],
8382
);
8483
}
85-
Descriptor::I8 => self.number(AdapterType::S8, WasmVT::I32),
86-
Descriptor::U8 => self.number(AdapterType::U8, WasmVT::I32),
87-
Descriptor::I16 => self.number(AdapterType::S16, WasmVT::I32),
88-
Descriptor::U16 => self.number(AdapterType::U16, WasmVT::I32),
89-
Descriptor::I32 => self.number(AdapterType::S32, WasmVT::I32),
90-
Descriptor::U32 => self.number(AdapterType::U32, WasmVT::I32),
91-
Descriptor::I64 => self.number(AdapterType::S64, WasmVT::I64),
92-
Descriptor::U64 => self.number(AdapterType::U64, WasmVT::I64),
84+
Descriptor::I8 => self.number_i32(AdapterType::S8),
85+
Descriptor::U8 => self.number_i32(AdapterType::U8),
86+
Descriptor::I16 => self.number_i32(AdapterType::S16),
87+
Descriptor::U16 => self.number_i32(AdapterType::U16),
88+
Descriptor::I32 => self.number_i32(AdapterType::S32),
89+
Descriptor::U32 => self.number_i32(AdapterType::U32),
90+
Descriptor::I64 => self.number_i64(AdapterType::S64),
91+
Descriptor::U64 => self.number_i64(AdapterType::U64),
9392
Descriptor::I128 => {
9493
self.instruction(
9594
&[AdapterType::S128],
@@ -115,10 +114,7 @@ impl InstructionBuilder<'_, '_> {
115114
Descriptor::Enum { name, .. } => {
116115
self.instruction(
117116
&[AdapterType::Enum(name.clone())],
118-
Instruction::IntToWasm {
119-
input: AdapterType::U32,
120-
output: ValType::I32,
121-
},
117+
Instruction::Int32ToWasm,
122118
&[AdapterType::I32],
123119
);
124120
},
@@ -470,12 +466,11 @@ impl InstructionBuilder<'_, '_> {
470466
self.output.extend_from_slice(outputs);
471467
}
472468

473-
fn number(&mut self, input: AdapterType, output: walrus::ValType) {
474-
let instr = Instruction::IntToWasm {
475-
input: input.clone(),
476-
output,
477-
};
478-
self.instruction(&[input], instr, &[AdapterType::from_wasm(output).unwrap()]);
469+
fn number_i32(&mut self, input: AdapterType) {
470+
self.instruction(&[input], Instruction::Int32ToWasm, &[AdapterType::I32]);
471+
}
472+
fn number_i64(&mut self, input: AdapterType) {
473+
self.instruction(&[input], Instruction::Int64ToWasm, &[AdapterType::I64]);
479474
}
480475

481476
fn in_option_native(&mut self, wasm: ValType) {

crates/cli-support/src/wit/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ impl<'a> Context<'a> {
197197
// aren't present in the signature but are present in the wasm
198198
// signature.
199199
let mut function = descriptor.function.clone();
200-
let nargs = function.arguments.len();
201200
function.arguments.insert(0, Descriptor::I32);
202201
function.arguments.insert(0, Descriptor::I32);
203202
let adapter = self.table_element_adapter(descriptor.shim_idx, function)?;
@@ -206,7 +205,6 @@ impl<'a> Context<'a> {
206205
AuxImport::Closure {
207206
dtor: descriptor.dtor_idx,
208207
mutable: descriptor.mutable,
209-
nargs,
210208
adapter,
211209
},
212210
);

crates/cli-support/src/wit/nonstandard.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,12 @@ pub enum AuxImport {
241241
/// This import is intended to manufacture a JS closure with the given
242242
/// signature and then return that back to Rust.
243243
Closure {
244-
mutable: bool, // whether or not this was a `FnMut` closure
245-
dtor: u32, // table element index of the destructor function
246-
adapter: AdapterId, // the adapter which translates the types for this closure
247-
#[allow(dead_code)]
248-
nargs: usize,
244+
/// whether or not this was a `FnMut` closure
245+
mutable: bool,
246+
/// table element index of the destructor function
247+
dtor: u32,
248+
/// the adapter which translates the types for this closure
249+
adapter: AdapterId,
249250
},
250251

251252
/// This import is expected to be a shim that simply calls the `foo` method

crates/cli-support/src/wit/outgoing.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,10 @@ impl InstructionBuilder<'_, '_> {
316316
&[AdapterType::Enum(name.clone()).option()],
317317
);
318318
}
319-
Descriptor::StringEnum { name, hole, .. } => {
319+
Descriptor::StringEnum { name, .. } => {
320320
self.instruction(
321321
&[AdapterType::I32],
322-
Instruction::OptionWasmToStringEnum {
323-
name: name.clone(),
324-
hole: *hole,
325-
},
322+
Instruction::OptionWasmToStringEnum { name: name.clone() },
326323
&[AdapterType::StringEnum(name.clone()).option()],
327324
);
328325
}
@@ -554,14 +551,6 @@ impl InstructionBuilder<'_, '_> {
554551
Ok(())
555552
}
556553

557-
fn outgoing_i32(&mut self, output: AdapterType) {
558-
let instr = Instruction::WasmToInt {
559-
input: walrus::ValType::I32,
560-
output: output.clone(),
561-
};
562-
self.instruction(&[AdapterType::I32], instr, &[output]);
563-
}
564-
565554
fn outgoing_string_enum(&mut self, name: &str) {
566555
self.instruction(
567556
&[AdapterType::I32],
@@ -572,10 +561,15 @@ impl InstructionBuilder<'_, '_> {
572561
);
573562
}
574563

564+
fn outgoing_i32(&mut self, output: AdapterType) {
565+
let instr = Instruction::WasmToInt32 {
566+
unsigned_32: output == AdapterType::U32 || output == AdapterType::NonNull,
567+
};
568+
self.instruction(&[AdapterType::I32], instr, &[output]);
569+
}
575570
fn outgoing_i64(&mut self, output: AdapterType) {
576-
let instr = Instruction::WasmToInt {
577-
input: walrus::ValType::I64,
578-
output: output.clone(),
571+
let instr = Instruction::WasmToInt64 {
572+
unsigned: output == AdapterType::U64,
579573
};
580574
self.instruction(&[AdapterType::I64], instr, &[output]);
581575
}

crates/cli-support/src/wit/standard.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,19 @@ pub enum Instruction {
137137
size: u32,
138138
},
139139

140-
/// Pops a typed integer (`u8`, `s16`, etc.) and pushes a plain Wasm `i32` or `i64` equivalent.
141-
IntToWasm {
142-
input: AdapterType,
143-
#[allow(dead_code)]
144-
output: walrus::ValType,
140+
/// Pops a 32/16/8-bit integer (`u8`, `s16`, etc.) and pushes a Wasm `i32`.
141+
Int32ToWasm,
142+
/// Pops a Wasm `i32` and pushes a 32-bit integer.
143+
WasmToInt32 {
144+
/// Whether the integer represents an unsigned 32-bit value.
145+
unsigned_32: bool,
145146
},
146-
/// Pops a Wasm `i32` or `i64` and pushes a typed integer (`u8`, `s16`, etc.) equivalent.
147-
WasmToInt {
148-
#[allow(dead_code)]
149-
input: walrus::ValType,
150-
output: AdapterType,
147+
148+
/// Pops a 64-bit integer and pushes a Wasm `i64`.
149+
Int64ToWasm,
150+
/// Pops a Wasm `i64` and pushes a 64-bit integer.
151+
WasmToInt64 {
152+
unsigned: bool,
151153
},
152154

153155
/// Pops a 128-bit integer and pushes 2 Wasm 64-bit ints.
@@ -169,8 +171,6 @@ pub enum Instruction {
169171

170172
OptionWasmToStringEnum {
171173
name: String,
172-
#[allow(dead_code)]
173-
hole: u32,
174174
},
175175

176176
/// pops a string and pushes the enum variant as an `i32`

0 commit comments

Comments
 (0)