Skip to content

Commit

Permalink
pulley: Remove unwrap_uninhabited helper function
Browse files Browse the repository at this point in the history
No longer needed on our MSRV any more.
  • Loading branch information
alexcrichton committed Feb 4, 2025
1 parent 0e05600 commit 5b80572
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
8 changes: 0 additions & 8 deletions pulley/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,6 @@ macro_rules! define_extended_decoder {
}
for_each_extended_op!(define_extended_decoder);

/// Unwrap a `Result<T, Uninhabited>`.
/// Always succeeds, since `Uninhabited` is uninhabited.
pub fn unwrap_uninhabited<T>(res: Result<T, Uninhabited>) -> T {
match res {
Ok(ok) => ok,
}
}

/// Functions for decoding the operands of an instruction, assuming the opcode
/// has already been decoded.
pub mod operands {
Expand Down
2 changes: 1 addition & 1 deletion pulley/src/interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ impl OpVisitor for Interpreter<'_> {
// Decode the `PcRelOffset` without tampering with `self.pc` as the
// jump is relative to `self.pc`.
let mut tmp = self.pc;
let rel = unwrap_uninhabited(PcRelOffset::decode(&mut tmp));
let Ok(rel) = PcRelOffset::decode(&mut tmp);
let offset = isize::try_from(i32::from(rel)).unwrap();
self.pc = unsafe { self.pc.offset(offset) };
ControlFlow::Continue(())
Expand Down
7 changes: 3 additions & 4 deletions pulley/src/interp/match_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//! will probably need tweaks to make it more performant.
use super::*;
use crate::decode::unwrap_uninhabited;

impl Interpreter<'_> {
pub fn run(self) -> Done {
Expand All @@ -30,9 +29,9 @@ impl Interpreter<'_> {
//
// This will then continue indefinitely until the bytecode says it's
// done. Note that only trusted bytecode is interpreted here.
match unwrap_uninhabited(decoder.decode_one(&mut visitor)) {
ControlFlow::Continue(()) => {}
ControlFlow::Break(done) => break done,
match decoder.decode_one(&mut visitor) {
Ok(ControlFlow::Continue(())) => {}
Ok(ControlFlow::Break(done)) => break done,
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions pulley/src/interp/tail_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! at this time but doesn't actually run anywhere.
use super::*;
use crate::decode::{unwrap_uninhabited, ExtendedOpVisitor};
use crate::decode::ExtendedOpVisitor;
use crate::opcode::Opcode;
use crate::profile::ExecutingPcRef;
use crate::ExtendedOpcode;
Expand Down Expand Up @@ -90,7 +90,7 @@ fn dispatch(
// opcode.
let mut debug = debug(state, pc, executing_pc);
debug.before_visit();
let opcode = unwrap_uninhabited(Opcode::decode(debug.bytecode()));
let Ok(opcode) = Opcode::decode(debug.bytecode());
let handler = OPCODE_HANDLER_TABLE[opcode as usize];
tail_call!(handler(debug.0.state, debug.0.pc, debug.0.executing_pc));
}
Expand All @@ -102,7 +102,7 @@ fn run_extended(
pc_ref: ExecutingPcRef<'_>,
) -> Done {
let mut i = debug(state, pc, pc_ref);
let opcode = unwrap_uninhabited(ExtendedOpcode::decode(i.bytecode()));
let Ok(opcode) = ExtendedOpcode::decode(i.bytecode());
let handler = EXTENDED_OPCODE_HANDLER_TABLE[opcode as usize];
tail_call!(handler(i.0.state, i.0.pc, i.0.executing_pc));
}
Expand Down Expand Up @@ -171,9 +171,7 @@ macro_rules! define_opcode_handler {
) -> Done {
let mut debug = debug(state, pc, executing_pc);
$(
let ($($field,)*) = unwrap_uninhabited(
crate::decode::operands::$snake_name(debug.0.bytecode())
);
let Ok(($($field,)*)) = crate::decode::operands::$snake_name(debug.0.bytecode());
)?
let result = debug.$snake_name($($($field),*)?);
debug.after_visit();
Expand Down

0 comments on commit 5b80572

Please sign in to comment.