Skip to content

Commit 956f471

Browse files
authored
Use num_enum crate for oparg types (RustPython#6980)
* Use `num_enum` crate for oparg types * Fix doctest * Make opargs `#[repr(u8)]` * BuildSliceArgCount optimized
1 parent 19db8d0 commit 956f471

4 files changed

Lines changed: 335 additions & 335 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/compiler-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bitflags = { workspace = true }
1717
itertools = { workspace = true }
1818
malachite-bigint = { workspace = true }
1919
num-complex = { workspace = true }
20+
num_enum = { workspace = true }
2021

2122
lz4_flex = "0.12"
2223

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ impl<T: OpArgType> Arg<T> {
12491249

12501250
#[inline]
12511251
pub fn new(arg: T) -> (Self, OpArg) {
1252-
(Self(PhantomData), OpArg(arg.to_op_arg()))
1252+
(Self(PhantomData), OpArg(arg.into()))
12531253
}
12541254

12551255
#[inline]
@@ -1267,15 +1267,15 @@ impl<T: OpArgType> Arg<T> {
12671267

12681268
#[inline(always)]
12691269
pub fn try_get(self, arg: OpArg) -> Result<T, MarshalError> {
1270-
T::from_op_arg(arg.0)
1270+
T::try_from(arg.0).map_err(|_| MarshalError::InvalidBytecode)
12711271
}
12721272

12731273
/// # Safety
12741274
/// T::from_op_arg(self) must succeed
12751275
#[inline(always)]
12761276
pub unsafe fn get_unchecked(self, arg: OpArg) -> T {
12771277
// SAFETY: requirements forwarded from caller
1278-
unsafe { T::from_op_arg(arg.0).unwrap_unchecked() }
1278+
unsafe { T::try_from(arg.0).unwrap_unchecked() }
12791279
}
12801280
}
12811281

0 commit comments

Comments
 (0)