From 48cc6360643e1547462f9ace6c36ce78dcab8262 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 3 Dec 2024 15:43:40 -0800 Subject: [PATCH] Rename "float32" to "f32". (#1935) The component-model type "float32" was [renamed to "f32"], so rename Wave's type to match. [renamed to "f32"]: https://github.com/WebAssembly/component-model/pull/324 --- crates/wasm-wave/src/ast.rs | 4 +-- crates/wasm-wave/src/value/convert.rs | 6 ++-- crates/wasm-wave/src/value/mod.rs | 28 ++++++++-------- crates/wasm-wave/src/value/tests.rs | 8 ++--- crates/wasm-wave/src/value/ty.rs | 6 ++-- crates/wasm-wave/src/value/wit.rs | 4 +-- crates/wasm-wave/src/wasm/ty.rs | 8 ++--- crates/wasm-wave/src/wasm/val.rs | 16 +++++----- crates/wasm-wave/src/writer.rs | 8 ++--- crates/wasm-wave/tests/nan.rs | 10 ++---- crates/wasm-wave/tests/types.wit | 4 +-- crates/wasm-wave/tests/ui/accept-floats.out | 16 +++++----- crates/wasm-wave/tests/ui/accept-floats.waves | 16 +++++----- crates/wasm-wave/tests/ui/reject-floats.out | 32 +++++++++---------- crates/wasm-wave/tests/ui/reject-floats.waves | 32 +++++++++---------- crates/wasm-wave/tests/ui/ui.wit | 10 +++--- 16 files changed, 101 insertions(+), 107 deletions(-) diff --git a/crates/wasm-wave/src/ast.rs b/crates/wasm-wave/src/ast.rs index a82c6c491a..7213394319 100644 --- a/crates/wasm-wave/src/ast.rs +++ b/crates/wasm-wave/src/ast.rs @@ -215,8 +215,8 @@ impl Node { WasmTypeKind::U16 => V::make_u16(self.as_number(src)?), WasmTypeKind::U32 => V::make_u32(self.as_number(src)?), WasmTypeKind::U64 => V::make_u64(self.as_number(src)?), - WasmTypeKind::Float32 => V::make_float32(self.as_number(src)?), - WasmTypeKind::Float64 => V::make_float64(self.as_number(src)?), + WasmTypeKind::F32 => V::make_f32(self.as_number(src)?), + WasmTypeKind::F64 => V::make_f64(self.as_number(src)?), WasmTypeKind::Char => V::make_char(self.as_char(src)?), WasmTypeKind::String => V::make_string(self.as_str(src)?), WasmTypeKind::List => self.to_wasm_list(ty, src)?, diff --git a/crates/wasm-wave/src/value/convert.rs b/crates/wasm-wave/src/value/convert.rs index f32d71704a..a4ac337ce0 100644 --- a/crates/wasm-wave/src/value/convert.rs +++ b/crates/wasm-wave/src/value/convert.rs @@ -78,8 +78,8 @@ impl_primitives!( (U16, u16), (U32, u32), (U64, u64), - (Float32, f32), - (Float64, f64), + (F32, f32), + (F64, f64), (Char, char) ); @@ -217,7 +217,7 @@ mod tests { for ty in [ Type::BOOL, Type::U8, - Type::FLOAT32, + Type::F32, Type::STRING, Type::list(Type::BOOL), Type::record([("a", Type::BOOL)]).unwrap(), diff --git a/crates/wasm-wave/src/value/mod.rs b/crates/wasm-wave/src/value/mod.rs index 1fb2cc42b9..25ce1aa96d 100644 --- a/crates/wasm-wave/src/value/mod.rs +++ b/crates/wasm-wave/src/value/mod.rs @@ -45,8 +45,8 @@ pub(super) enum ValueEnum { U32(u32), S64(i64), U64(u64), - Float32(f32), - Float64(f64), + F32(f32), + F64(f64), Char(char), String(Box), List(List), @@ -144,8 +144,8 @@ impl WasmValue for Value { ValueEnum::U16(_) => WasmTypeKind::U16, ValueEnum::U32(_) => WasmTypeKind::U32, ValueEnum::U64(_) => WasmTypeKind::U64, - ValueEnum::Float32(_) => WasmTypeKind::Float32, - ValueEnum::Float64(_) => WasmTypeKind::Float64, + ValueEnum::F32(_) => WasmTypeKind::F32, + ValueEnum::F64(_) => WasmTypeKind::F64, ValueEnum::Char(_) => WasmTypeKind::Char, ValueEnum::String(_) => WasmTypeKind::String, ValueEnum::List(_) => WasmTypeKind::List, @@ -173,14 +173,14 @@ impl WasmValue for Value { (Char, char, make_char, unwrap_char) ); - fn make_float32(val: f32) -> Self { + fn make_f32(val: f32) -> Self { let val = canonicalize_nan32(val); - Self(ValueEnum::Float32(val)) + Self(ValueEnum::F32(val)) } - fn make_float64(val: f64) -> Self { + fn make_f64(val: f64) -> Self { let val = canonicalize_nan64(val); - Self(ValueEnum::Float64(val)) + Self(ValueEnum::F64(val)) } fn make_string(val: std::borrow::Cow) -> Self { @@ -315,13 +315,13 @@ impl WasmValue for Value { Ok(Self(ValueEnum::Flags(Flags { ty, flags }))) } - fn unwrap_float32(&self) -> f32 { - let val = *unwrap_val!(&self.0, ValueEnum::Float32, "float32"); + fn unwrap_f32(&self) -> f32 { + let val = *unwrap_val!(&self.0, ValueEnum::F32, "f32"); canonicalize_nan32(val) } - fn unwrap_float64(&self) -> f64 { - let val = *unwrap_val!(&self.0, ValueEnum::Float64, "float64"); + fn unwrap_f64(&self) -> f64 { + let val = *unwrap_val!(&self.0, ValueEnum::F64, "f64"); canonicalize_nan64(val) } @@ -404,8 +404,8 @@ fn check_type2(expected: &Type, val: &Value) -> Result<(), WasmValueError> { (ValueEnum::U16(_), &Type::U16) => {} (ValueEnum::U32(_), &Type::U32) => {} (ValueEnum::U64(_), &Type::U64) => {} - (ValueEnum::Float32(_), &Type::FLOAT32) => {} - (ValueEnum::Float64(_), &Type::FLOAT64) => {} + (ValueEnum::F32(_), &Type::F32) => {} + (ValueEnum::F64(_), &Type::F64) => {} (ValueEnum::Char(_), &Type::CHAR) => {} (ValueEnum::String(_), &Type::STRING) => {} (ValueEnum::List(list), _) => { diff --git a/crates/wasm-wave/src/value/tests.rs b/crates/wasm-wave/src/value/tests.rs index 0a4dc9e8e3..ba29cd8e16 100644 --- a/crates/wasm-wave/src/value/tests.rs +++ b/crates/wasm-wave/src/value/tests.rs @@ -32,8 +32,8 @@ fn float_round_trips() { (f32::INFINITY, f64::INFINITY), (f32::NEG_INFINITY, f64::NEG_INFINITY), ] { - test_value_round_trip(Value::make_float32(float32)); - test_value_round_trip(Value::make_float64(float64)); + test_value_round_trip(Value::make_f32(float32)); + test_value_round_trip(Value::make_f64(float64)); } } @@ -130,8 +130,8 @@ fn local_ty(val: &Value) -> Type { ValueEnum::U16(_) => Type::U16, ValueEnum::U32(_) => Type::U32, ValueEnum::U64(_) => Type::U64, - ValueEnum::Float32(_) => Type::FLOAT32, - ValueEnum::Float64(_) => Type::FLOAT64, + ValueEnum::F32(_) => Type::F32, + ValueEnum::F64(_) => Type::F64, ValueEnum::Char(_) => Type::CHAR, ValueEnum::String(_) => Type::STRING, ValueEnum::List(inner) => Type(TypeEnum::List(inner.ty.clone())), diff --git a/crates/wasm-wave/src/value/ty.rs b/crates/wasm-wave/src/value/ty.rs index 5c01fa9121..8898892b4a 100644 --- a/crates/wasm-wave/src/value/ty.rs +++ b/crates/wasm-wave/src/value/ty.rs @@ -30,8 +30,8 @@ impl Type { pub const U16: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::U16))); pub const U32: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::U32))); pub const U64: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::U64))); - pub const FLOAT32: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::Float32))); - pub const FLOAT64: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::Float64))); + pub const F32: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::F32))); + pub const F64: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::F64))); pub const CHAR: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::Char))); pub const STRING: Self = Self(TypeEnum::Simple(SimpleType(WasmTypeKind::String))); @@ -139,7 +139,7 @@ const fn is_simple(kind: WasmTypeKind) -> bool { use WasmTypeKind::*; matches!( kind, - Bool | S8 | S16 | S32 | S64 | U8 | U16 | U32 | U64 | Float32 | Float64 | Char | String + Bool | S8 | S16 | S32 | S64 | U8 | U16 | U32 | U64 | F32 | F64 | Char | String ) } diff --git a/crates/wasm-wave/src/value/wit.rs b/crates/wasm-wave/src/value/wit.rs index 8d8231a710..9ac77bdfbd 100644 --- a/crates/wasm-wave/src/value/wit.rs +++ b/crates/wasm-wave/src/value/wit.rs @@ -79,8 +79,8 @@ impl<'a> TypeResolver<'a> { TypeDefKind::Type(Type::S16) => Ok(value::Type::S16), TypeDefKind::Type(Type::S32) => Ok(value::Type::S32), TypeDefKind::Type(Type::S64) => Ok(value::Type::S64), - TypeDefKind::Type(Type::F32) => Ok(value::Type::FLOAT32), - TypeDefKind::Type(Type::F64) => Ok(value::Type::FLOAT64), + TypeDefKind::Type(Type::F32) => Ok(value::Type::F32), + TypeDefKind::Type(Type::F64) => Ok(value::Type::F64), TypeDefKind::Type(Type::Char) => Ok(value::Type::CHAR), TypeDefKind::Type(Type::String) => Ok(value::Type::STRING), TypeDefKind::Type(Type::Id(_)) => unreachable!(), diff --git a/crates/wasm-wave/src/wasm/ty.rs b/crates/wasm-wave/src/wasm/ty.rs index b9baea45ee..e4d097bc56 100644 --- a/crates/wasm-wave/src/wasm/ty.rs +++ b/crates/wasm-wave/src/wasm/ty.rs @@ -15,8 +15,8 @@ pub enum WasmTypeKind { U16, U32, U64, - Float32, - Float64, + F32, + F64, Char, String, List, @@ -43,8 +43,8 @@ impl std::fmt::Display for WasmTypeKind { WasmTypeKind::U16 => "u16", WasmTypeKind::U32 => "u32", WasmTypeKind::U64 => "u64", - WasmTypeKind::Float32 => "float32", - WasmTypeKind::Float64 => "float64", + WasmTypeKind::F32 => "f32", + WasmTypeKind::F64 => "f64", WasmTypeKind::Char => "char", WasmTypeKind::String => "string", WasmTypeKind::List => "list", diff --git a/crates/wasm-wave/src/wasm/val.rs b/crates/wasm-wave/src/wasm/val.rs index 69413c54ca..0c8c020a40 100644 --- a/crates/wasm-wave/src/wasm/val.rs +++ b/crates/wasm-wave/src/wasm/val.rs @@ -73,23 +73,23 @@ pub trait WasmValue: Clone + Sized { /// Returns a new WasmValue of the given type. /// /// The Rust `f32` type has many distinct NaN bitpatterns, however the - /// component-model `float32` type only has a single NaN value, so this + /// component-model `f32` type only has a single NaN value, so this /// function does not preserve NaN bitpatterns. /// /// # Panics /// Panics if the type is not implemented (the trait default). - fn make_float32(val: f32) -> Self { + fn make_f32(val: f32) -> Self { unimplemented!() } /// Returns a new WasmValue of the given type. /// /// The Rust `f64` type has many distinct NaN bitpatterns, however the - /// component-model `float64` type only has a single NaN value, so this + /// component-model `f64` type only has a single NaN value, so this /// function does not preserve NaN bitpatterns. /// /// # Panics /// Panics if the type is not implemented (the trait default). - fn make_float64(val: f64) -> Self { + fn make_f64(val: f64) -> Self { unimplemented!() } /// Returns a new WasmValue of the given type. @@ -237,23 +237,23 @@ pub trait WasmValue: Clone + Sized { /// Returns the underlying value of the WasmValue, panicing if it's the wrong type. /// /// The Rust `f32` type has many distinct NaN bitpatterns, however the - /// component-model `float64` type only has a single NaN value, so this + /// component-model `f64` type only has a single NaN value, so this /// function does not preserve NaN bitpatterns. /// /// # Panics /// Panics if `self` is not of the right type. - fn unwrap_float32(&self) -> f32 { + fn unwrap_f32(&self) -> f32 { unimplemented!() } /// Returns the underlying value of the WasmValue, panicing if it's the wrong type. /// /// The Rust `f64` type has many distinct NaN bitpatterns, however the - /// component-model `float64` type only has a single NaN value, so this + /// component-model `f64` type only has a single NaN value, so this /// function does not preserve NaN bitpatterns. /// /// # Panics /// Panics if `self` is not of the right type. - fn unwrap_float64(&self) -> f64 { + fn unwrap_f64(&self) -> f64 { unimplemented!() } /// Returns the underlying value of the WasmValue, panicing if it's the wrong type. diff --git a/crates/wasm-wave/src/writer.rs b/crates/wasm-wave/src/writer.rs index f857624cd2..eca4f37a14 100644 --- a/crates/wasm-wave/src/writer.rs +++ b/crates/wasm-wave/src/writer.rs @@ -37,16 +37,16 @@ impl Writer { WasmTypeKind::U16 => self.write_display(val.unwrap_u16()), WasmTypeKind::U32 => self.write_display(val.unwrap_u32()), WasmTypeKind::U64 => self.write_display(val.unwrap_u64()), - WasmTypeKind::Float32 => { - let f = val.unwrap_float32(); + WasmTypeKind::F32 => { + let f = val.unwrap_f32(); if f.is_nan() { self.write_str("nan") // Display is "NaN" } else { self.write_display(f) } } - WasmTypeKind::Float64 => { - let f = val.unwrap_float64(); + WasmTypeKind::F64 => { + let f = val.unwrap_f64(); if f.is_nan() { self.write_str("nan") // Display is "NaN" } else { diff --git a/crates/wasm-wave/tests/nan.rs b/crates/wasm-wave/tests/nan.rs index 18609ccaa2..65854c8150 100644 --- a/crates/wasm-wave/tests/nan.rs +++ b/crates/wasm-wave/tests/nan.rs @@ -26,10 +26,7 @@ fn nan() { { use wasm_wave::value::Value; - assert_eq!( - Value::make_float32(val).unwrap_float32().to_bits(), - expected - ); + assert_eq!(Value::make_f32(val).unwrap_f32().to_bits(), expected); } } @@ -52,10 +49,7 @@ fn nan() { { use wasm_wave::value::Value; - assert_eq!( - Value::make_float64(val).unwrap_float64().to_bits(), - expected - ); + assert_eq!(Value::make_f64(val).unwrap_f64().to_bits(), expected); } } } diff --git a/crates/wasm-wave/tests/types.wit b/crates/wasm-wave/tests/types.wit index 24d930d830..ede8f11a05 100644 --- a/crates/wasm-wave/tests/types.wit +++ b/crates/wasm-wave/tests/types.wit @@ -7,7 +7,7 @@ world tests { export bools: func() -> tuple export sints: func() -> tuple export uints: func() -> tuple - export floats: func() -> tuple + export floats: func() -> tuple export options: func() -> tuple, option>> export list-chars: func() -> list export list-strings: func() -> list @@ -41,4 +41,4 @@ world tests { export %flags: func() -> flags-type export func-type: func(a: bool, b: enum-type) -> result -} \ No newline at end of file +} diff --git a/crates/wasm-wave/tests/ui/accept-floats.out b/crates/wasm-wave/tests/ui/accept-floats.out index 5f682c47f7..71dbf5a75e 100644 --- a/crates/wasm-wave/tests/ui/accept-floats.out +++ b/crates/wasm-wave/tests/ui/accept-floats.out @@ -1,13 +1,13 @@ -list-float32(vals: [0, 0, 0, 0, 0, 0, 0]) -list-float32(vals: [-3.1415, -100000, -0]) -list-float32(vals: [nan, inf, -inf]) +list-f32(vals: [0, 0, 0, 0, 0, 0, 0]) +list-f32(vals: [-3.1415, -100000, -0]) +list-f32(vals: [nan, inf, -inf]) // Largest normal f32 -float32(val: 340282350000000000000000000000000000000) +f32(val: 340282350000000000000000000000000000000) // Truncated precision -float32(val: 340282350000000000000000000000000000000) +f32(val: 340282350000000000000000000000000000000) // Too large; infinity -float32(val: inf) +f32(val: inf) // Smallest positive non-zero f32 -float32(val: 0.000000000000000000000000000000000000000000001) +f32(val: 0.000000000000000000000000000000000000000000001) // Too small; round to zero -float32(val: 0) +f32(val: 0) diff --git a/crates/wasm-wave/tests/ui/accept-floats.waves b/crates/wasm-wave/tests/ui/accept-floats.waves index 01d4d48662..367aea2aa9 100644 --- a/crates/wasm-wave/tests/ui/accept-floats.waves +++ b/crates/wasm-wave/tests/ui/accept-floats.waves @@ -1,13 +1,13 @@ -list-float32([0, 0.0, 0e0, 0.0e0, 0e-1, 0e+1, 0.000e100]); -list-float32([-3.1415, -100000, -0.0e-0]); -list-float32([nan, inf, -inf]); +list-f32([0, 0.0, 0e0, 0.0e0, 0e-1, 0e+1, 0.000e100]); +list-f32([-3.1415, -100000, -0.0e-0]); +list-f32([nan, inf, -inf]); // Largest normal f32 -float32(3.4028234664e38); +f32(3.4028234664e38); // Truncated precision -float32(3.4028234664123e38); +f32(3.4028234664123e38); // Too large; infinity -float32(3.4028234664e39); +f32(3.4028234664e39); // Smallest positive non-zero f32 -float32(1.4012984643e-45); +f32(1.4012984643e-45); // Too small; round to zero -float32(1.4012984643e-46); \ No newline at end of file +f32(1.4012984643e-46); diff --git a/crates/wasm-wave/tests/ui/reject-floats.out b/crates/wasm-wave/tests/ui/reject-floats.out index 6489eb9250..f3e096c077 100644 --- a/crates/wasm-wave/tests/ui/reject-floats.out +++ b/crates/wasm-wave/tests/ui/reject-floats.out @@ -1,19 +1,19 @@ // Reject "-nan". -invalid token at 8..9 -invalid token at 8..9 -unexpected token: LabelOrKeyword at 9..10 -unexpected token: LabelOrKeyword at 9..10 +invalid token at 4..5 +invalid token at 4..5 +unexpected token: LabelOrKeyword at 5..6 +unexpected token: LabelOrKeyword at 5..6 // Reject "infinity", "-infinity", and uppercase variations. -invalid value type at 8..16 -unexpected token: LabelOrKeyword at 12..17 -invalid value type at 8..16 -invalid token at 8..9 -unexpected token: LabelOrKeyword at 9..16 -invalid token at 8..9 -unexpected token: LabelOrKeyword at 9..16 -invalid token at 8..9 +invalid value type at 4..12 +unexpected token: LabelOrKeyword at 8..13 +invalid value type at 4..12 +invalid token at 4..5 +unexpected token: LabelOrKeyword at 5..12 +invalid token at 4..5 +unexpected token: LabelOrKeyword at 5..12 +invalid token at 4..5 // Reject mixed case variations of "inf" and "nan". -unexpected token: LabelOrKeyword at 9..11 -invalid token at 8..9 -invalid value type at 8..11 -invalid token at 8..9 +unexpected token: LabelOrKeyword at 5..7 +invalid token at 4..5 +invalid value type at 4..7 +invalid token at 4..5 diff --git a/crates/wasm-wave/tests/ui/reject-floats.waves b/crates/wasm-wave/tests/ui/reject-floats.waves index 672a01c5db..130d207147 100644 --- a/crates/wasm-wave/tests/ui/reject-floats.waves +++ b/crates/wasm-wave/tests/ui/reject-floats.waves @@ -1,19 +1,19 @@ // Reject "-nan". -float32(-nan); -float64(-nan); -float32(NaN); -float64(NaN); +f32(-nan); +f64(-nan); +f32(NaN); +f64(NaN); // Reject "infinity", "-infinity", and uppercase variations. -float32(infinity); -float64(-infinity); -float32(INFINITY); -float64(-INFINITY); -float32(Infinity); -float64(-Infinity); -float32(Infinity); -float64(-Infinity); +f32(infinity); +f64(-infinity); +f32(INFINITY); +f64(-INFINITY); +f32(Infinity); +f64(-Infinity); +f32(Infinity); +f64(-Infinity); // Reject mixed case variations of "inf" and "nan". -float32(Inf); -float64(-Inf); -float32(INF); -float64(-INF); \ No newline at end of file +f32(Inf); +f64(-Inf); +f32(INF); +f64(-INF); diff --git a/crates/wasm-wave/tests/ui/ui.wit b/crates/wasm-wave/tests/ui/ui.wit index 49ba14275d..216fb3b231 100644 --- a/crates/wasm-wave/tests/ui/ui.wit +++ b/crates/wasm-wave/tests/ui/ui.wit @@ -2,10 +2,10 @@ package ui:tests; interface ui { nullary: func(); - %float32: func(val: f32); - %list-float32: func(vals: list); - %float64: func(val: f64); - %list-float64: func(vals: list); + %f32: func(val: f32); + %list-f32: func(vals: list); + %f64: func(val: f64); + %list-f64: func(vals: list); %char: func(val: char); list-chars: func(vals: list); %string: func(val: string); @@ -63,4 +63,4 @@ interface ui { write, } permission-flags: func(flgs: permissions); -} \ No newline at end of file +}