From a58281ca114359cd6e65f5daaf086636aa18b0b0 Mon Sep 17 00:00:00 2001 From: Thomas Lively <tlively@google.com> Date: Thu, 4 Jan 2024 14:25:18 -0800 Subject: Require `then` and `else` with `if` (#6201) We previously supported (and primarily used) a non-standard text format for conditionals in which the condition, if-true expression, and if-false expression were all simply s-expression children of the `if` expression. The standard text format, however, requires the use of `then` and `else` forms to introduce the if-true and if-false arms of the conditional. Update the legacy text parser to require the standard format and update all tests to match. Update the printer to print the standard format as well. The .wast and .wat test inputs were mechanically updated with this script: https://gist.github.com/tlively/85ae7f01f92f772241ec994c840ccbb1 --- test/passes/precompute_all-features.wast | 54 +++++++++++++++++++------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'test/passes/precompute_all-features.wast') diff --git a/test/passes/precompute_all-features.wast b/test/passes/precompute_all-features.wast index 450001533..633787fad 100644 --- a/test/passes/precompute_all-features.wast +++ b/test/passes/precompute_all-features.wast @@ -192,16 +192,22 @@ ) (func $ret (result i32) (if (call $ret) - (return (i32.const 0)) + (then + (return (i32.const 0)) + ) ) (if (call $ret) - (return (return (i32.const 1))) + (then + (return (return (i32.const 1))) + ) ) (i32.const 1) ) (func $noret (if (call $ret) - (return) + (then + (return) + ) ) ) (func $refinalize-br-condition-unreachable @@ -234,33 +240,37 @@ (i32.const 1919623207) (if (result i32) (i32.const 1) - (block $label$2 (result i32) - (drop - (i64.and - (i64.trunc_f32_u - (f32.const 70847791997969805621592064) + (then + (block $label$2 (result i32) + (drop + (i64.and + (i64.trunc_f32_u + (f32.const 70847791997969805621592064) + ) + (i64.const 729618461987467893) ) - (i64.const 729618461987467893) ) - ) - (br_if $label$2 - (i32.const 2049535349) - (f32.eq - (f32.demote_f64 - (f64.mul - (br_if $label$0 ;; this br is optimized, and br *and* values reused - (f64.const 6.134856208230095e-154) - (i32.const 690910817) + (br_if $label$2 + (i32.const 2049535349) + (f32.eq + (f32.demote_f64 + (f64.mul + (br_if $label$0 ;; this br is optimized, and br *and* values reused + (f64.const 6.134856208230095e-154) + (i32.const 690910817) + ) + (f64.const 1.515470884183969e-152) ) - (f64.const 1.515470884183969e-152) ) + (f32.const 66524025679377434935296) ) - (f32.const 66524025679377434935296) ) ) ) - (i32.load offset=3 align=2 - (i32.const 169901344) + (else + (i32.load offset=3 align=2 + (i32.const 169901344) + ) ) ) ) -- cgit v1.2.3