Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: minor improve and remove unused traits impls for f32/f64 #543

Merged
merged 5 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions crates/core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ impl FromValue for bool {
impl FromValue for i8 {
#[inline]
fn from_value(val: Value) -> Option<Self> {
let min = i32::from(i8::min_value());
let max = i32::from(i8::max_value());
let min = i32::from(i8::MIN);
let max = i32::from(i8::MAX);
match val {
Value::I32(val) if min <= val && val <= max => Some(val as i8),
_ => None,
Expand All @@ -431,8 +431,8 @@ impl FromValue for i8 {
impl FromValue for i16 {
#[inline]
fn from_value(val: Value) -> Option<Self> {
let min = i32::from(i16::min_value());
let max = i32::from(i16::max_value());
let min = i32::from(i16::MIN);
let max = i32::from(i16::MAX);
match val {
Value::I32(val) if min <= val && val <= max => Some(val as i16),
_ => None,
Expand All @@ -446,8 +446,8 @@ impl FromValue for i16 {
impl FromValue for u8 {
#[inline]
fn from_value(val: Value) -> Option<Self> {
let min = i32::from(u8::min_value());
let max = i32::from(u8::max_value());
let min = i32::from(u8::MIN);
let max = i32::from(u8::MAX);
match val {
Value::I32(val) if min <= val && val <= max => Some(val as u8),
_ => None,
Expand All @@ -461,8 +461,8 @@ impl FromValue for u8 {
impl FromValue for u16 {
#[inline]
fn from_value(val: Value) -> Option<Self> {
let min = i32::from(u16::min_value());
let max = i32::from(u16::max_value());
let min = i32::from(u16::MIN);
let max = i32::from(u16::MAX);
match val {
Value::I32(val) if min <= val && val <= max => Some(val as u16),
_ => None,
Expand Down Expand Up @@ -503,10 +503,6 @@ impl_wrap_into!(i64, i16);
impl_wrap_into!(i64, i32);
impl_wrap_into!(i64, f32, F32);
impl_wrap_into!(u64, f32, F32);
// Casting from an f64 to an f32 will produce the closest possible value (rounding strategy unspecified)
// NOTE: currently this will cause Undefined Behavior if the value is finite but larger or smaller than the
// largest or smallest finite value representable by f32. This is a bug and will be fixed.
impl_wrap_into!(f64, f32);

// Casting to self
impl_wrap_into!(i32, i32);
Expand Down Expand Up @@ -616,13 +612,6 @@ impl_extend_into!(u16, i64);
impl_extend_into!(i32, i64);
impl_extend_into!(u32, i64);
impl_extend_into!(u32, u64);
impl_extend_into!(i32, f32);
impl_extend_into!(i32, f64);
impl_extend_into!(u32, f32);
impl_extend_into!(u32, f64);
impl_extend_into!(i64, f64);
impl_extend_into!(u64, f64);
impl_extend_into!(f32, f64);

impl_extend_into!(i32, f32, F32);
impl_extend_into!(i32, f64, F64);
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/module/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl GlobalIdx {
pub struct Global {
/// The type of the global variable.
global_type: GlobalType,
/// The initial value of the global variabel.
/// The initial value of the global variable.
///
/// # Note
///
Expand Down
26 changes: 13 additions & 13 deletions crates/wasmi/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Module {
/// # Errors
///
/// - If the `stream` cannot be decoded into a valid Wasm module.
/// - If unsupported Wasm proposals are encounterd.
/// - If unsupported Wasm proposals are encountered.
pub fn new(engine: &Engine, stream: impl Read) -> Result<Self, Error> {
parse(engine, stream).map_err(Into::into)
}
Expand Down Expand Up @@ -238,10 +238,6 @@ pub struct ModuleImportsIter<'a> {
impl<'a> Iterator for ModuleImportsIter<'a> {
type Item = ModuleImport<'a>;

fn size_hint(&self) -> (usize, Option<usize>) {
self.names.size_hint()
}

fn next(&mut self) -> Option<Self::Item> {
let import = match self.names.next() {
None => return None,
Expand Down Expand Up @@ -274,6 +270,10 @@ impl<'a> Iterator for ModuleImportsIter<'a> {
};
Some(import)
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.names.size_hint()
}
}

impl<'a> ExactSizeIterator for ModuleImportsIter<'a> {
Expand Down Expand Up @@ -376,15 +376,15 @@ pub struct InternalFuncsIter<'a> {
impl<'a> Iterator for InternalFuncsIter<'a> {
type Item = (DedupFuncType, FuncBody);

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}

fn next(&mut self) -> Option<Self::Item> {
self.iter
.next()
.map(|(func_type, func_body)| (*func_type, *func_body))
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

impl<'a> ExactSizeIterator for InternalFuncsIter<'a> {
Expand All @@ -402,13 +402,13 @@ pub struct InternalGlobalsIter<'a> {
impl<'a> Iterator for InternalGlobalsIter<'a> {
type Item = (&'a GlobalType, &'a InitExpr);

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}

fn next(&mut self) -> Option<Self::Item> {
self.iter.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

impl<'a> ExactSizeIterator for InternalGlobalsIter<'a> {
Expand Down