From 0616ef196a183cf137ee06b4a5993b7d590088bf Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 5 Jan 2024 08:30:25 -0800 Subject: [PATCH] Accept `f32`/`f64` as aliases for `float32`/`float64`. (#1356) * Accept `f32`/`f64` as aliases for `float32`/`float64`. In WebAssembly/component-model#277 there seems to be consensus emerging to rename `float32`/`float64` to `f32`/`f64`. This PR just adds support for parsing `f32`/`f64`, and changes nothing else for now, to start preparing for this change. * Add a test for `f32`/`f64`. --- crates/wit-parser/src/ast/lex.rs | 4 +- crates/wit-parser/tests/ui/types.wit | 6 +- crates/wit-parser/tests/ui/types.wit.json | 126 +++++++++++++--------- 3 files changed, 79 insertions(+), 57 deletions(-) diff --git a/crates/wit-parser/src/ast/lex.rs b/crates/wit-parser/src/ast/lex.rs index fde7f3d4e6..c300392f53 100644 --- a/crates/wit-parser/src/ast/lex.rs +++ b/crates/wit-parser/src/ast/lex.rs @@ -285,8 +285,8 @@ impl<'a> Tokenizer<'a> { "s16" => S16, "s32" => S32, "s64" => S64, - "float32" => Float32, - "float64" => Float64, + "f32" | "float32" => Float32, + "f64" | "float64" => Float64, "char" => Char, "resource" => Resource, "own" => Own, diff --git a/crates/wit-parser/tests/ui/types.wit b/crates/wit-parser/tests/ui/types.wit index 99f0f2a26d..bb391f91b1 100644 --- a/crates/wit-parser/tests/ui/types.wit +++ b/crates/wit-parser/tests/ui/types.wit @@ -9,8 +9,10 @@ interface types { type t6 = s16; type t7 = s32; type t8 = s64; - type t9 = float32; - type t10 = float64; + type t9a = float32; + type t9b = f32; + type t10a = float64; + type t10b = f64; type t11 = char; type t12 = list; type t13 = string; diff --git a/crates/wit-parser/tests/ui/types.wit.json b/crates/wit-parser/tests/ui/types.wit.json index fb9316aa65..e2d0b9546e 100644 --- a/crates/wit-parser/tests/ui/types.wit.json +++ b/crates/wit-parser/tests/ui/types.wit.json @@ -12,50 +12,52 @@ "t6": 5, "t7": 6, "t8": 7, - "t9": 8, - "t10": 9, - "t11": 10, - "t12": 11, - "t13": 12, - "t14": 13, - "t15": 14, - "t16": 15, - "t17": 16, - "t18": 17, - "t20": 18, - "t21": 19, - "t22": 20, - "t23": 21, - "t24": 22, - "t25": 23, - "record": 24, - "t26": 25, - "t27": 26, - "t28": 27, - "t29": 28, - "t30": 29, - "t31": 30, - "t32": 31, - "t33": 32, - "t34": 33, - "t35": 34, - "t36": 35, - "t37": 37, - "t41": 38, - "t42": 39, - "t43": 40, - "t44": 41, - "t45": 44, - "t46": 45, - "t47": 46, - "t48": 47, - "t49": 48, - "t50": 49, - "t51": 50, - "t52": 51, - "t53": 52, - "bar": 53, - "foo": 54 + "t9a": 8, + "t9b": 9, + "t10a": 10, + "t10b": 11, + "t11": 12, + "t12": 13, + "t13": 14, + "t14": 15, + "t15": 16, + "t16": 17, + "t17": 18, + "t18": 19, + "t20": 20, + "t21": 21, + "t22": 22, + "t23": 23, + "t24": 24, + "t25": 25, + "record": 26, + "t26": 27, + "t27": 28, + "t28": 29, + "t29": 30, + "t30": 31, + "t31": 32, + "t32": 33, + "t33": 34, + "t34": 35, + "t35": 36, + "t36": 37, + "t37": 39, + "t41": 40, + "t42": 41, + "t43": 42, + "t44": 43, + "t45": 46, + "t46": 47, + "t47": 48, + "t48": 49, + "t49": 50, + "t50": 51, + "t51": 52, + "t52": 53, + "t53": 54, + "bar": 55, + "foo": 56 }, "functions": {}, "package": 0 @@ -135,7 +137,7 @@ } }, { - "name": "t9", + "name": "t9a", "kind": { "type": "float32" }, @@ -144,7 +146,25 @@ } }, { - "name": "t10", + "name": "t9b", + "kind": { + "type": "float32" + }, + "owner": { + "interface": 0 + } + }, + { + "name": "t10a", + "kind": { + "type": "float64" + }, + "owner": { + "interface": 0 + } + }, + { + "name": "t10b", "kind": { "type": "float64" }, @@ -544,7 +564,7 @@ }, { "name": "b", - "type": 36 + "type": 38 } ] } @@ -616,21 +636,21 @@ { "name": null, "kind": { - "list": 31 + "list": 33 }, "owner": null }, { "name": null, "kind": { - "list": 42 + "list": 44 }, "owner": null }, { "name": "t45", "kind": { - "list": 43 + "list": 45 }, "owner": { "interface": 0 @@ -639,7 +659,7 @@ { "name": "t46", "kind": { - "type": 41 + "type": 43 }, "owner": { "interface": 0 @@ -648,7 +668,7 @@ { "name": "t47", "kind": { - "type": 41 + "type": 43 }, "owner": { "interface": 0 @@ -732,7 +752,7 @@ { "name": "foo", "kind": { - "type": 53 + "type": 55 }, "owner": { "interface": 0