Skip to content

Commit 7803d17

Browse files
authored
Rename float32/float64 to f32/f64. (#1466)
As discussed [here], and following up on #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
1 parent ef3d743 commit 7803d17

52 files changed

Lines changed: 269 additions & 255 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/wasm-compose/tests/compositions/complex-import/composed.wat

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
(export (;7;) "h" (func (type 7)))
3838
(type (;8;) (func (param "x" u64)))
3939
(export (;8;) "i" (func (type 8)))
40-
(type (;9;) (func (param "x" float32)))
40+
(type (;9;) (func (param "x" f32)))
4141
(export (;9;) "j" (func (type 9)))
42-
(type (;10;) (func (param "x" float64)))
42+
(type (;10;) (func (param "x" f64)))
4343
(export (;10;) "k" (func (type 10)))
4444
(type (;11;) (func (param "x" bool)))
4545
(export (;11;) "l" (func (type 11)))
4646
(type (;12;) (func (param "x" string)))
4747
(export (;12;) "m" (func (type 12)))
48-
(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)))
48+
(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)))
4949
(export (;14;) "record1" (type (eq 13)))
5050
(type (;15;) (func (param "x" 14)))
5151
(export (;13;) "n" (func (type 15)))
@@ -67,7 +67,7 @@
6767
(export (;27;) "option1" (type (eq 26)))
6868
(type (;28;) (func (param "x" 27)))
6969
(export (;18;) "s" (func (type 28)))
70-
(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)))
70+
(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)))
7171
(export (;30;) "variant1" (type (eq 29)))
7272
(type (;31;) (option 30))
7373
(type (;32;) (func (param "x" 31)))
@@ -90,15 +90,15 @@
9090
(import "b" (component (;1;) (type 1)))
9191
(type (;2;)
9292
(component
93-
(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)))
93+
(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)))
9494
(export (;1;) "record1" (type (eq 0)))
9595
(type (;2;) (flags "a" "b" "c"))
9696
(export (;3;) "flags1" (type (eq 2)))
9797
(type (;4;) (enum "a" "b" "c"))
9898
(export (;5;) "enum1" (type (eq 4)))
9999
(type (;6;) (option 1))
100100
(export (;7;) "option1" (type (eq 6)))
101-
(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)))
101+
(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)))
102102
(export (;9;) "variant1" (type (eq 8)))
103103
(type (;10;) (func))
104104
(export (;0;) "a" (func (type 10)))
@@ -118,9 +118,9 @@
118118
(export (;7;) "h" (func (type 17)))
119119
(type (;18;) (func (param "x" u64)))
120120
(export (;8;) "i" (func (type 18)))
121-
(type (;19;) (func (param "x" float32)))
121+
(type (;19;) (func (param "x" f32)))
122122
(export (;9;) "j" (func (type 19)))
123-
(type (;20;) (func (param "x" float64)))
123+
(type (;20;) (func (param "x" f64)))
124124
(export (;10;) "k" (func (type 20)))
125125
(type (;21;) (func (param "x" bool)))
126126
(export (;11;) "l" (func (type 21)))

