Skip to content

Commit

Permalink
Rename float32/float64 to f32/f64.
Browse files Browse the repository at this point in the history
As discussed [here], and following up on bytecodealliance#1364 which added `f32`
and `f64` parsing support, this PR renames the types `float32`
and `float64` to `f32` and `f64`.

The old names are still accepted by the parser for compatibility.

[here]: WebAssembly/component-model#277
  • Loading branch information
sunfishcode committed Mar 21, 2024
1 parent ef3d743 commit 0556c34
Show file tree
Hide file tree
Showing 52 changed files with 269 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
(export (;7;) "h" (func (type 7)))
(type (;8;) (func (param "x" u64)))
(export (;8;) "i" (func (type 8)))
(type (;9;) (func (param "x" float32)))
(type (;9;) (func (param "x" f32)))
(export (;9;) "j" (func (type 9)))
(type (;10;) (func (param "x" float64)))
(type (;10;) (func (param "x" f64)))
(export (;10;) "k" (func (type 10)))
(type (;11;) (func (param "x" bool)))
(export (;11;) "l" (func (type 11)))
(type (;12;) (func (param "x" string)))
(export (;12;) "m" (func (type 12)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export (;14;) "record1" (type (eq 13)))
(type (;15;) (func (param "x" 14)))
(export (;13;) "n" (func (type 15)))
Expand All @@ -67,7 +67,7 @@
(export (;27;) "option1" (type (eq 26)))
(type (;28;) (func (param "x" 27)))
(export (;18;) "s" (func (type 28)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 14)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" 14)))
(export (;30;) "variant1" (type (eq 29)))
(type (;31;) (option 30))
(type (;32;) (func (param "x" 31)))
Expand All @@ -90,15 +90,15 @@
(import "b" (component (;1;) (type 1)))
(type (;2;)
(component
(type (;0;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type (;0;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export (;1;) "record1" (type (eq 0)))
(type (;2;) (flags "a" "b" "c"))
(export (;3;) "flags1" (type (eq 2)))
(type (;4;) (enum "a" "b" "c"))
(export (;5;) "enum1" (type (eq 4)))
(type (;6;) (option 1))
(export (;7;) "option1" (type (eq 6)))
(type (;8;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 1)))
(type (;8;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" 1)))
(export (;9;) "variant1" (type (eq 8)))
(type (;10;) (func))
(export (;0;) "a" (func (type 10)))
Expand All @@ -118,9 +118,9 @@
(export (;7;) "h" (func (type 17)))
(type (;18;) (func (param "x" u64)))
(export (;8;) "i" (func (type 18)))
(type (;19;) (func (param "x" float32)))
(type (;19;) (func (param "x" f32)))
(export (;9;) "j" (func (type 19)))
(type (;20;) (func (param "x" float64)))
(type (;20;) (func (param "x" f64)))
(export (;10;) "k" (func (type 20)))
(type (;21;) (func (param "x" bool)))
(export (;11;) "l" (func (type 21)))
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm-compose/tests/compositions/complex/a.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
(type $t6 (func (param "x" u32)))
(type $t7 (func (param "x" s64)))
(type $t8 (func (param "x" u64)))
(type $t9 (func (param "x" float32)))
(type $t10 (func (param "x" float64)))
(type $t9 (func (param "x" f32)))
(type $t10 (func (param "x" f64)))
(type $t11 (func (param "x" bool)))
(type $t12 (func (param "x" string)))
(type $t13' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type $t13' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export $t13 "record1" (type $t13'))
(type $t14 (func (param "x" $t13)))
(type $t15 (list $t13))
Expand All @@ -28,7 +28,7 @@
(type $t23' (option $t13))
(export $t23 "option1" (type $t23'))
(type $t24 (func (param "x" $t23)))
(type $t25' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t13)))
(type $t25' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" $t13)))
(export $t25 "variant1" (type $t25'))
(type $t26 (option $t25))
(type $t27 (func (param "x" $t26)))
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm-compose/tests/compositions/complex/b.wat
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
(type $f7 (func (param "x" u32)))
(type $f8 (func (param "x" s64)))
(type $f9 (func (param "x" u64)))
(type $f10 (func (param "x" float32)))
(type $f11 (func (param "x" float64)))
(type $f10 (func (param "x" f32)))
(type $f11 (func (param "x" f64)))
(type $f12 (func (param "x" bool)))
(type $f13 (func (param "x" string)))
(export "a" (func (type $f1)))
Expand All @@ -27,7 +27,7 @@
(export "k" (func (type $f11)))
(export "l" (func (type $f12)))
(export "m" (func (type $f13)))
(type $t1' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type $t1' (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export $t1 "record1" (type (eq $t1')))
(type $f14 (func (param "x" $t1)))
(export "n" (func (type $f14)))
Expand All @@ -49,7 +49,7 @@
(export $t6 "option1" (type (eq $t6')))
(type $f19 (func (param "x" $t6)))
(export "s" (func (type $f19)))
(type $t7' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t1)))
(type $t7' (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" $t1)))
(export $t7 "variant1" (type (eq $t7')))
(type $t8 (option $t7))
(type $f20 (func (param "x" $t8)))
Expand Down
16 changes: 8 additions & 8 deletions crates/wasm-compose/tests/compositions/complex/composed.wat
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
(type (;6;) (func (param "x" u32)))
(type (;7;) (func (param "x" s64)))
(type (;8;) (func (param "x" u64)))
(type (;9;) (func (param "x" float32)))
(type (;10;) (func (param "x" float64)))
(type (;9;) (func (param "x" f32)))
(type (;10;) (func (param "x" f64)))
(type (;11;) (func (param "x" bool)))
(type (;12;) (func (param "x" string)))
(export (;0;) "a" (func (type 0)))
Expand All @@ -42,7 +42,7 @@
(export (;10;) "k" (func (type 10)))
(export (;11;) "l" (func (type 11)))
(export (;12;) "m" (func (type 12)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export (;14;) "record1" (type (eq 13)))
(type (;15;) (func (param "x" 14)))
(export (;13;) "n" (func (type 15)))
Expand All @@ -64,7 +64,7 @@
(export (;27;) "option1" (type (eq 26)))
(type (;28;) (func (param "x" 27)))
(export (;18;) "s" (func (type 28)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" 14)))
(type (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" 14)))
(export (;30;) "variant1" (type (eq 29)))
(type (;31;) (option 30))
(type (;32;) (func (param "x" 31)))
Expand Down Expand Up @@ -327,11 +327,11 @@
(type $t6 (;6;) (func (param "x" u32)))
(type $t7 (;7;) (func (param "x" s64)))
(type $t8 (;8;) (func (param "x" u64)))
(type $t9 (;9;) (func (param "x" float32)))
(type $t10 (;10;) (func (param "x" float64)))
(type $t9 (;9;) (func (param "x" f32)))
(type $t10 (;10;) (func (param "x" f64)))
(type $t11 (;11;) (func (param "x" bool)))
(type $t12 (;12;) (func (param "x" string)))
(type $t13' (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string)))
(type $t13' (;13;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" f32) (field "j" f64) (field "k" bool) (field "l" string)))
(export $t13 (;14;) "record1" (type $t13'))
(type $t14 (;15;) (func (param "x" $t13)))
(type $t15 (;16;) (list $t13))
Expand All @@ -347,7 +347,7 @@
(type $t23' (;26;) (option $t13))
(export $t23 (;27;) "option1" (type $t23'))
(type $t24 (;28;) (func (param "x" $t23)))
(type $t25' (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" float32) (case "j" float64) (case "k" bool) (case "l" string) (case "m" $t13)))
(type $t25' (;29;) (variant (case "a" s8) (case "b" u8) (case "c" s16) (case "d" u16) (case "e" s32) (case "f" u32) (case "g" s64) (case "h" u64) (case "i" f32) (case "j" f64) (case "k" bool) (case "l" string) (case "m" $t13)))
(export $t25 (;30;) "variant1" (type $t25'))
(type $t26 (;31;) (option $t25))
(type $t27 (;32;) (func (param "x" $t26)))
Expand Down
16 changes: 8 additions & 8 deletions crates/wasm-encoder/src/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ pub enum PrimitiveValType {
S64,
/// The type is an unsigned 64-bit integer.
U64,
/// The type is a 32-bit floating point number.
Float32,
/// The type is a 64-bit floating point number.
Float64,
/// The type is a 32-bit floating point number with only one NaN.
F32,
/// The type is a 64-bit floating point number with only one NaN.
F64,
/// The type is a Unicode character.
Char,
/// The type is a string.
Expand All @@ -519,8 +519,8 @@ impl Encode for PrimitiveValType {
Self::U32 => 0x79,
Self::S64 => 0x78,
Self::U64 => 0x77,
Self::Float32 => 0x76,
Self::Float64 => 0x75,
Self::F32 => 0x76,
Self::F64 => 0x75,
Self::Char => 0x74,
Self::String => 0x73,
});
Expand All @@ -540,8 +540,8 @@ impl From<wasmparser::PrimitiveValType> for PrimitiveValType {
wasmparser::PrimitiveValType::U32 => PrimitiveValType::U32,
wasmparser::PrimitiveValType::S64 => PrimitiveValType::S64,
wasmparser::PrimitiveValType::U64 => PrimitiveValType::U64,
wasmparser::PrimitiveValType::Float32 => PrimitiveValType::Float32,
wasmparser::PrimitiveValType::Float64 => PrimitiveValType::Float64,
wasmparser::PrimitiveValType::F32 => PrimitiveValType::F32,
wasmparser::PrimitiveValType::F64 => PrimitiveValType::F64,
wasmparser::PrimitiveValType::Char => PrimitiveValType::Char,
wasmparser::PrimitiveValType::String => PrimitiveValType::String,
}
Expand Down
16 changes: 8 additions & 8 deletions crates/wasm-smith/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,8 @@ impl ComponentBuilder {
6 => Ok(PrimitiveValType::U32),
7 => Ok(PrimitiveValType::S64),
8 => Ok(PrimitiveValType::U64),
9 => Ok(PrimitiveValType::Float32),
10 => Ok(PrimitiveValType::Float64),
9 => Ok(PrimitiveValType::F32),
10 => Ok(PrimitiveValType::F64),
11 => Ok(PrimitiveValType::Char),
12 => Ok(PrimitiveValType::String),
_ => unreachable!(),
Expand Down Expand Up @@ -1773,8 +1773,8 @@ fn canonical_abi_for(func_ty: &FuncType) -> Rc<crate::core::FuncType> {
| PrimitiveValType::S32
| PrimitiveValType::U32 => ValType::I32,
PrimitiveValType::S64 | PrimitiveValType::U64 => ValType::I64,
PrimitiveValType::Float32 => ValType::F32,
PrimitiveValType::Float64 => ValType::F64,
PrimitiveValType::F32 => ValType::F32,
PrimitiveValType::F64 => ValType::F64,
PrimitiveValType::String => {
unimplemented!("non-scalar types are not supported yet")
}
Expand Down Expand Up @@ -1819,8 +1819,8 @@ fn inverse_scalar_canonical_abi_for(
ComponentValType::Primitive(PrimitiveValType::U64),
])
.cloned(),
ValType::F32 => Ok(ComponentValType::Primitive(PrimitiveValType::Float32)),
ValType::F64 => Ok(ComponentValType::Primitive(PrimitiveValType::Float64)),
ValType::F32 => Ok(ComponentValType::Primitive(PrimitiveValType::F32)),
ValType::F64 => Ok(ComponentValType::Primitive(PrimitiveValType::F64)),
ValType::V128 | ValType::Ref(_) => {
unreachable!("not used in canonical ABI")
}
Expand Down Expand Up @@ -2055,8 +2055,8 @@ fn is_scalar(ty: &ComponentValType) -> bool {
| PrimitiveValType::U32
| PrimitiveValType::S64
| PrimitiveValType::U64
| PrimitiveValType::Float32
| PrimitiveValType::Float64
| PrimitiveValType::F32
| PrimitiveValType::F64
| PrimitiveValType::Char => true,
PrimitiveValType::String => false,
},
Expand Down
16 changes: 8 additions & 8 deletions crates/wasmparser/src/readers/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ pub enum PrimitiveValType {
S64,
/// The type is an unsigned 64-bit integer.
U64,
/// The type is a 32-bit floating point number.
Float32,
/// The type is a 64-bit floating point number.
Float64,
/// The type is a 32-bit floating point number with only one NaN.
F32,
/// The type is a 64-bit floating point number with only one NaN.
F64,
/// The type is a Unicode character.
Char,
/// The type is a string.
Expand All @@ -185,8 +185,8 @@ impl PrimitiveValType {
0x79 => PrimitiveValType::U32,
0x78 => PrimitiveValType::S64,
0x77 => PrimitiveValType::U64,
0x76 => PrimitiveValType::Float32,
0x75 => PrimitiveValType::Float64,
0x76 => PrimitiveValType::F32,
0x75 => PrimitiveValType::F64,
0x74 => PrimitiveValType::Char,
0x73 => PrimitiveValType::String,
_ => return None,
Expand Down Expand Up @@ -222,8 +222,8 @@ impl fmt::Display for PrimitiveValType {
U32 => "u32",
S64 => "s64",
U64 => "u64",
Float32 => "float32",
Float64 => "float64",
F32 => "f32",
F64 => "f64",
Char => "char",
String => "string",
};
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/validator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ fn push_primitive_wasm_types(ty: &PrimitiveValType, lowered_types: &mut LoweredT
| PrimitiveValType::U32
| PrimitiveValType::Char => lowered_types.push(ValType::I32),
PrimitiveValType::S64 | PrimitiveValType::U64 => lowered_types.push(ValType::I64),
PrimitiveValType::Float32 => lowered_types.push(ValType::F32),
PrimitiveValType::Float64 => lowered_types.push(ValType::F64),
PrimitiveValType::F32 => lowered_types.push(ValType::F32),
PrimitiveValType::F64 => lowered_types.push(ValType::F64),
PrimitiveValType::String => {
lowered_types.push(ValType::I32) && lowered_types.push(ValType::I32)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmprinter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,8 +1631,8 @@ impl Printer {
PrimitiveValType::U32 => self.result.push_str("u32"),
PrimitiveValType::S64 => self.result.push_str("s64"),
PrimitiveValType::U64 => self.result.push_str("u64"),
PrimitiveValType::Float32 => self.result.push_str("float32"),
PrimitiveValType::Float64 => self.result.push_str("float64"),
PrimitiveValType::F32 => self.result.push_str("f32"),
PrimitiveValType::F64 => self.result.push_str("f64"),
PrimitiveValType::Char => self.result.push_str("char"),
PrimitiveValType::String => self.result.push_str("string"),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wast/src/component/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ impl From<PrimitiveValType> for wasm_encoder::PrimitiveValType {
PrimitiveValType::U32 => Self::U32,
PrimitiveValType::S64 => Self::S64,
PrimitiveValType::U64 => Self::U64,
PrimitiveValType::Float32 => Self::Float32,
PrimitiveValType::Float64 => Self::Float64,
PrimitiveValType::F32 => Self::F32,
PrimitiveValType::F64 => Self::F64,
PrimitiveValType::Char => Self::Char,
PrimitiveValType::String => Self::String,
}
Expand Down
16 changes: 12 additions & 4 deletions crates/wast/src/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ pub enum PrimitiveValType {
U32,
S64,
U64,
Float32,
Float64,
F32,
F64,
Char,
String,
}
Expand Down Expand Up @@ -266,12 +266,18 @@ impl<'a> Parse<'a> for PrimitiveValType {
} else if l.peek::<kw::u64>()? {
parser.parse::<kw::u64>()?;
Ok(Self::U64)
} else if l.peek::<kw::f32>()? {
parser.parse::<kw::f32>()?;
Ok(Self::F32)
} else if l.peek::<kw::f64>()? {
parser.parse::<kw::f64>()?;
Ok(Self::F64)
} else if l.peek::<kw::float32>()? {
parser.parse::<kw::float32>()?;
Ok(Self::Float32)
Ok(Self::F32)
} else if l.peek::<kw::float64>()? {
parser.parse::<kw::float64>()?;
Ok(Self::Float64)
Ok(Self::F64)
} else if l.peek::<kw::char>()? {
parser.parse::<kw::char>()?;
Ok(Self::Char)
Expand All @@ -297,6 +303,8 @@ impl Peek for PrimitiveValType {
| Some(("u32", _))
| Some(("s64", _))
| Some(("u64", _))
| Some(("f32", _))
| Some(("f64", _))
| Some(("float32", _))
| Some(("float64", _))
| Some(("char", _))
Expand Down
Loading

0 comments on commit 0556c34

Please sign in to comment.