From c8256949d0fdf10435e5e2df5b07083163e56c91 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 25 Oct 2024 07:46:10 +0200 Subject: [PATCH 1/5] Heuristic for pattern matching untagged variants. --- compiler/ml/ast_untagged_variants.ml | 22 +++++--- tests/tests/src/UntaggedVariants.mjs | 50 +++++++++---------- tests/tests/src/core/Core_JsonTests.mjs | 10 ++-- tests/tests/src/core/Core_NullableTests.mjs | 6 +-- .../tests/src/untagged_variants_heuristic.mjs | 22 ++++++++ .../tests/src/untagged_variants_heuristic.res | 22 ++++++++ tests/tests/src/variantsMatching.mjs | 14 +++--- 7 files changed, 100 insertions(+), 46 deletions(-) create mode 100644 tests/tests/src/untagged_variants_heuristic.mjs create mode 100644 tests/tests/src/untagged_variants_heuristic.res diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index ab53f3961e..349c99f962 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -458,12 +458,22 @@ module DynamicChecks = struct Ext_list.fold_right others is_literal_1 (fun literal_n acc -> is_literal_case literal_n ||| acc)) in - match block_cases with - | [c] -> is_not_block_case c - | c1 :: (_ :: _ as rest) -> - is_not_block_case c1 - &&& is_a_literal_case ~literal_cases ~block_cases:rest e - | [] -> assert false + let list_literal_cases = true in + if list_literal_cases then + let rec mk cases = + match cases with + | [case] -> is_literal_case case + | case :: rest -> is_literal_case case ||| mk rest + | [] -> assert false + in + mk literal_cases + else + match block_cases with + | [c] -> is_not_block_case c + | c1 :: (_ :: _ as rest) -> + is_not_block_case c1 + &&& is_a_literal_case ~literal_cases ~block_cases:rest e + | [] -> assert false let is_int_tag ?(has_null_undefined_other = (false, false, false)) (e : _ t) : _ t = diff --git a/tests/tests/src/UntaggedVariants.mjs b/tests/tests/src/UntaggedVariants.mjs index 6f59067b7b..41251e1d52 100644 --- a/tests/tests/src/UntaggedVariants.mjs +++ b/tests/tests/src/UntaggedVariants.mjs @@ -6,7 +6,7 @@ import * as Primitive_array from "rescript/lib/es6/Primitive_array.js"; import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; function classify(x) { - if (x === "A" && typeof x !== "number") { + if (x === "A") { return "A"; } else if (typeof x === "number") { return "An integer"; @@ -24,7 +24,7 @@ function classify2(x) { } function cls(x) { - if (typeof x !== "object") { + if (x === "Two" || x === "One") { if (x === "One") { return "one"; } else { @@ -40,13 +40,13 @@ let ListWithTuples = {}; let ListWithObjects = {}; function tuplesToObjects(l) { - if (Array.isArray(l)) { + if (l === undefined) { + return null; + } else { return { hd: l[0], tl: tuplesToObjects(l[1]) }; - } else { - return null; } } @@ -68,7 +68,7 @@ console.log("l1", l1); console.log("l2", l2); function isTrue(x) { - if (typeof x !== "object") { + if (x === true) { return true; } else { return x.flag; @@ -80,7 +80,7 @@ let Truthy = { }; function classify$1(x) { - if (x === null || typeof x !== "object") { + if (x === undefined || x === null) { if (x === null) { return "null"; } else { @@ -96,7 +96,7 @@ let TwoObjects = { }; function classify$2(x) { - if (x === "A" || x === "B") { + if (x === "B" || x === "A") { if (x === "A") { return "a"; } else { @@ -112,7 +112,7 @@ let Unknown = { }; function classify$3(x) { - if (typeof x !== "object" && typeof x !== "number" && (x === "C" || x === "B" || x === "A" || x === "D")) { + if (x === "D" || x === "C" || x === "B" || x === "A") { switch (x) { case "A" : return "a"; @@ -173,7 +173,7 @@ let WithArray = { }; function classify$6(x) { - if (!Array.isArray(x) && (x === null || typeof x !== "object") && typeof x !== "number" && typeof x !== "string") { + if (x === null || x === true || x === false) { switch (x) { case false : return "JSONFalse"; @@ -214,18 +214,18 @@ let Json = { }; function check(s, y) { - if (!Array.isArray(s)) { + if (s === "B") { return 42; } let x = s[0]; - if (!Array.isArray(x)) { + if (x === "B") { return 42; } let tmp = s[1]; - if (Array.isArray(tmp) || x === y) { - return 42; - } else { + if (tmp === "B" && x !== y) { return 41; + } else { + return 42; } } @@ -234,7 +234,7 @@ let TrickyNested = { }; function checkEnum(e) { - if (!(e === "Two" || e === "One" || e === "Three")) { + if (!(e === "Three" || e === "Two" || e === "One")) { return "Something else..." + e; } switch (e) { @@ -252,7 +252,7 @@ let OverlapString = { }; function checkEnum$1(e) { - if (!(e === "Two" || e === 1.0 || e === "Three")) { + if (!(e === "Three" || e === "Two" || e === 1.0)) { return "Something else..."; } switch (e) { @@ -270,7 +270,7 @@ let OverlapNumber = { }; function checkEnum$2(e) { - if (!(e === null || typeof e !== "object")) { + if (!(e === "Three" || e === "Two" || e === null)) { return "Object..."; } switch (e) { @@ -376,7 +376,7 @@ let TestFunctionCase = { let someJson = '[{"name": "Haan"}, {"name": "Mr"}, false]'; function check$1(s) { - if (!Array.isArray(s) && (s === null || typeof s !== "object") && typeof s !== "number" && typeof s !== "string") { + if (s === null || s === true || s === false || s === undefined) { console.log("Nope..."); return; } @@ -386,11 +386,11 @@ function check$1(s) { return; } let match = s[0]; - if (match === true) { + if ((match === null || match === true || match === false || match === undefined) && match === true) { let match$1 = s[1]; - if (match$1 === false) { + if ((match$1 === null || match$1 === true || match$1 === false || match$1 === undefined) && match$1 === false) { let match$2 = s[2]; - if (!Array.isArray(match$2) && (match$2 === null || typeof match$2 !== "object") && typeof match$2 !== "number" && typeof match$2 !== "string") { + if (match$2 === null || match$2 === true || match$2 === false || match$2 === undefined) { console.log("Nope..."); return; } @@ -400,13 +400,13 @@ function check$1(s) { return; } let match$3 = match$2[0]; - if (!Array.isArray(match$3) && (match$3 === null || typeof match$3 !== "object") && typeof match$3 !== "number" && typeof match$3 !== "string") { + if (match$3 === null || match$3 === true || match$3 === false || match$3 === undefined) { console.log("Nope..."); return; } if (typeof match$3 === "string" && match$3 === "My name is") { let match$4 = match$2[1]; - if (!Array.isArray(match$4) && (match$4 === null || typeof match$4 !== "object") && typeof match$4 !== "number" && typeof match$4 !== "string") { + if (match$4 === null || match$4 === true || match$4 === false || match$4 === undefined) { console.log("Nope..."); return; } @@ -476,7 +476,7 @@ let PromiseSync = { }; async function classify$10(a) { - if (typeof a !== "object" && !(a instanceof Promise) && (a === "test" || a === 12) && !Array.isArray(a)) { + if (a === 12 || a === "test") { if (a === "test") { console.log("testing"); return; diff --git a/tests/tests/src/core/Core_JsonTests.mjs b/tests/tests/src/core/Core_JsonTests.mjs index 8898a2d2b0..0ddd7e6628 100644 --- a/tests/tests/src/core/Core_JsonTests.mjs +++ b/tests/tests/src/core/Core_JsonTests.mjs @@ -5,19 +5,19 @@ import * as Test from "./Test.mjs"; function decodeJsonTest() { let json = {"someProp":{"otherProp": null, "thirdProp": [true, false]}}; let decodedCorrectly; - if (!Array.isArray(json) && (json === null || typeof json !== "object") && typeof json !== "number" && typeof json !== "string" && typeof json !== "boolean" || !(typeof json === "object" && !Array.isArray(json))) { + if (json === null || !(typeof json === "object" && !Array.isArray(json))) { decodedCorrectly = false; } else { let match = json["someProp"]; - if (match !== undefined && !(!Array.isArray(match) && (match === null || typeof match !== "object") && typeof match !== "number" && typeof match !== "string" && typeof match !== "boolean" || !(typeof match === "object" && !Array.isArray(match)))) { + if (match !== undefined && !(match === null || !(typeof match === "object" && !Array.isArray(match)))) { let match$1 = match["thirdProp"]; - if (match$1 !== undefined && !(!Array.isArray(match$1) && (match$1 === null || typeof match$1 !== "object") && typeof match$1 !== "number" && typeof match$1 !== "string" && typeof match$1 !== "boolean" || !(Array.isArray(match$1) && match$1.length === 2))) { + if (match$1 !== undefined && !(match$1 === null || !(Array.isArray(match$1) && match$1.length === 2))) { let match$2 = match$1[0]; - if (!Array.isArray(match$2) && (match$2 === null || typeof match$2 !== "object") && typeof match$2 !== "number" && typeof match$2 !== "string" && typeof match$2 !== "boolean" || !(typeof match$2 === "boolean" && match$2)) { + if (match$2 === null || !(typeof match$2 === "boolean" && match$2)) { decodedCorrectly = false; } else { let match$3 = match$1[1]; - decodedCorrectly = !Array.isArray(match$3) && (match$3 === null || typeof match$3 !== "object") && typeof match$3 !== "number" && typeof match$3 !== "string" && typeof match$3 !== "boolean" || !(typeof match$3 === "boolean" && !match$3) ? false : true; + decodedCorrectly = match$3 === null || !(typeof match$3 === "boolean" && !match$3) ? false : true; } } else { decodedCorrectly = false; diff --git a/tests/tests/src/core/Core_NullableTests.mjs b/tests/tests/src/core/Core_NullableTests.mjs index 072aa64f28..6c0989d542 100644 --- a/tests/tests/src/core/Core_NullableTests.mjs +++ b/tests/tests/src/core/Core_NullableTests.mjs @@ -7,7 +7,7 @@ function shouldHandleNullableValues() { let tUndefined = undefined; let tValue = "hello"; let tmp; - tmp = (tNull === null || tNull === undefined) && tNull === null ? true : false; + tmp = (tNull === undefined || tNull === null) && tNull === null ? true : false; Test.run([ [ "Core_NullableTests.res", @@ -18,7 +18,7 @@ function shouldHandleNullableValues() { "Should handle null" ], tmp, (prim0, prim1) => prim0 === prim1, true); let tmp$1; - tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null ? true : false; + tmp$1 = (tUndefined === undefined || tUndefined === null) && tUndefined !== null ? true : false; Test.run([ [ "Core_NullableTests.res", @@ -29,7 +29,7 @@ function shouldHandleNullableValues() { "Should handle undefined" ], tmp$1, (prim0, prim1) => prim0 === prim1, true); let tmp$2; - tmp$2 = tValue === null || tValue === undefined || tValue !== "hello" ? false : true; + tmp$2 = tValue === undefined || tValue === null || tValue !== "hello" ? false : true; Test.run([ [ "Core_NullableTests.res", diff --git a/tests/tests/src/untagged_variants_heuristic.mjs b/tests/tests/src/untagged_variants_heuristic.mjs new file mode 100644 index 0000000000..9146fff377 --- /dev/null +++ b/tests/tests/src/untagged_variants_heuristic.mjs @@ -0,0 +1,22 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +function f(x) { + if (x !== null) { + return; + } + console.log("abc"); +} + +function ff(x) { + if (x === "G" || x === "F" || x === "E" || x === "D" || x === "C" || x === "B" || x === "A") { + return; + } + console.log("abc"); +} + +export { + f, + ff, +} +/* No side effect */ diff --git a/tests/tests/src/untagged_variants_heuristic.res b/tests/tests/src/untagged_variants_heuristic.res new file mode 100644 index 0000000000..2f068b207a --- /dev/null +++ b/tests/tests/src/untagged_variants_heuristic.res @@ -0,0 +1,22 @@ +let f = (x: JSON.t) => + switch x { + | Null => Console.log("abc") + | _ => () + } + +@unboxed +type t = + | A + | B + | C + | D + | E + | F + | G + | Int(int) + +let ff = (x: t) => + switch x { + | Int(_) => Console.log("abc") + | _ => () + } diff --git a/tests/tests/src/variantsMatching.mjs b/tests/tests/src/variantsMatching.mjs index 0a90661e6a..ad33c3903f 100644 --- a/tests/tests/src/variantsMatching.mjs +++ b/tests/tests/src/variantsMatching.mjs @@ -224,9 +224,9 @@ function isUndefined$1(x) { } function plus$2(x, y) { - if (x === null || x === undefined) { + if (x === undefined || x === null) { return y; - } else if (y === null || y === undefined) { + } else if (y === undefined || y === null) { return x; } else { return x + y | 0; @@ -234,7 +234,7 @@ function plus$2(x, y) { } function kind(x) { - if (x === null || x === undefined) { + if (x === undefined || x === null) { if (x === null) { return "null"; } else { @@ -274,7 +274,7 @@ function isWhyNot(x) { } function plus$3(x, y) { - if (x === undefined || x === null || x === "WhyNotAnotherOne") { + if (x === "WhyNotAnotherOne" || x === undefined || x === null) { switch (x) { case null : case undefined : @@ -282,13 +282,13 @@ function plus$3(x, y) { case "WhyNotAnotherOne" : break; } - } else if (!(y === undefined || y === null || y === "WhyNotAnotherOne")) { + } else if (!(y === "WhyNotAnotherOne" || y === undefined || y === null)) { return { x: x.x + y.x, y: x.y + y.y }; } - if (!(y === undefined || y === null || y === "WhyNotAnotherOne")) { + if (!(y === "WhyNotAnotherOne" || y === undefined || y === null)) { return "WhyNotAnotherOne"; } switch (y) { @@ -301,7 +301,7 @@ function plus$3(x, y) { } function kind$1(x) { - if (!(x === undefined || x === null || x === "WhyNotAnotherOne")) { + if (!(x === "WhyNotAnotherOne" || x === undefined || x === null)) { return "present"; } switch (x) { From 693fedf192f7cc250d4fdc86523646e38ffb7089 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 25 Oct 2024 14:00:14 +0200 Subject: [PATCH 2/5] Heuristic: size of generated code. --- compiler/ml/ast_untagged_variants.ml | 25 ++++++++++++++++--- tests/tests/src/UntaggedVariants.mjs | 4 +-- .../tests/src/untagged_variants_heuristic.mjs | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index 349c99f962..78e062bf40 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -372,6 +372,14 @@ module DynamicChecks = struct | Not of 'a t | Expr of 'a + let rec size = function + | BinOp (_, x, y) -> 1 + size x + size y + | TagType _ -> 1 + | TypeOf x -> 1 + size x + | IsInstanceOf (_, x) -> 1 + size x + | Not x -> 1 + size x + | Expr _ -> 1 + let bin op x y = BinOp (op, x, y) let tag_type t = TagType t let typeof x = TypeOf x @@ -396,7 +404,7 @@ module DynamicChecks = struct let ( &&& ) x y = bin And x y let rec is_a_literal_case ~(literal_cases : tag_type list) ~block_cases - (e : _ t) = + ~list_literal_cases (e : _ t) = let literals_overlaps_with_string () = Ext_list.exists literal_cases (function | String _ -> true @@ -458,7 +466,6 @@ module DynamicChecks = struct Ext_list.fold_right others is_literal_1 (fun literal_n acc -> is_literal_case literal_n ||| acc)) in - let list_literal_cases = true in if list_literal_cases then let rec mk cases = match cases with @@ -472,9 +479,21 @@ module DynamicChecks = struct | [c] -> is_not_block_case c | c1 :: (_ :: _ as rest) -> is_not_block_case c1 - &&& is_a_literal_case ~literal_cases ~block_cases:rest e + &&& is_a_literal_case ~literal_cases ~block_cases:rest + ~list_literal_cases e | [] -> assert false + let is_a_literal_case ~literal_cases ~block_cases e = + let with_literal_cases = + is_a_literal_case ~literal_cases ~block_cases ~list_literal_cases:true e + in + let without_literal_cases = + is_a_literal_case ~literal_cases ~block_cases ~list_literal_cases:false e + in + if size with_literal_cases <= size without_literal_cases then + with_literal_cases + else without_literal_cases + let is_int_tag ?(has_null_undefined_other = (false, false, false)) (e : _ t) : _ t = let has_null, has_undefined, has_other = has_null_undefined_other in diff --git a/tests/tests/src/UntaggedVariants.mjs b/tests/tests/src/UntaggedVariants.mjs index 41251e1d52..b14cc32108 100644 --- a/tests/tests/src/UntaggedVariants.mjs +++ b/tests/tests/src/UntaggedVariants.mjs @@ -24,7 +24,7 @@ function classify2(x) { } function cls(x) { - if (x === "Two" || x === "One") { + if (typeof x !== "object") { if (x === "One") { return "one"; } else { @@ -270,7 +270,7 @@ let OverlapNumber = { }; function checkEnum$2(e) { - if (!(e === "Three" || e === "Two" || e === null)) { + if (!(e === null || typeof e !== "object")) { return "Object..."; } switch (e) { diff --git a/tests/tests/src/untagged_variants_heuristic.mjs b/tests/tests/src/untagged_variants_heuristic.mjs index 9146fff377..66eb239c11 100644 --- a/tests/tests/src/untagged_variants_heuristic.mjs +++ b/tests/tests/src/untagged_variants_heuristic.mjs @@ -9,7 +9,7 @@ function f(x) { } function ff(x) { - if (x === "G" || x === "F" || x === "E" || x === "D" || x === "C" || x === "B" || x === "A") { + if (typeof x !== "number") { return; } console.log("abc"); From fc6f9e92562de32e5385ceb5047e5bf47254d628 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 25 Oct 2024 14:02:01 +0200 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c76a6809d..ef3f326b63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ - Improve output of record copying. https://github.com/rescript-lang/rescript-compiler/pull/7043 - Provide additional context in error message when `unit` is expected. https://github.com/rescript-lang/rescript-compiler/pull/7045 - Improve error message when passing an object where a record is expected. https://github.com/rescript-lang/rescript-compiler/pull/7101 +- Improve code generation or pattern matching of untagged variants. https://github.com/rescript-lang/rescript-compiler/pull/7128 #### :house: Internal From 6913da92f3d0f9755d4c6df704d509fa0ba0661d Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 26 Oct 2024 11:05:11 +0200 Subject: [PATCH 4/5] Bring ad-hoc simplification of && generation up to speed. --- compiler/core/js_exp_make.ml | 8 ++++++++ tests/tests/src/UntaggedVariants.mjs | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/core/js_exp_make.ml b/compiler/core/js_exp_make.ml index 5d9c197ddd..5997dafcce 100644 --- a/compiler/core/js_exp_make.ml +++ b/compiler/core/js_exp_make.ml @@ -673,6 +673,14 @@ let rec filter_bool (e : t) ~j ~b = match (filter_bool e1 ~j ~b, filter_bool e2 ~j ~b) with | None, _ | _, None -> None | Some e1, Some e2 -> Some {e with expression_desc = Bin (Or, e1, e2)}) + | Bin (EqEqEq, {expression_desc = Var i}, {expression_desc = Bool b1}) + | Bin (EqEqEq, {expression_desc = Bool b1}, {expression_desc = Var i}) + when Js_op_util.same_vident i j -> + if b1 = b then None else Some e + | Bin (NotEqEq, {expression_desc = Var i}, {expression_desc = Bool b1}) + | Bin (NotEqEq, {expression_desc = Bool b1}, {expression_desc = Var i}) + when Js_op_util.same_vident i j -> + if b1 <> b then None else Some e | Bin ( NotEqEq, {expression_desc = Typeof {expression_desc = Var i}}, diff --git a/tests/tests/src/UntaggedVariants.mjs b/tests/tests/src/UntaggedVariants.mjs index b14cc32108..bd867ca720 100644 --- a/tests/tests/src/UntaggedVariants.mjs +++ b/tests/tests/src/UntaggedVariants.mjs @@ -386,9 +386,9 @@ function check$1(s) { return; } let match = s[0]; - if ((match === null || match === true || match === false || match === undefined) && match === true) { + if (match === true) { let match$1 = s[1]; - if ((match$1 === null || match$1 === true || match$1 === false || match$1 === undefined) && match$1 === false) { + if (match$1 === false) { let match$2 = s[2]; if (match$2 === null || match$2 === true || match$2 === false || match$2 === undefined) { console.log("Nope..."); From b12f189b7f34863025540d1c49325b7c00a010e4 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 26 Oct 2024 11:15:02 +0200 Subject: [PATCH 5/5] respect declaration order --- compiler/ml/ast_untagged_variants.ml | 2 +- tests/tests/src/UntaggedVariants.mjs | 22 ++++++++++----------- tests/tests/src/core/Core_NullableTests.mjs | 6 +++--- tests/tests/src/variantsMatching.mjs | 14 ++++++------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index 78e062bf40..5e7df5cd69 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -468,7 +468,7 @@ module DynamicChecks = struct in if list_literal_cases then let rec mk cases = - match cases with + match List.rev cases with | [case] -> is_literal_case case | case :: rest -> is_literal_case case ||| mk rest | [] -> assert false diff --git a/tests/tests/src/UntaggedVariants.mjs b/tests/tests/src/UntaggedVariants.mjs index bd867ca720..6043df57ac 100644 --- a/tests/tests/src/UntaggedVariants.mjs +++ b/tests/tests/src/UntaggedVariants.mjs @@ -80,7 +80,7 @@ let Truthy = { }; function classify$1(x) { - if (x === undefined || x === null) { + if (x === null || x === undefined) { if (x === null) { return "null"; } else { @@ -96,7 +96,7 @@ let TwoObjects = { }; function classify$2(x) { - if (x === "B" || x === "A") { + if (x === "A" || x === "B") { if (x === "A") { return "a"; } else { @@ -112,7 +112,7 @@ let Unknown = { }; function classify$3(x) { - if (x === "D" || x === "C" || x === "B" || x === "A") { + if (x === "A" || x === "D" || x === "B" || x === "C") { switch (x) { case "A" : return "a"; @@ -173,7 +173,7 @@ let WithArray = { }; function classify$6(x) { - if (x === null || x === true || x === false) { + if (x === false || x === null || x === true) { switch (x) { case false : return "JSONFalse"; @@ -234,7 +234,7 @@ let TrickyNested = { }; function checkEnum(e) { - if (!(e === "Three" || e === "Two" || e === "One")) { + if (!(e === "One" || e === "Three" || e === "Two")) { return "Something else..." + e; } switch (e) { @@ -252,7 +252,7 @@ let OverlapString = { }; function checkEnum$1(e) { - if (!(e === "Three" || e === "Two" || e === 1.0)) { + if (!(e === 1.0 || e === "Three" || e === "Two")) { return "Something else..."; } switch (e) { @@ -376,7 +376,7 @@ let TestFunctionCase = { let someJson = '[{"name": "Haan"}, {"name": "Mr"}, false]'; function check$1(s) { - if (s === null || s === true || s === false || s === undefined) { + if (s === undefined || s === null || s === false || s === true) { console.log("Nope..."); return; } @@ -390,7 +390,7 @@ function check$1(s) { let match$1 = s[1]; if (match$1 === false) { let match$2 = s[2]; - if (match$2 === null || match$2 === true || match$2 === false || match$2 === undefined) { + if (match$2 === undefined || match$2 === null || match$2 === false || match$2 === true) { console.log("Nope..."); return; } @@ -400,13 +400,13 @@ function check$1(s) { return; } let match$3 = match$2[0]; - if (match$3 === null || match$3 === true || match$3 === false || match$3 === undefined) { + if (match$3 === undefined || match$3 === null || match$3 === false || match$3 === true) { console.log("Nope..."); return; } if (typeof match$3 === "string" && match$3 === "My name is") { let match$4 = match$2[1]; - if (match$4 === null || match$4 === true || match$4 === false || match$4 === undefined) { + if (match$4 === undefined || match$4 === null || match$4 === false || match$4 === true) { console.log("Nope..."); return; } @@ -476,7 +476,7 @@ let PromiseSync = { }; async function classify$10(a) { - if (a === 12 || a === "test") { + if (a === "test" || a === 12) { if (a === "test") { console.log("testing"); return; diff --git a/tests/tests/src/core/Core_NullableTests.mjs b/tests/tests/src/core/Core_NullableTests.mjs index 6c0989d542..072aa64f28 100644 --- a/tests/tests/src/core/Core_NullableTests.mjs +++ b/tests/tests/src/core/Core_NullableTests.mjs @@ -7,7 +7,7 @@ function shouldHandleNullableValues() { let tUndefined = undefined; let tValue = "hello"; let tmp; - tmp = (tNull === undefined || tNull === null) && tNull === null ? true : false; + tmp = (tNull === null || tNull === undefined) && tNull === null ? true : false; Test.run([ [ "Core_NullableTests.res", @@ -18,7 +18,7 @@ function shouldHandleNullableValues() { "Should handle null" ], tmp, (prim0, prim1) => prim0 === prim1, true); let tmp$1; - tmp$1 = (tUndefined === undefined || tUndefined === null) && tUndefined !== null ? true : false; + tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null ? true : false; Test.run([ [ "Core_NullableTests.res", @@ -29,7 +29,7 @@ function shouldHandleNullableValues() { "Should handle undefined" ], tmp$1, (prim0, prim1) => prim0 === prim1, true); let tmp$2; - tmp$2 = tValue === undefined || tValue === null || tValue !== "hello" ? false : true; + tmp$2 = tValue === null || tValue === undefined || tValue !== "hello" ? false : true; Test.run([ [ "Core_NullableTests.res", diff --git a/tests/tests/src/variantsMatching.mjs b/tests/tests/src/variantsMatching.mjs index ad33c3903f..498102609f 100644 --- a/tests/tests/src/variantsMatching.mjs +++ b/tests/tests/src/variantsMatching.mjs @@ -224,9 +224,9 @@ function isUndefined$1(x) { } function plus$2(x, y) { - if (x === undefined || x === null) { + if (x === null || x === undefined) { return y; - } else if (y === undefined || y === null) { + } else if (y === null || y === undefined) { return x; } else { return x + y | 0; @@ -234,7 +234,7 @@ function plus$2(x, y) { } function kind(x) { - if (x === undefined || x === null) { + if (x === null || x === undefined) { if (x === null) { return "null"; } else { @@ -274,7 +274,7 @@ function isWhyNot(x) { } function plus$3(x, y) { - if (x === "WhyNotAnotherOne" || x === undefined || x === null) { + if (x === null || x === "WhyNotAnotherOne" || x === undefined) { switch (x) { case null : case undefined : @@ -282,13 +282,13 @@ function plus$3(x, y) { case "WhyNotAnotherOne" : break; } - } else if (!(y === "WhyNotAnotherOne" || y === undefined || y === null)) { + } else if (!(y === null || y === "WhyNotAnotherOne" || y === undefined)) { return { x: x.x + y.x, y: x.y + y.y }; } - if (!(y === "WhyNotAnotherOne" || y === undefined || y === null)) { + if (!(y === null || y === "WhyNotAnotherOne" || y === undefined)) { return "WhyNotAnotherOne"; } switch (y) { @@ -301,7 +301,7 @@ function plus$3(x, y) { } function kind$1(x) { - if (!(x === "WhyNotAnotherOne" || x === undefined || x === null)) { + if (!(x === null || x === "WhyNotAnotherOne" || x === undefined)) { return "present"; } switch (x) {