crates/wasm-compose/tests/compositions/complex/a.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
(type $t6 (func (param "x" u32)))
99
(type $t7 (func (param "x" s64)))
1010
(type $t8 (func (param "x" u64)))
11-
(type $t9 (func (param "x" float32)))
12-
(type $t10 (func (param "x" float64)))
11+
(type $t9 (func (param "x" f32)))
12+
(type $t10 (func (param "x" f64)))
1313
(type $t11 (func (param "x" bool)))
1414
(type $t12 (func (param "x" string)))
15-
(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)))
15+
(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)))
1616
(export $t13 "record1" (type $t13'))
1717
(type $t14 (func (param "x" $t13)))
1818
(type $t15 (list $t13))
@@ -28,7 +28,7 @@
2828
(type $t23' (option $t13))
2929
(export $t23 "option1" (type $t23'))
3030
(type $t24 (func (param "x" $t23)))
31-
(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)))
31+
(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)))
3232
(export $t25 "variant1" (type $t25'))
3333
(type $t26 (option $t25))
3434
(type $t27 (func (param "x" $t26)))

crates/wasm-compose/tests/compositions/complex/b.wat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
(type $f7 (func (param "x" u32)))
1111
(type $f8 (func (param "x" s64)))
1212
(type $f9 (func (param "x" u64)))
13-
(type $f10 (func (param "x" float32)))
14-
(type $f11 (func (param "x" float64)))
13+
(type $f10 (func (param "x" f32)))
14+
(type $f11 (func (param "x" f64)))
1515
(type $f12 (func (param "x" bool)))
1616
(type $f13 (func (param "x" string)))
1717
(export "a" (func (type $f1)))
@@ -27,7 +27,7 @@
2727
(export "k" (func (type $f11)))
2828
(export "l" (func (type $f12)))
2929
(export "m" (func (type $f13)))
30-
(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)))
30+
(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)))
3131
(export $t1 "record1" (type (eq $t1')))
3232
(type $f14 (func (param "x" $t1)))
3333
(export "n" (func (type $f14)))
@@ -49,7 +49,7 @@
4949
(export $t6 "option1" (type (eq $t6')))
5050
(type $f19 (func (param "x" $t6)))
5151
(export "s" (func (type $f19)))
52-
(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)))
52+
(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)))
5353
(export $t7 "variant1" (type (eq $t7')))
5454
(type $t8 (option $t7))
5555
(type $f20 (func (param "x" $t8)))

crates/wasm-compose/tests/compositions/complex/composed.wat

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
(type (;6;) (func (param "x" u32)))
2626
(type (;7;) (func (param "x" s64)))
2727
(type (;8;) (func (param "x" u64)))
28-
(type (;9;) (func (param "x" float32)))
29-
(type (;10;) (func (param "x" float64)))
28+
(type (;9;) (func (param "x" f32)))
29+
(type (;10;) (func (param "x" f64)))
3030
(type (;11;) (func (param "x" bool)))
3131
(type (;12;) (func (param "x" string)))
3232
(export (;0;) "a" (func (type 0)))
@@ -42,7 +42,7 @@
4242
(export (;10;) "k" (func (type 10)))
4343
(export (;11;) "l" (func (type 11)))
4444
(export (;12;) "m" (func (type 12)))
45-
(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)))
45+
(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)))
4646
(export (;14;) "record1" (type (eq 13)))
4747
(type (;15;) (func (param "x" 14)))
4848
(export (;13;) "n" (func (type 15)))
@@ -64,7 +64,7 @@
6464
(export (;27;) "option1" (type (eq 26)))
6565
(type (;28;) (func (param "x" 27)))
6666
(export (;18;) "s" (func (type 28)))
67-
(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)))
67+
(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)))
6868
(export (;30;) "variant1" (type (eq 29)))
6969
(type (;31;) (option 30))
7070
(type (;32;) (func (param "x" 31)))
@@ -327,11 +327,11 @@
327327
(type $t6 (;6;) (func (param "x" u32)))
328328
(type $t7 (;7;) (func (param "x" s64)))
329329
(type $t8 (;8;) (func (param "x" u64)))
330-
(type $t9 (;9;) (func (param "x" float32)))
331-
(type $t10 (;10;) (func (param "x" float64)))
330+
(type $t9 (;9;) (func (param "x" f32)))
331+
(type $t10 (;10;) (func (param "x" f64)))
332332
(type $t11 (;11;) (func (param "x" bool)))
333333
(type $t12 (;12;) (func (param "x" string)))
334-
(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)))
334+
(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)))
335335
(export $t13 (;14;) "record1" (type $t13'))
336336
(type $t14 (;15;) (func (param "x" $t13)))
337337
(type $t15 (;16;) (list $t13))
@@ -347,7 +347,7 @@
347347
(type $t23' (;26;) (option $t13))
348348
(export $t23 (;27;) "option1" (type $t23'))
349349
(type $t24 (;28;) (func (param "x" $t23)))
350-
(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)))
350+
(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)))
351351
(export $t25 (;30;) "variant1" (type $t25'))
352352
(type $t26 (;31;) (option $t25))
353353
(type $t27 (;32;) (func (param "x" $t26)))

crates/wasm-encoder/src/component/types.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,10 @@ pub enum PrimitiveValType {
497497
S64,
498498
/// The type is an unsigned 64-bit integer.
499499
U64,
500-
/// The type is a 32-bit floating point number.
501-
Float32,
502-
/// The type is a 64-bit floating point number.
503-
Float64,
500+
/// The type is a 32-bit floating point number with only one NaN.
501+
F32,
502+
/// The type is a 64-bit floating point number with only one NaN.
503+
F64,
504504
/// The type is a Unicode character.
505505
Char,
506506
/// The type is a string.
@@ -519,8 +519,8 @@ impl Encode for PrimitiveValType {
519519
Self::U32 => 0x79,
520520
Self::S64 => 0x78,
521521
Self::U64 => 0x77,
522-
Self::Float32 => 0x76,
523-
Self::Float64 => 0x75,
522+
Self::F32 => 0x76,
523+
Self::F64 => 0x75,
524524
Self::Char => 0x74,
525525
Self::String => 0x73,
526526
});
@@ -540,8 +540,8 @@ impl From<wasmparser::PrimitiveValType> for PrimitiveValType {
540540
wasmparser::PrimitiveValType::U32 => PrimitiveValType::U32,
541541
wasmparser::PrimitiveValType::S64 => PrimitiveValType::S64,
542542
wasmparser::PrimitiveValType::U64 => PrimitiveValType::U64,
543-
wasmparser::PrimitiveValType::Float32 => PrimitiveValType::Float32,
544-
wasmparser::PrimitiveValType::Float64 => PrimitiveValType::Float64,
543+
wasmparser::PrimitiveValType::F32 => PrimitiveValType::F32,
544+
wasmparser::PrimitiveValType::F64 => PrimitiveValType::F64,
545545
wasmparser::PrimitiveValType::Char => PrimitiveValType::Char,
546546
wasmparser::PrimitiveValType::String => PrimitiveValType::String,
547547
}

crates/wasm-smith/src/component.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,8 @@ impl ComponentBuilder {
13081308
6 => Ok(PrimitiveValType::U32),
13091309
7 => Ok(PrimitiveValType::S64),
13101310
8 => Ok(PrimitiveValType::U64),
1311-
9 => Ok(PrimitiveValType::Float32),
1312-
10 => Ok(PrimitiveValType::Float64),
1311+
9 => Ok(PrimitiveValType::F32),
1312+
10 => Ok(PrimitiveValType::F64),
13131313
11 => Ok(PrimitiveValType::Char),
13141314
12 => Ok(PrimitiveValType::String),
13151315
_ => unreachable!(),
@@ -1773,8 +1773,8 @@ fn canonical_abi_for(func_ty: &FuncType) -> Rc<crate::core::FuncType> {
17731773
| PrimitiveValType::S32
17741774
| PrimitiveValType::U32 => ValType::I32,
17751775
PrimitiveValType::S64 | PrimitiveValType::U64 => ValType::I64,
1776-
PrimitiveValType::Float32 => ValType::F32,
1777-
PrimitiveValType::Float64 => ValType::F64,
1776+
PrimitiveValType::F32 => ValType::F32,
1777+
PrimitiveValType::F64 => ValType::F64,
17781778
PrimitiveValType::String => {
17791779
unimplemented!("non-scalar types are not supported yet")
17801780
}
@@ -1819,8 +1819,8 @@ fn inverse_scalar_canonical_abi_for(
18191819
ComponentValType::Primitive(PrimitiveValType::U64),
18201820
])
18211821
.cloned(),
1822-
ValType::F32 => Ok(ComponentValType::Primitive(PrimitiveValType::Float32)),
1823-
ValType::F64 => Ok(ComponentValType::Primitive(PrimitiveValType::Float64)),
1822+
ValType::F32 => Ok(ComponentValType::Primitive(PrimitiveValType::F32)),
1823+
ValType::F64 => Ok(ComponentValType::Primitive(PrimitiveValType::F64)),
18241824
ValType::V128 | ValType::Ref(_) => {
18251825
unreachable!("not used in canonical ABI")
18261826
}
@@ -2055,8 +2055,8 @@ fn is_scalar(ty: &ComponentValType) -> bool {
20552055
| PrimitiveValType::U32
20562056
| PrimitiveValType::S64
20572057
| PrimitiveValType::U64
2058-
| PrimitiveValType::Float32
2059-
| PrimitiveValType::Float64
2058+
| PrimitiveValType::F32
2059+
| PrimitiveValType::F64
20602060
| PrimitiveValType::Char => true,
20612061
PrimitiveValType::String => false,
20622062
},

crates/wasmparser/src/readers/component/types.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ pub enum PrimitiveValType {
163163
S64,
164164
/// The type is an unsigned 64-bit integer.
165165
U64,
166-
/// The type is a 32-bit floating point number.
167-
Float32,
168-
/// The type is a 64-bit floating point number.
169-
Float64,
166+
/// The type is a 32-bit floating point number with only one NaN.
167+
F32,
168+
/// The type is a 64-bit floating point number with only one NaN.
169+
F64,
170170
/// The type is a Unicode character.
171171
Char,
172172
/// The type is a string.
@@ -185,8 +185,8 @@ impl PrimitiveValType {
185185
0x79 => PrimitiveValType::U32,
186186
0x78 => PrimitiveValType::S64,
187187
0x77 => PrimitiveValType::U64,
188-
0x76 => PrimitiveValType::Float32,
189-
0x75 => PrimitiveValType::Float64,
188+
0x76 => PrimitiveValType::F32,
189+
0x75 => PrimitiveValType::F64,
190190
0x74 => PrimitiveValType::Char,
191191
0x73 => PrimitiveValType::String,
192192
_ => return None,
@@ -222,8 +222,8 @@ impl fmt::Display for PrimitiveValType {
222222
U32 => "u32",
223223
S64 => "s64",
224224
U64 => "u64",
225-
Float32 => "float32",
226-
Float64 => "float64",
225+
F32 => "f32",
226+
F64 => "f64",
227227
Char => "char",
228228
String => "string",
229229
};

crates/wasmparser/src/validator/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ fn push_primitive_wasm_types(ty: &PrimitiveValType, lowered_types: &mut LoweredT
132132
| PrimitiveValType::U32
133133
| PrimitiveValType::Char => lowered_types.push(ValType::I32),
134134
PrimitiveValType::S64 | PrimitiveValType::U64 => lowered_types.push(ValType::I64),
135-
PrimitiveValType::Float32 => lowered_types.push(ValType::F32),
136-
PrimitiveValType::Float64 => lowered_types.push(ValType::F64),
135+
PrimitiveValType::F32 => lowered_types.push(ValType::F32),
136+
PrimitiveValType::F64 => lowered_types.push(ValType::F64),
137137
PrimitiveValType::String => {
138138
lowered_types.push(ValType::I32) && lowered_types.push(ValType::I32)
139139
}

crates/wasmprinter/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,8 @@ impl Printer {
16311631
PrimitiveValType::U32 => self.result.push_str("u32"),
16321632
PrimitiveValType::S64 => self.result.push_str("s64"),
16331633
PrimitiveValType::U64 => self.result.push_str("u64"),
1634-
PrimitiveValType::Float32 => self.result.push_str("float32"),
1635-
PrimitiveValType::Float64 => self.result.push_str("float64"),
1634+
PrimitiveValType::F32 => self.result.push_str("f32"),
1635+
PrimitiveValType::F64 => self.result.push_str("f64"),
16361636
PrimitiveValType::Char => self.result.push_str("char"),
16371637
PrimitiveValType::String => self.result.push_str("string"),
16381638
}

crates/wast/src/component/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ impl From<PrimitiveValType> for wasm_encoder::PrimitiveValType {
780780
PrimitiveValType::U32 => Self::U32,
781781
PrimitiveValType::S64 => Self::S64,
782782
PrimitiveValType::U64 => Self::U64,
783-
PrimitiveValType::Float32 => Self::Float32,
784-
PrimitiveValType::Float64 => Self::Float64,
783+
PrimitiveValType::F32 => Self::F32,
784+
PrimitiveValType::F64 => Self::F64,
785785
PrimitiveValType::Char => Self::Char,
786786
PrimitiveValType::String => Self::String,
787787
}

0 commit comments

Comments
 (0)