diff --git a/compiler/core/lam_analysis.ml b/compiler/core/lam_analysis.ml index a95b382ca2..a48ffaaf14 100644 --- a/compiler/core/lam_analysis.ml +++ b/compiler/core/lam_analysis.ml @@ -97,8 +97,8 @@ let rec no_side_effects (lam : Lam.t) : bool = (* TODO *) | Praw_js_code _ (* byte swap *) - | Parraysets | Parraysetu | Poffsetref _ | Praise | Plazyforce | Psetfield _ - -> + | Parraysets | Parraysetu | Poffsetref _ | Praise | Passert | Plazyforce + | Psetfield _ -> false) | Llet (_, _, arg, body) -> no_side_effects arg && no_side_effects body | Lswitch (_, _) -> false diff --git a/compiler/core/lam_compile.ml b/compiler/core/lam_compile.ml index 22b3ffa2b8..d2621928cc 100644 --- a/compiler/core/lam_compile.ml +++ b/compiler/core/lam_compile.ml @@ -1543,6 +1543,42 @@ let compile output_prefix = | Fld_module {name = field} -> compile_external_field ~dynamic_import lambda_cxt id field | _ -> assert false) + | {primitive = Passert; args = [e]; _} -> ( + match + compile_lambda {lambda_cxt with continuation = NeedValue Not_tail} e + with + | {block; value = Some v} -> + let loc_start = prim_info.loc.loc_start in + let payload = + E.array Js_op.Immutable + [ + E.str (loc_start.pos_fname |> Filename.basename); + E.int (Int32.of_int loc_start.pos_lnum); + E.int (Int32.of_int (loc_start.pos_cnum - loc_start.pos_bol)); + ] + in + + let block_expr = + Js_exp_make.make_block payload Blk_extension + (E.str "Assert_failure" :: [payload]) + Immutable + in + + let else_ = + if !Clflags.no_assert_false then S.exp E.undefined + else S.throw_stmt block_expr + in + + let result = + Js_output.make + [S.if_ v block ~else_:[else_]] + ~value:E.undefined ~output_finished:False + in + (* let _a = *) + (* if !Clflags.no_assert_false then Js_output.make block else result *) + (* in *) + result + | {value = None} -> assert false) | {primitive = Praise; args = [e]; _} -> ( match compile_lambda {lambda_cxt with continuation = NeedValue Not_tail} e diff --git a/compiler/core/lam_compile_primitive.ml b/compiler/core/lam_compile_primitive.ml index 47c255afb2..405d39f3db 100644 --- a/compiler/core/lam_compile_primitive.ml +++ b/compiler/core/lam_compile_primitive.ml @@ -533,6 +533,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | _ -> assert false) (* only when Lapply -> expand = true*) | Praise -> assert false (* handled before here *) + | Passert -> assert false (* Runtime encoding relevant *) | Parraylength -> E.array_length (Ext_list.singleton_exn args) | Psetfield (i, field_info) -> ( diff --git a/compiler/core/lam_convert.ml b/compiler/core/lam_convert.ml index 74131236ab..a28aeb3731 100644 --- a/compiler/core/lam_convert.ml +++ b/compiler/core/lam_convert.ml @@ -232,6 +232,7 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Pduprecord -> prim ~primitive:Pduprecord ~args loc | Plazyforce -> prim ~primitive:Plazyforce ~args loc | Praise _ -> prim ~primitive:Praise ~args loc + | Passert -> prim ~primitive:Passert ~args loc | Pobjcomp x -> prim ~primitive:(Pobjcomp x) ~args loc | Pobjorder -> prim ~primitive:Pobjorder ~args loc | Pobjmin -> prim ~primitive:Pobjmin ~args loc diff --git a/compiler/core/lam_primitive.ml b/compiler/core/lam_primitive.ml index 21cedb23e5..b480e473f8 100644 --- a/compiler/core/lam_primitive.ml +++ b/compiler/core/lam_primitive.ml @@ -52,6 +52,7 @@ type t = | Pjs_object_create of External_arg_spec.obj_params (* Exceptions *) | Praise + | Passert (* object primitives *) | Pobjcomp of Lam_compat.comparison | Pobjorder @@ -193,7 +194,7 @@ let eq_tag_info (x : Lam_tag_info.t) y = x = y let eq_primitive_approx (lhs : t) (rhs : t) = match lhs with - | Pwrap_exn | Praise + | Pwrap_exn | Praise | Passert (* generic comparison *) | Pobjorder | Pobjmin | Pobjmax | Pobjtag | Pobjsize (* bool primitives *) diff --git a/compiler/core/lam_primitive.mli b/compiler/core/lam_primitive.mli index 4f358b525a..0f1dedd018 100644 --- a/compiler/core/lam_primitive.mli +++ b/compiler/core/lam_primitive.mli @@ -46,6 +46,7 @@ type t = } | Pjs_object_create of External_arg_spec.obj_params | Praise + | Passert (* object primitives *) | Pobjcomp of Lam_compat.comparison | Pobjorder diff --git a/compiler/core/lam_print.ml b/compiler/core/lam_print.ml index 17c18d6108..2dd996d0d4 100644 --- a/compiler/core/lam_print.ml +++ b/compiler/core/lam_print.ml @@ -86,6 +86,7 @@ let primitive ppf (prim : Lam_primitive.t) = | Pjs_call {prim_name} -> fprintf ppf "%s[js]" prim_name | Pjs_object_create _ -> fprintf ppf "[js.obj]" | Praise -> fprintf ppf "raise" + | Passert -> fprintf ppf "assert" | Pobjcomp Ceq -> fprintf ppf "==" | Pobjcomp Cneq -> fprintf ppf "!=" | Pobjcomp Clt -> fprintf ppf "<" diff --git a/compiler/ml/lambda.ml b/compiler/ml/lambda.ml index fcd1dc86ca..7a0ba3e8c4 100644 --- a/compiler/ml/lambda.ml +++ b/compiler/ml/lambda.ml @@ -198,6 +198,7 @@ type primitive = | Pccall of Primitive.description (* Exceptions *) | Praise of raise_kind + | Passert (* object operations *) | Pobjcomp of comparison | Pobjorder diff --git a/compiler/ml/lambda.mli b/compiler/ml/lambda.mli index 7f506ac62d..dc75b447b2 100644 --- a/compiler/ml/lambda.mli +++ b/compiler/ml/lambda.mli @@ -161,6 +161,7 @@ type primitive = | Pccall of Primitive.description (* Exceptions *) | Praise of raise_kind + | Passert (* object primitives *) | Pobjcomp of comparison | Pobjorder diff --git a/compiler/ml/predef.mli b/compiler/ml/predef.mli index 7919b802ee..493817052c 100644 --- a/compiler/ml/predef.mli +++ b/compiler/ml/predef.mli @@ -54,6 +54,7 @@ val path_promise : Path.t val path_uncurried : Path.t val path_match_failure : Path.t + val path_assert_failure : Path.t val path_undefined_recursive_module : Path.t diff --git a/compiler/ml/printlambda.ml b/compiler/ml/printlambda.ml index 4512355c34..d0d9a5afeb 100644 --- a/compiler/ml/printlambda.ml +++ b/compiler/ml/printlambda.ml @@ -125,6 +125,7 @@ let primitive ppf = function | Plazyforce -> fprintf ppf "force" | Pccall p -> fprintf ppf "%s" p.prim_name | Praise k -> fprintf ppf "%s" (Lambda.raise_kind k) + | Passert -> fprintf ppf "assert" | Pobjcomp Ceq -> fprintf ppf "==" | Pobjcomp Cneq -> fprintf ppf "!=" | Pobjcomp Clt -> fprintf ppf "<" diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index a3f61e8990..e9a7ab71a1 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -259,6 +259,7 @@ let primitives_table = ("%obj_get_field", Parrayrefu); ("%obj_set_field", Parraysetu); ("%raise", Praise Raise_regular); + ("%assert", Passert); (* bool primitives *) ("%sequand", Psequand); ("%sequor", Psequor); diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 7538874010..2970e64937 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -2147,15 +2147,9 @@ and parse_unary_expr p = * If you have `a + b`, `a` and `b` both represent * the operands of the binary expression with opeartor `+` *) and parse_operand_expr ~context p = - let start_pos = p.Parser.start_pos in let attrs = ref (parse_attributes p) in let expr = match p.Parser.token with - | Assert -> - Parser.next p; - let expr = parse_expr p in - let loc = mk_loc start_pos p.prev_end_pos in - Ast_helper.Exp.assert_ ~loc expr | Lident "async" (* we need to be careful when we're in a ternary true branch: `condition ? ternary-true-branch : false-branch` diff --git a/compiler/syntax/src/res_grammar.ml b/compiler/syntax/src/res_grammar.ml index 63dc9d6c33..44d76caaa2 100644 --- a/compiler/syntax/src/res_grammar.ml +++ b/compiler/syntax/src/res_grammar.ml @@ -149,10 +149,10 @@ let is_atomic_typ_expr_start = function | _ -> false let is_expr_start = function - | Token.Assert | At | Await | Backtick | Bang | Codepoint _ | False | Float _ - | For | Hash | If | Int _ | Lbrace | Lbracket | LessThan | Lident _ | List - | Lparen | Minus | MinusDot | Module | Percent | Plus | PlusDot | String _ - | Switch | True | Try | Uident _ | Underscore (* _ => doThings() *) + | Token.At | Await | Backtick | Bang | Codepoint _ | False | Float _ | For + | Hash | If | Int _ | Lbrace | Lbracket | LessThan | Lident _ | List | Lparen + | Minus | MinusDot | Module | Percent | Plus | PlusDot | String _ | Switch + | True | Try | Uident _ | Underscore (* _ => doThings() *) | While | Forwardslash | ForwardslashDot | Dict -> true | _ -> false @@ -263,11 +263,11 @@ let is_attribute_start = function let is_jsx_child_start = is_atomic_expr_start let is_block_expr_start = function - | Token.Assert | At | Await | Backtick | Bang | Codepoint _ | Exception - | False | Float _ | For | Forwardslash | ForwardslashDot | Hash | If | Int _ - | Lbrace | Lbracket | LessThan | Let | Lident _ | List | Lparen | Minus - | MinusDot | Module | Open | Percent | Plus | PlusDot | String _ | Switch - | True | Try | Uident _ | Underscore | While | Dict -> + | Token.At | Await | Backtick | Bang | Codepoint _ | Exception | False + | Float _ | For | Forwardslash | ForwardslashDot | Hash | If | Int _ | Lbrace + | Lbracket | LessThan | Let | Lident _ | List | Lparen | Minus | MinusDot + | Module | Open | Percent | Plus | PlusDot | String _ | Switch | True | Try + | Uident _ | Underscore | While | Dict -> true | _ -> false diff --git a/compiler/syntax/src/res_token.ml b/compiler/syntax/src/res_token.ml index b55d7c0ec7..bfcaa942ae 100644 --- a/compiler/syntax/src/res_token.ml +++ b/compiler/syntax/src/res_token.ml @@ -55,7 +55,6 @@ type t = | LessThanSlash | Hash | HashEqual - | Assert | Tilde | Question | If @@ -167,7 +166,6 @@ let to_string = function | Asterisk -> "*" | AsteriskDot -> "*." | Exponentiation -> "**" - | Assert -> "assert" | Tilde -> "tilde" | Question -> "?" | If -> "if" @@ -213,7 +211,6 @@ let to_string = function let keyword_table = function | "and" -> And | "as" -> As - | "assert" -> Assert | "await" -> Await | "constraint" -> Constraint | "else" -> Else @@ -243,9 +240,9 @@ let keyword_table = function [@@raises Not_found] let is_keyword = function - | Await | And | As | Assert | Constraint | Else | Exception | External | False - | For | If | In | Include | Land | Let | List | Lor | Module | Mutable | Of - | Open | Private | Rec | Switch | True | Try | Typ | When | While | Dict -> + | Await | And | As | Constraint | Else | Exception | External | False | For + | If | In | Include | Land | Let | List | Lor | Module | Mutable | Of | Open + | Private | Rec | Switch | True | Try | Typ | When | While | Dict -> true | _ -> false diff --git a/lib/es6/Belt_List.js b/lib/es6/Belt_List.js index 22455cc2e0..789d9e9d59 100644 --- a/lib/es6/Belt_List.js +++ b/lib/es6/Belt_List.js @@ -1231,16 +1231,23 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } return [ nextX, - nextY.tl - ]; - } else { - return [ - nextX.tl, - nextY + tmp ]; } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; + } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/lib/es6/Belt_internalAVLset.js b/lib/es6/Belt_internalAVLset.js index bcc1ca58f8..da87b79253 100644 --- a/lib/es6/Belt_internalAVLset.js +++ b/lib/es6/Belt_internalAVLset.js @@ -55,30 +55,41 @@ function bal(l, v, r) { let hl = l !== undefined ? l.h : 0; let hr = r !== undefined ? r.h : 0; if (hl > (hr + 2 | 0)) { - let ll = l.l; - let lr = l.r; - if (heightGe(ll, lr)) { - return create(ll, l.v, create(lr, v, r)); - } else { - return create(create(ll, l.v, lr.l), lr.v, create(lr.r, v, r)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (heightGe(ll, lr)) { + return create(ll, l.v, create(lr, v, r)); + } + if (lr !== undefined) { + return create(create(ll, l.v, lr.l), lr.v, create(lr.r, v, r)); + } + } - } - if (hr <= (hl + 2 | 0)) { - return { - v: v, - h: ( - hl >= hr ? hl : hr - ) + 1 | 0, - l: l, - r: r - }; - } - let rl = r.l; - let rr = r.r; - if (heightGe(rr, rl)) { - return create(create(l, v, rl), r.v, rr); + } else { - return create(create(l, v, rl.l), rl.v, create(rl.r, r.v, rr)); + if (hr <= (hl + 2 | 0)) { + return { + v: v, + h: ( + hl >= hr ? hl : hr + ) + 1 | 0, + l: l, + r: r + }; + } + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return create(create(l, v, rl), r.v, rr); + } + if (rl !== undefined) { + return create(create(l, v, rl.l), rl.v, create(rl.r, r.v, rr)); + } + + } + } } @@ -350,15 +361,7 @@ function checkInvariantInternal(_v) { r !== undefined ? r.h : 0 ) | 0; if (!(diff <= 2 && diff >= -2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 310, - 4 - ], - Error: new Error() - }; + } checkInvariantInternal(l); _v = r; @@ -709,48 +712,60 @@ function getExn(_n, x, cmp) { function rotateWithLeftChild(k2) { let k1 = k2.l; - k2.l = k1.r; - k1.r = k2; - let n = k2.l; - let hlk2 = n !== undefined ? n.h : 0; - let n$1 = k2.r; - let hrk2 = n$1 !== undefined ? n$1.h : 0; - k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; - let n$2 = k1.l; - let hlk1 = n$2 !== undefined ? n$2.h : 0; - let hk2 = k2.h; - k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; - return k1; + if (k1 !== undefined) { + k2.l = k1.r; + k1.r = k2; + let n = k2.l; + let hlk2 = n !== undefined ? n.h : 0; + let n$1 = k2.r; + let hrk2 = n$1 !== undefined ? n$1.h : 0; + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; + let n$2 = k1.l; + let hlk1 = n$2 !== undefined ? n$2.h : 0; + let hk2 = k2.h; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; + return k1; + } + } function rotateWithRightChild(k1) { let k2 = k1.r; - k1.r = k2.l; - k2.l = k1; - let n = k1.l; - let hlk1 = n !== undefined ? n.h : 0; - let n$1 = k1.r; - let hrk1 = n$1 !== undefined ? n$1.h : 0; - k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; - let n$2 = k2.r; - let hrk2 = n$2 !== undefined ? n$2.h : 0; - let hk1 = k1.h; - k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; - return k2; + if (k2 !== undefined) { + k1.r = k2.l; + k2.l = k1; + let n = k1.l; + let hlk1 = n !== undefined ? n.h : 0; + let n$1 = k1.r; + let hrk1 = n$1 !== undefined ? n$1.h : 0; + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; + let n$2 = k2.r; + let hrk2 = n$2 !== undefined ? n$2.h : 0; + let hk1 = k1.h; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; + return k2; + } + } function doubleWithLeftChild(k3) { let k3l = k3.l; - let v = rotateWithRightChild(k3l); - k3.l = v; - return rotateWithLeftChild(k3); + if (k3l !== undefined) { + let v = rotateWithRightChild(k3l); + k3.l = v; + return rotateWithLeftChild(k3); + } + } function doubleWithRightChild(k2) { let k2r = k2.r; - let v = rotateWithLeftChild(k2r); - k2.r = v; - return rotateWithRightChild(k2); + if (k2r !== undefined) { + let v = rotateWithLeftChild(k2r); + k2.r = v; + return rotateWithRightChild(k2); + } + } function heightUpdateMutate(t) { @@ -768,25 +783,31 @@ function balMutate(nt) { let hl = l !== undefined ? l.h : 0; let hr = r !== undefined ? r.h : 0; if (hl > (2 + hr | 0)) { - let ll = l.l; - let lr = l.r; - if (heightGe(ll, lr)) { - return heightUpdateMutate(rotateWithLeftChild(nt)); - } else { - return heightUpdateMutate(doubleWithLeftChild(nt)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (heightGe(ll, lr)) { + return heightUpdateMutate(rotateWithLeftChild(nt)); + } else { + return heightUpdateMutate(doubleWithLeftChild(nt)); + } } - } - if (hr > (2 + hl | 0)) { - let rl = r.l; - let rr = r.r; - if (heightGe(rr, rl)) { - return heightUpdateMutate(rotateWithRightChild(nt)); - } else { - return heightUpdateMutate(doubleWithRightChild(nt)); + + } else if (hr > (2 + hl | 0)) { + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + + } else { + nt.h = Primitive_int.max(hl, hr) + 1 | 0; + return nt; } - nt.h = Primitive_int.max(hl, hr) + 1 | 0; - return nt; } function addMutate(cmp, t, x) { diff --git a/lib/es6/Belt_internalAVLtree.js b/lib/es6/Belt_internalAVLtree.js index c5454dafda..555df157d6 100644 --- a/lib/es6/Belt_internalAVLtree.js +++ b/lib/es6/Belt_internalAVLtree.js @@ -78,29 +78,40 @@ function bal(l, x, d, r) { let hl = l !== undefined ? l.h : 0; let hr = r !== undefined ? r.h : 0; if (hl > (hr + 2 | 0)) { - let ll = l.l; - let lr = l.r; - if (treeHeight(ll) >= treeHeight(lr)) { - return create(ll, l.k, l.v, create(lr, x, d, r)); - } else { - return create(create(ll, l.k, l.v, lr.l), lr.k, lr.v, create(lr.r, x, d, r)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (treeHeight(ll) >= treeHeight(lr)) { + return create(ll, l.k, l.v, create(lr, x, d, r)); + } + if (lr !== undefined) { + return create(create(ll, l.k, l.v, lr.l), lr.k, lr.v, create(lr.r, x, d, r)); + } + } - } - if (hr <= (hl + 2 | 0)) { - return { - k: x, - v: d, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0, - l: l, - r: r - }; - } - let rl = r.l; - let rr = r.r; - if (treeHeight(rr) >= treeHeight(rl)) { - return create(create(l, x, d, rl), r.k, r.v, rr); + } else { - return create(create(l, x, d, rl.l), rl.k, rl.v, create(rl.r, r.k, r.v, rr)); + if (hr <= (hl + 2 | 0)) { + return { + k: x, + v: d, + h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0, + l: l, + r: r + }; + } + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (treeHeight(rr) >= treeHeight(rl)) { + return create(create(l, x, d, rl), r.k, r.v, rr); + } + if (rl !== undefined) { + return create(create(l, x, d, rl.l), rl.k, rl.v, create(rl.r, r.k, r.v, rr)); + } + + } + } } @@ -547,15 +558,7 @@ function checkInvariantInternal(_v) { let r = v.r; let diff = treeHeight(l) - treeHeight(r) | 0; if (!(diff <= 2 && diff >= -2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 439, - 4 - ], - Error: new Error() - }; + } checkInvariantInternal(l); _v = r; @@ -890,40 +893,54 @@ function has(_n, x, cmp) { function rotateWithLeftChild(k2) { let k1 = k2.l; - k2.l = k1.r; - k1.r = k2; - let hlk2 = treeHeight(k2.l); - let hrk2 = treeHeight(k2.r); - k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; - let hlk1 = treeHeight(k1.l); - let hk2 = k2.h; - k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; - return k1; + if (k1 !== undefined) { + k2.l = k1.r; + k1.r = k2; + let hlk2 = treeHeight(k2.l); + let hrk2 = treeHeight(k2.r); + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; + let hlk1 = treeHeight(k1.l); + let hk2 = k2.h; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; + return k1; + } + } function rotateWithRightChild(k1) { let k2 = k1.r; - k1.r = k2.l; - k2.l = k1; - let hlk1 = treeHeight(k1.l); - let hrk1 = treeHeight(k1.r); - k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; - let hrk2 = treeHeight(k2.r); - let hk1 = k1.h; - k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; - return k2; + if (k2 !== undefined) { + k1.r = k2.l; + k2.l = k1; + let hlk1 = treeHeight(k1.l); + let hrk1 = treeHeight(k1.r); + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; + let hrk2 = treeHeight(k2.r); + let hk1 = k1.h; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; + return k2; + } + } function doubleWithLeftChild(k3) { let x = k3.l; - let v = rotateWithRightChild(x); + let k3l; + if (x !== undefined) { + k3l = x; + } + let v = rotateWithRightChild(k3l); k3.l = v; return rotateWithLeftChild(k3); } function doubleWithRightChild(k2) { let x = k2.r; - let v = rotateWithLeftChild(x); + let k2r; + if (x !== undefined) { + k2r = x; + } + let v = rotateWithLeftChild(k2r); k2.r = v; return rotateWithRightChild(k2); } @@ -941,25 +958,31 @@ function balMutate(nt) { let hl = treeHeight(l); let hr = treeHeight(r); if (hl > (2 + hr | 0)) { - let ll = l.l; - let lr = l.r; - if (heightGe(ll, lr)) { - return heightUpdateMutate(rotateWithLeftChild(nt)); - } else { - return heightUpdateMutate(doubleWithLeftChild(nt)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (heightGe(ll, lr)) { + return heightUpdateMutate(rotateWithLeftChild(nt)); + } else { + return heightUpdateMutate(doubleWithLeftChild(nt)); + } } - } - if (hr > (2 + hl | 0)) { - let rl = r.l; - let rr = r.r; - if (heightGe(rr, rl)) { - return heightUpdateMutate(rotateWithRightChild(nt)); - } else { - return heightUpdateMutate(doubleWithRightChild(nt)); + + } else if (hr > (2 + hl | 0)) { + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + + } else { + nt.h = Primitive_int.max(hl, hr) + 1 | 0; + return nt; } - nt.h = Primitive_int.max(hl, hr) + 1 | 0; - return nt; } function updateMutate(t, x, data, cmp) { diff --git a/lib/es6/Belt_internalMapInt.js b/lib/es6/Belt_internalMapInt.js index 698255f843..8561e3f3c4 100644 --- a/lib/es6/Belt_internalMapInt.js +++ b/lib/es6/Belt_internalMapInt.js @@ -199,12 +199,15 @@ function merge(s1, s2, f) { } else if (s2 === undefined) { return; } - let v2 = s2.k; - let d2 = s2.v; - let l2 = s2.l; - let r2 = s2.r; - let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + if (s2 !== undefined) { + let v2 = s2.k; + let d2 = s2.v; + let l2 = s2.l; + let r2 = s2.r; + let match$1 = split(v2, s1); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + } + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/es6/Belt_internalMapString.js b/lib/es6/Belt_internalMapString.js index 9083d62782..3918ef0719 100644 --- a/lib/es6/Belt_internalMapString.js +++ b/lib/es6/Belt_internalMapString.js @@ -199,12 +199,15 @@ function merge(s1, s2, f) { } else if (s2 === undefined) { return; } - let v2 = s2.k; - let d2 = s2.v; - let l2 = s2.l; - let r2 = s2.r; - let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + if (s2 !== undefined) { + let v2 = s2.k; + let d2 = s2.v; + let l2 = s2.l; + let r2 = s2.r; + let match$1 = split(v2, s1); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + } + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/es6/List.js b/lib/es6/List.js index 06760467a5..ff9c8048a5 100644 --- a/lib/es6/List.js +++ b/lib/es6/List.js @@ -1243,16 +1243,23 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } return [ nextX, - nextY.tl - ]; - } else { - return [ - nextX.tl, - nextY + tmp ]; } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; + } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/lib/js/Belt_List.js b/lib/js/Belt_List.js index 2d9f0e17ec..9767f18421 100644 --- a/lib/js/Belt_List.js +++ b/lib/js/Belt_List.js @@ -1231,16 +1231,23 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } return [ nextX, - nextY.tl - ]; - } else { - return [ - nextX.tl, - nextY + tmp ]; } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; + } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/lib/js/Belt_internalAVLset.js b/lib/js/Belt_internalAVLset.js index 6e17ca2e5f..0e218d9390 100644 --- a/lib/js/Belt_internalAVLset.js +++ b/lib/js/Belt_internalAVLset.js @@ -55,30 +55,41 @@ function bal(l, v, r) { let hl = l !== undefined ? l.h : 0; let hr = r !== undefined ? r.h : 0; if (hl > (hr + 2 | 0)) { - let ll = l.l; - let lr = l.r; - if (heightGe(ll, lr)) { - return create(ll, l.v, create(lr, v, r)); - } else { - return create(create(ll, l.v, lr.l), lr.v, create(lr.r, v, r)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (heightGe(ll, lr)) { + return create(ll, l.v, create(lr, v, r)); + } + if (lr !== undefined) { + return create(create(ll, l.v, lr.l), lr.v, create(lr.r, v, r)); + } + } - } - if (hr <= (hl + 2 | 0)) { - return { - v: v, - h: ( - hl >= hr ? hl : hr - ) + 1 | 0, - l: l, - r: r - }; - } - let rl = r.l; - let rr = r.r; - if (heightGe(rr, rl)) { - return create(create(l, v, rl), r.v, rr); + } else { - return create(create(l, v, rl.l), rl.v, create(rl.r, r.v, rr)); + if (hr <= (hl + 2 | 0)) { + return { + v: v, + h: ( + hl >= hr ? hl : hr + ) + 1 | 0, + l: l, + r: r + }; + } + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return create(create(l, v, rl), r.v, rr); + } + if (rl !== undefined) { + return create(create(l, v, rl.l), rl.v, create(rl.r, r.v, rr)); + } + + } + } } @@ -350,15 +361,7 @@ function checkInvariantInternal(_v) { r !== undefined ? r.h : 0 ) | 0; if (!(diff <= 2 && diff >= -2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 310, - 4 - ], - Error: new Error() - }; + } checkInvariantInternal(l); _v = r; @@ -709,48 +712,60 @@ function getExn(_n, x, cmp) { function rotateWithLeftChild(k2) { let k1 = k2.l; - k2.l = k1.r; - k1.r = k2; - let n = k2.l; - let hlk2 = n !== undefined ? n.h : 0; - let n$1 = k2.r; - let hrk2 = n$1 !== undefined ? n$1.h : 0; - k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; - let n$2 = k1.l; - let hlk1 = n$2 !== undefined ? n$2.h : 0; - let hk2 = k2.h; - k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; - return k1; + if (k1 !== undefined) { + k2.l = k1.r; + k1.r = k2; + let n = k2.l; + let hlk2 = n !== undefined ? n.h : 0; + let n$1 = k2.r; + let hrk2 = n$1 !== undefined ? n$1.h : 0; + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; + let n$2 = k1.l; + let hlk1 = n$2 !== undefined ? n$2.h : 0; + let hk2 = k2.h; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; + return k1; + } + } function rotateWithRightChild(k1) { let k2 = k1.r; - k1.r = k2.l; - k2.l = k1; - let n = k1.l; - let hlk1 = n !== undefined ? n.h : 0; - let n$1 = k1.r; - let hrk1 = n$1 !== undefined ? n$1.h : 0; - k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; - let n$2 = k2.r; - let hrk2 = n$2 !== undefined ? n$2.h : 0; - let hk1 = k1.h; - k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; - return k2; + if (k2 !== undefined) { + k1.r = k2.l; + k2.l = k1; + let n = k1.l; + let hlk1 = n !== undefined ? n.h : 0; + let n$1 = k1.r; + let hrk1 = n$1 !== undefined ? n$1.h : 0; + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; + let n$2 = k2.r; + let hrk2 = n$2 !== undefined ? n$2.h : 0; + let hk1 = k1.h; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; + return k2; + } + } function doubleWithLeftChild(k3) { let k3l = k3.l; - let v = rotateWithRightChild(k3l); - k3.l = v; - return rotateWithLeftChild(k3); + if (k3l !== undefined) { + let v = rotateWithRightChild(k3l); + k3.l = v; + return rotateWithLeftChild(k3); + } + } function doubleWithRightChild(k2) { let k2r = k2.r; - let v = rotateWithLeftChild(k2r); - k2.r = v; - return rotateWithRightChild(k2); + if (k2r !== undefined) { + let v = rotateWithLeftChild(k2r); + k2.r = v; + return rotateWithRightChild(k2); + } + } function heightUpdateMutate(t) { @@ -768,25 +783,31 @@ function balMutate(nt) { let hl = l !== undefined ? l.h : 0; let hr = r !== undefined ? r.h : 0; if (hl > (2 + hr | 0)) { - let ll = l.l; - let lr = l.r; - if (heightGe(ll, lr)) { - return heightUpdateMutate(rotateWithLeftChild(nt)); - } else { - return heightUpdateMutate(doubleWithLeftChild(nt)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (heightGe(ll, lr)) { + return heightUpdateMutate(rotateWithLeftChild(nt)); + } else { + return heightUpdateMutate(doubleWithLeftChild(nt)); + } } - } - if (hr > (2 + hl | 0)) { - let rl = r.l; - let rr = r.r; - if (heightGe(rr, rl)) { - return heightUpdateMutate(rotateWithRightChild(nt)); - } else { - return heightUpdateMutate(doubleWithRightChild(nt)); + + } else if (hr > (2 + hl | 0)) { + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + + } else { + nt.h = Primitive_int.max(hl, hr) + 1 | 0; + return nt; } - nt.h = Primitive_int.max(hl, hr) + 1 | 0; - return nt; } function addMutate(cmp, t, x) { diff --git a/lib/js/Belt_internalAVLtree.js b/lib/js/Belt_internalAVLtree.js index 278f2a4141..f4a2ac657b 100644 --- a/lib/js/Belt_internalAVLtree.js +++ b/lib/js/Belt_internalAVLtree.js @@ -78,29 +78,40 @@ function bal(l, x, d, r) { let hl = l !== undefined ? l.h : 0; let hr = r !== undefined ? r.h : 0; if (hl > (hr + 2 | 0)) { - let ll = l.l; - let lr = l.r; - if (treeHeight(ll) >= treeHeight(lr)) { - return create(ll, l.k, l.v, create(lr, x, d, r)); - } else { - return create(create(ll, l.k, l.v, lr.l), lr.k, lr.v, create(lr.r, x, d, r)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (treeHeight(ll) >= treeHeight(lr)) { + return create(ll, l.k, l.v, create(lr, x, d, r)); + } + if (lr !== undefined) { + return create(create(ll, l.k, l.v, lr.l), lr.k, lr.v, create(lr.r, x, d, r)); + } + } - } - if (hr <= (hl + 2 | 0)) { - return { - k: x, - v: d, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0, - l: l, - r: r - }; - } - let rl = r.l; - let rr = r.r; - if (treeHeight(rr) >= treeHeight(rl)) { - return create(create(l, x, d, rl), r.k, r.v, rr); + } else { - return create(create(l, x, d, rl.l), rl.k, rl.v, create(rl.r, r.k, r.v, rr)); + if (hr <= (hl + 2 | 0)) { + return { + k: x, + v: d, + h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0, + l: l, + r: r + }; + } + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (treeHeight(rr) >= treeHeight(rl)) { + return create(create(l, x, d, rl), r.k, r.v, rr); + } + if (rl !== undefined) { + return create(create(l, x, d, rl.l), rl.k, rl.v, create(rl.r, r.k, r.v, rr)); + } + + } + } } @@ -547,15 +558,7 @@ function checkInvariantInternal(_v) { let r = v.r; let diff = treeHeight(l) - treeHeight(r) | 0; if (!(diff <= 2 && diff >= -2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 439, - 4 - ], - Error: new Error() - }; + } checkInvariantInternal(l); _v = r; @@ -890,40 +893,54 @@ function has(_n, x, cmp) { function rotateWithLeftChild(k2) { let k1 = k2.l; - k2.l = k1.r; - k1.r = k2; - let hlk2 = treeHeight(k2.l); - let hrk2 = treeHeight(k2.r); - k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; - let hlk1 = treeHeight(k1.l); - let hk2 = k2.h; - k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; - return k1; + if (k1 !== undefined) { + k2.l = k1.r; + k1.r = k2; + let hlk2 = treeHeight(k2.l); + let hrk2 = treeHeight(k2.r); + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; + let hlk1 = treeHeight(k1.l); + let hk2 = k2.h; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; + return k1; + } + } function rotateWithRightChild(k1) { let k2 = k1.r; - k1.r = k2.l; - k2.l = k1; - let hlk1 = treeHeight(k1.l); - let hrk1 = treeHeight(k1.r); - k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; - let hrk2 = treeHeight(k2.r); - let hk1 = k1.h; - k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; - return k2; + if (k2 !== undefined) { + k1.r = k2.l; + k2.l = k1; + let hlk1 = treeHeight(k1.l); + let hrk1 = treeHeight(k1.r); + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; + let hrk2 = treeHeight(k2.r); + let hk1 = k1.h; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; + return k2; + } + } function doubleWithLeftChild(k3) { let x = k3.l; - let v = rotateWithRightChild(x); + let k3l; + if (x !== undefined) { + k3l = x; + } + let v = rotateWithRightChild(k3l); k3.l = v; return rotateWithLeftChild(k3); } function doubleWithRightChild(k2) { let x = k2.r; - let v = rotateWithLeftChild(x); + let k2r; + if (x !== undefined) { + k2r = x; + } + let v = rotateWithLeftChild(k2r); k2.r = v; return rotateWithRightChild(k2); } @@ -941,25 +958,31 @@ function balMutate(nt) { let hl = treeHeight(l); let hr = treeHeight(r); if (hl > (2 + hr | 0)) { - let ll = l.l; - let lr = l.r; - if (heightGe(ll, lr)) { - return heightUpdateMutate(rotateWithLeftChild(nt)); - } else { - return heightUpdateMutate(doubleWithLeftChild(nt)); + if (l !== undefined) { + let ll = l.l; + let lr = l.r; + if (heightGe(ll, lr)) { + return heightUpdateMutate(rotateWithLeftChild(nt)); + } else { + return heightUpdateMutate(doubleWithLeftChild(nt)); + } } - } - if (hr > (2 + hl | 0)) { - let rl = r.l; - let rr = r.r; - if (heightGe(rr, rl)) { - return heightUpdateMutate(rotateWithRightChild(nt)); - } else { - return heightUpdateMutate(doubleWithRightChild(nt)); + + } else if (hr > (2 + hl | 0)) { + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + + } else { + nt.h = Primitive_int.max(hl, hr) + 1 | 0; + return nt; } - nt.h = Primitive_int.max(hl, hr) + 1 | 0; - return nt; } function updateMutate(t, x, data, cmp) { diff --git a/lib/js/Belt_internalMapInt.js b/lib/js/Belt_internalMapInt.js index 2bf62458d1..2c83364bae 100644 --- a/lib/js/Belt_internalMapInt.js +++ b/lib/js/Belt_internalMapInt.js @@ -199,12 +199,15 @@ function merge(s1, s2, f) { } else if (s2 === undefined) { return; } - let v2 = s2.k; - let d2 = s2.v; - let l2 = s2.l; - let r2 = s2.r; - let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + if (s2 !== undefined) { + let v2 = s2.k; + let d2 = s2.v; + let l2 = s2.l; + let r2 = s2.r; + let match$1 = split(v2, s1); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + } + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/js/Belt_internalMapString.js b/lib/js/Belt_internalMapString.js index 6d75fd58be..9ab75cc916 100644 --- a/lib/js/Belt_internalMapString.js +++ b/lib/js/Belt_internalMapString.js @@ -199,12 +199,15 @@ function merge(s1, s2, f) { } else if (s2 === undefined) { return; } - let v2 = s2.k; - let d2 = s2.v; - let l2 = s2.l; - let r2 = s2.r; - let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + if (s2 !== undefined) { + let v2 = s2.k; + let d2 = s2.v; + let l2 = s2.l; + let r2 = s2.r; + let match$1 = split(v2, s1); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); + } + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/js/List.js b/lib/js/List.js index 8e8cd35fbc..51288c4a2b 100644 --- a/lib/js/List.js +++ b/lib/js/List.js @@ -1243,16 +1243,23 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } return [ nextX, - nextY.tl - ]; - } else { - return [ - nextX.tl, - nextY + tmp ]; } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; + } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index a19348538d..c43c23ac44 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -15,6 +15,8 @@ __unsafe_cast: 'a => 'b = "%identity" external raise: exn => 'a = "%raise" +external assert: bool => 'a = "%assert" + @deprecated("Use custom exception instead") let failwith = s => raise(Failure(s)) diff --git a/runtime/Pervasives_mini.res b/runtime/Pervasives_mini.res index 9cf3cd90e4..20efe35a74 100644 --- a/runtime/Pervasives_mini.res +++ b/runtime/Pervasives_mini.res @@ -1,6 +1,6 @@ /* Exceptions */ external raise: exn => 'a = "%raise" - +external assert: bool => 'a = "%assert" /* Debugging */ external __LOC__: string = "%loc_LOC" diff --git a/runtime/rescript.json b/runtime/rescript.json index b39c522cb5..682226eb17 100644 --- a/runtime/rescript.json +++ b/runtime/rescript.json @@ -16,7 +16,7 @@ "-bs-no-check-div-by-zero", "-bs-cross-module-opt", "-unsafe", - "-w -3+50", + "-w -3+50-21", "-warn-error A" ] } diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt index 7d4bc6327e..93f57344c5 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt @@ -3,8 +3,8 @@ [@attr ]) let x = (match z with | _ -> false) z let x = ((match z with | _ -> false)[@attr ]) z -let x = (assert z) z -let x = ((assert z)[@attr ]) z +let x = assert z z +let x = ((assert z z)[@attr ]) let x = (try sideEffect () with | _ -> f ()) z let x = ((try sideEffect () with | _ -> f ())[@attr ]) z let x = for i = 0 to 10 do () done z diff --git a/tests/syntax_tests/data/printer/comments/blockExpr.res b/tests/syntax_tests/data/printer/comments/blockExpr.res index 8f1aca233e..876adbca5d 100644 --- a/tests/syntax_tests/data/printer/comments/blockExpr.res +++ b/tests/syntax_tests/data/printer/comments/blockExpr.res @@ -357,17 +357,17 @@ if { true } // trailing -assert({ - // here - open /* inside */ Matrix - // c - - // c2 - compare(m1, m2) - // after - - // test -}) +// assert({ +// // here +// open /* inside */ Matrix +// // c +// +// // c2 +// compare(m1, m2) +// // after +// +// // test +// }) user.name = { // here diff --git a/tests/syntax_tests/data/printer/comments/expected/blockExpr.res.txt b/tests/syntax_tests/data/printer/comments/expected/blockExpr.res.txt index a2efeccdc3..2e72d4fe64 100644 --- a/tests/syntax_tests/data/printer/comments/expected/blockExpr.res.txt +++ b/tests/syntax_tests/data/printer/comments/expected/blockExpr.res.txt @@ -354,17 +354,17 @@ if { true } // trailing -assert({ - // here - open /* inside */ Matrix - // c - - // c2 - compare(m1, m2) - // after - - // test -}) +// assert({ +// // here +// open /* inside */ Matrix +// // c +// +// // c2 +// compare(m1, m2) +// // after +// +// // test +// }) user.name = { // here diff --git a/tests/syntax_tests/data/printer/expr/assert.res b/tests/syntax_tests/data/printer/expr/assert.res index 471e69f61e..3267bac74d 100644 --- a/tests/syntax_tests/data/printer/expr/assert.res +++ b/tests/syntax_tests/data/printer/expr/assert.res @@ -1,56 +1,56 @@ -assert false - -assert truth - -let x = assert true -let x = assert 12 -let x = assert (12: int) -let x = assert 12 -let x = assert list{1, 2, ...x} -let x = assert module(Foo: Bar) -let x = assert module(Foo) -let x = assert Rgb(1, 2, 3) -let x = assert [a, b, c] -let x = assert {x: 1, y: 3} -let x = assert (1, 2, 3) -let x = assert %extension -let x = assert user.name -let x = assert streets[0] -let x = assert apply(arg1, arg2) -let x = assert apply(. arg1, arg2) -let x = assert -1 -let x = assert !true -let x = assert (x => print(x)) -let x = assert (switch x { +assert(false) + +assert(truth) + +let x = assert(true) +let x = assert(12) +let x = assert((12: int)) +let x = assert(12) +let x = assert(list{1, 2, ...x}) +let x = assert(module(Foo: Bar)) +let x = assert(module(Foo)) +let x = assert(Rgb(1, 2, 3)) +let x = assert([a, b, c]) +let x = assert({x: 1, y: 3}) +let x = assert((1, 2, 3)) +let x = assert(%extension) +let x = assert(user.name) +let x = assert(streets[0]) +let x = assert(apply(arg1, arg2)) +let x = assert(apply(. arg1, arg2)) +let x = assert(-1) +let x = assert(!true) +let x = assert(x => print(x)) +let x = assert(switch x { | Blue => () | Yello => () }) -let x = assert (for i in 0 to 10 { +let x = assert(for i in 0 to 10 { print_int(i) }) -let x = assert (if i < 10 { +let x = assert(if i < 10 { print_int(i) } else { print_int(1000) }) -let x = assert (while i < 10 { +let x = assert(while i < 10 { print_int(i) }) -let x = assert (try sideEffect() catch {| Exit => ()}) +let x = assert(try sideEffect() catch {| Exit => ()}) -let x = assert (@attr expr) +let x = assert(@attr expr) -let x = assert (a + b) +let x = assert(a + b) -let x = @attr assert false +let x = @attr assert(false) -assert invariant["fatal"] -assert invariants[0] +assert(invariant["fatal"]) +assert(invariants[0]) -assert address["street"] = "Brusselsestraat" +assert(address["street"] = "Brusselsestraat") -assert (true ? 0 : 1) +assert(true ? 0 : 1) diff --git a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt index 93d7d60d5c..6fc1dc92da 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt @@ -4,7 +4,7 @@ assert(truth) let x = assert(true) let x = assert(12) -let x = assert(12: int) +let x = assert((12: int)) let x = assert(12) let x = assert(list{1, 2, ...x}) let x = assert(module(Foo: Bar)) @@ -21,28 +21,38 @@ let x = assert(apply(arg1, arg2)) let x = assert(-1) let x = assert(!true) let x = assert(x => print(x)) -let x = assert(switch x { -| Blue => () -| Yello => () -}) - -let x = assert(for i in 0 to 10 { - print_int(i) -}) - -let x = assert(if i < 10 { - print_int(i) -} else { - print_int(1000) -}) - -let x = assert(while i < 10 { - print_int(i) -}) - -let x = assert(try sideEffect() catch { -| Exit => () -}) +let x = assert( + switch x { + | Blue => () + | Yello => () + }, +) + +let x = assert( + for i in 0 to 10 { + print_int(i) + }, +) + +let x = assert( + if i < 10 { + print_int(i) + } else { + print_int(1000) + }, +) + +let x = assert( + while i < 10 { + print_int(i) + }, +) + +let x = assert( + try sideEffect() catch { + | Exit => () + }, +) let x = assert(@attr expr) diff --git a/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt b/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt index 41435587ce..9f50baf406 100644 --- a/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/asyncAwait.res.txt @@ -84,7 +84,7 @@ let _ = await ( sideEffect() } ) -let _ = await (assert(x)) +let _ = await assert(x) let _ = await promises[0] let _ = await promises["resolved"] let _ = await promises["resolved"] = sideEffect() diff --git a/tests/syntax_tests/data/printer/expr/expected/binary.res.txt b/tests/syntax_tests/data/printer/expr/expected/binary.res.txt index e57e20fedb..03d2b1032b 100644 --- a/tests/syntax_tests/data/printer/expr/expected/binary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/binary.res.txt @@ -384,7 +384,7 @@ let x = } let x = a && assert(false) -let x = a && assert(false && assert(true)) +let x = a && assert(false) && assert(true) let x = a && { diff --git a/tests/syntax_tests/data/printer/expr/expected/braced.res.txt b/tests/syntax_tests/data/printer/expr/expected/braced.res.txt index 26c9d855b4..633e050607 100644 --- a/tests/syntax_tests/data/printer/expr/expected/braced.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/braced.res.txt @@ -206,8 +206,8 @@ map((arr, i): coordinate => { x +. (Environment.width /. 2. -. centering.x) }) -let _ = assert(true) -let _ = {assert(true)} +let _ = assert({true}) +let _ = {assert({true})} let _ = {%extension} let _ = {module(ME)} diff --git a/tests/syntax_tests/data/printer/expr/expected/field.res.txt b/tests/syntax_tests/data/printer/expr/expected/field.res.txt index f3e2fed896..218ecac0bc 100644 --- a/tests/syntax_tests/data/printer/expr/expected/field.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/field.res.txt @@ -48,7 +48,7 @@ let x = ( } ).x -let x = (assert(false)).x +let x = assert(false).x let x = ( try sideEffect() catch { | Exit => () diff --git a/tests/syntax_tests/data/printer/expr/expected/unary.res.txt b/tests/syntax_tests/data/printer/expr/expected/unary.res.txt index d1b390b6a2..0f836c4e14 100644 --- a/tests/syntax_tests/data/printer/expr/expected/unary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/unary.res.txt @@ -24,7 +24,7 @@ let x = -a.bar // same as above let x = -a.bar -!(assert(x)) +!assert(x) assert(!x) !(@attr expr) //!(arg => doStuffWith(arg)) diff --git a/tests/tests/rescript.json b/tests/tests/rescript.json index c7dfdd6f05..9659a72b63 100644 --- a/tests/tests/rescript.json +++ b/tests/tests/rescript.json @@ -12,7 +12,7 @@ "suffix": ".mjs" }, "bsc-flags": [ - "-w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104", + "-w -3-6-21-26-27-29-30-32..40-44-45-52-60-9-106+104", "-warn-error A" ] -} \ No newline at end of file +} diff --git a/tests/tests/src/bdd.mjs b/tests/tests/src/bdd.mjs index ea08036d64..3a4df765c0 100644 --- a/tests/tests/src/bdd.mjs +++ b/tests/tests/src/bdd.mjs @@ -385,18 +385,18 @@ function main() { for (let i = 1; i <= 100; ++i) { succeeded = succeeded && test_hwb(bdd, random_vars(22)); } - if (succeeded) { - return; + if (!succeeded) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "bdd.res", + 304, + 2 + ], + Error: new Error() + }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "bdd.res", - 304, - 2 - ], - Error: new Error() - }; + } main(); diff --git a/tests/tests/src/equal_exception_test.mjs b/tests/tests/src/equal_exception_test.mjs index fc7990ef36..eb9bb875c8 100644 --- a/tests/tests/src/equal_exception_test.mjs +++ b/tests/tests/src/equal_exception_test.mjs @@ -7,18 +7,18 @@ import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js" let v = "gso"; function is_equal() { - if (v.codePointAt(0) === /* 'g' */103) { - return; + if (v.codePointAt(0) !== /* 'g' */103) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "equal_exception_test.res", + 6, + 2 + ], + Error: new Error() + }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "equal_exception_test.res", - 6, - 2 - ], - Error: new Error() - }; + } function is_exception() { diff --git a/tests/tests/src/format_regression.mjs b/tests/tests/src/format_regression.mjs index f06f105f26..aa41ce918a 100644 --- a/tests/tests/src/format_regression.mjs +++ b/tests/tests/src/format_regression.mjs @@ -51,14 +51,46 @@ function format_pp_token(param, param$1, param$2) { function advance_loop(state) { while (true) { - let match = peek_queue(state.pp_queue); - let size = match.elem_size; - let size$1 = int_of_size(size); - if (size$1 < 0 && (state.pp_right_total - state.pp_left_total | 0) < state.pp_space_left) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "format_regression.res", + 10, + 22 + ], + Error: new Error() + }; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "format_regression.res", + 11, + 23 + ], + Error: new Error() + }; + if (size < 0 && (state.pp_right_total - state.pp_left_total | 0) < state.pp_space_left) { return; } - take_queue(state.pp_queue); - format_pp_token(state, size$1 < 0 ? 1000000010 : size$1, match.token); + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "format_regression.res", + 12, + 22 + ], + Error: new Error() + }; + size < 0; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "format_regression.res", + 13, + 35 + ], + Error: new Error() + }; state.pp_left_total = match.length + state.pp_left_total | 0; continue; }; diff --git a/tests/tests/src/fun_pattern_match.mjs b/tests/tests/src/fun_pattern_match.mjs index 1a175d381d..8c580f909d 100644 --- a/tests/tests/src/fun_pattern_match.mjs +++ b/tests/tests/src/fun_pattern_match.mjs @@ -14,44 +14,102 @@ function f3(param, param$1) { let lhs = param.rank; let rhs = param$1.rank; if (typeof lhs !== "object") { - lhs === "Uninitialized"; + if (lhs === "Uninitialized") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 33, + 9 + ], + Error: new Error() + }; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 33, + 9 + ], + Error: new Error() + }; } else { if (typeof rhs === "object") { return Primitive_int.compare(lhs._0, rhs._0); } - rhs === "Uninitialized"; + if (rhs === "Uninitialized") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 33, + 9 + ], + Error: new Error() + }; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 33, + 9 + ], + Error: new Error() + }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "fun_pattern_match.res", - 33, - 9 - ], - Error: new Error() - }; } function f4(param, param$1) { let lhs = param.rank; let rhs = param$1.rank; if (typeof lhs !== "object") { - lhs === "Uninitialized"; + if (lhs === "Uninitialized") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 39, + 9 + ], + Error: new Error() + }; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 39, + 9 + ], + Error: new Error() + }; } else { if (typeof rhs === "object") { return Primitive_int.compare(lhs._0, rhs._0); } - rhs === "Uninitialized"; + if (rhs === "Uninitialized") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 39, + 9 + ], + Error: new Error() + }; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "fun_pattern_match.res", + 39, + 9 + ], + Error: new Error() + }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "fun_pattern_match.res", - 39, - 9 - ], - Error: new Error() - }; } let x = { diff --git a/tests/tests/src/gpr_1150.mjs b/tests/tests/src/gpr_1150.mjs index 6485e77f1c..ff9fba5e47 100644 --- a/tests/tests/src/gpr_1150.mjs +++ b/tests/tests/src/gpr_1150.mjs @@ -213,35 +213,35 @@ function f(children) { a14 ]; } - if (children$15.tl) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "gpr_1150.res", - 100, - 62 - ], - Error: new Error() - }; - } - return [ - a0, - a1, - a2, - a3, - a4, - a5, - a6, - a7, - a8, - a9, - a10, - a11, - a12, - a13, - a14, - children$15.hd - ]; + if (!children$15.tl) { + return [ + a0, + a1, + a2, + a3, + a4, + a5, + a6, + a7, + a8, + a9, + a10, + a11, + a12, + a13, + a14, + children$15.hd + ]; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "gpr_1150.res", + 100, + 62 + ], + Error: new Error() + }; } export { diff --git a/tests/tests/src/gpr_858_unit2_test.mjs b/tests/tests/src/gpr_858_unit2_test.mjs index dddf174039..72194b6d05 100644 --- a/tests/tests/src/gpr_858_unit2_test.mjs +++ b/tests/tests/src/gpr_858_unit2_test.mjs @@ -15,18 +15,18 @@ for (let i = 1; i <= 2; ++i) { }; return; } - if (i === n) { - return; + if (i !== n) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "gpr_858_unit2_test.res", + 6, + 13 + ], + Error: new Error() + }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "gpr_858_unit2_test.res", - 6, - 13 - ], - Error: new Error() - }; + }; f(0, i); } diff --git a/tests/tests/src/rbset.mjs b/tests/tests/src/rbset.mjs index 258ef6c4e1..a8d308a818 100644 --- a/tests/tests/src/rbset.mjs +++ b/tests/tests/src/rbset.mjs @@ -205,60 +205,105 @@ function singleton(x) { } function unbalanced_left(x) { - if (typeof x === "object") { - if (x._0 === "Black") { - let match = x._1; - if (typeof match === "object") { - if (match._0 === "Black") { - return [ - balance_left({ - TAG: "Node", - _0: "Red", - _1: match._1, - _2: match._2, - _3: match._3 - }, x._2, x._3), - true - ]; - } - let match$1 = match._3; - if (typeof match$1 === "object" && match$1._0 === "Black") { - return [ - { - TAG: "Node", - _0: "Black", - _1: match._1, - _2: match._2, - _3: balance_left({ - TAG: "Node", - _0: "Red", - _1: match$1._1, - _2: match$1._2, - _3: match$1._3 - }, x._2, x._3) - }, - false - ]; - } - - } - - } else { - let match$2 = x._1; - if (typeof match$2 === "object" && match$2._0 === "Black") { - return [ - balance_left({ + if (typeof x !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 64, + 9 + ], + Error: new Error() + }; + } + if (x._0 === "Black") { + let match = x._1; + if (typeof match !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 64, + 9 + ], + Error: new Error() + }; + } + if (match._0 === "Black") { + return [ + balance_left({ + TAG: "Node", + _0: "Red", + _1: match._1, + _2: match._2, + _3: match._3 + }, x._2, x._3), + true + ]; + } + let match$1 = match._3; + if (typeof match$1 !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 64, + 9 + ], + Error: new Error() + }; + } + if (match$1._0 === "Black") { + return [ + { + TAG: "Node", + _0: "Black", + _1: match._1, + _2: match._2, + _3: balance_left({ TAG: "Node", _0: "Red", - _1: match$2._1, - _2: match$2._2, - _3: match$2._3 - }, x._2, x._3), - false - ]; - } - + _1: match$1._1, + _2: match$1._2, + _3: match$1._3 + }, x._2, x._3) + }, + false + ]; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 64, + 9 + ], + Error: new Error() + }; + } + let match$2 = x._1; + if (typeof match$2 !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 64, + 9 + ], + Error: new Error() + }; + } + if (match$2._0 === "Black") { + return [ + balance_left({ + TAG: "Node", + _0: "Red", + _1: match$2._1, + _2: match$2._2, + _3: match$2._3 + }, x._2, x._3), + false + ]; } throw { RE_EXN_ID: "Assert_failure", @@ -272,62 +317,107 @@ function unbalanced_left(x) { } function unbalanced_right(x) { - if (typeof x === "object") { - if (x._0 === "Black") { - let match = x._3; - let x$1 = x._2; - let a = x._1; - if (typeof match === "object") { - if (match._0 === "Black") { - return [ - balance_right(a, x$1, { - TAG: "Node", - _0: "Red", - _1: match._1, - _2: match._2, - _3: match._3 - }), - true - ]; - } - let match$1 = match._1; - if (typeof match$1 === "object" && match$1._0 === "Black") { - return [ - { - TAG: "Node", - _0: "Black", - _1: balance_right(a, x$1, { - TAG: "Node", - _0: "Red", - _1: match$1._1, - _2: match$1._2, - _3: match$1._3 - }), - _2: match._2, - _3: match._3 - }, - false - ]; - } - - } - - } else { - let match$2 = x._3; - if (typeof match$2 === "object" && match$2._0 === "Black") { - return [ - balance_right(x._1, x._2, { + if (typeof x !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 75, + 9 + ], + Error: new Error() + }; + } + if (x._0 === "Black") { + let match = x._3; + let x$1 = x._2; + let a = x._1; + if (typeof match !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 75, + 9 + ], + Error: new Error() + }; + } + if (match._0 === "Black") { + return [ + balance_right(a, x$1, { + TAG: "Node", + _0: "Red", + _1: match._1, + _2: match._2, + _3: match._3 + }), + true + ]; + } + let match$1 = match._1; + if (typeof match$1 !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 75, + 9 + ], + Error: new Error() + }; + } + if (match$1._0 === "Black") { + return [ + { + TAG: "Node", + _0: "Black", + _1: balance_right(a, x$1, { TAG: "Node", _0: "Red", - _1: match$2._1, - _2: match$2._2, - _3: match$2._3 + _1: match$1._1, + _2: match$1._2, + _3: match$1._3 }), - false - ]; - } - + _2: match._2, + _3: match._3 + }, + false + ]; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 75, + 9 + ], + Error: new Error() + }; + } + let match$2 = x._3; + if (typeof match$2 !== "object") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "rbset.res", + 75, + 9 + ], + Error: new Error() + }; + } + if (match$2._0 === "Black") { + return [ + balance_right(x._1, x._2, { + TAG: "Node", + _0: "Red", + _1: match$2._1, + _2: match$2._2, + _3: match$2._3 + }), + false + ]; } throw { RE_EXN_ID: "Assert_failure", diff --git a/tests/tests/src/stringmatch_test.mjs b/tests/tests/src/stringmatch_test.mjs index a6df5db225..2e517bdfcc 100644 --- a/tests/tests/src/stringmatch_test.mjs +++ b/tests/tests/src/stringmatch_test.mjs @@ -61,22 +61,22 @@ function tst02(s) { Error: new Error() }; } - if (len === 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "stringmatch_test.res", - 35, - 21 - ], - Error: new Error() - }; - } - if (s === "A") { - return 2; - } else { - return 3; + if (len !== 0) { + if (s === "A") { + return 2; + } else { + return 3; + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "stringmatch_test.res", + 35, + 21 + ], + Error: new Error() + }; } if (tst02("") !== 1) { diff --git a/tests/tests/src/topsort_test.mjs b/tests/tests/src/topsort_test.mjs index 2dc512b66a..6575e08eea 100644 --- a/tests/tests/src/topsort_test.mjs +++ b/tests/tests/src/topsort_test.mjs @@ -536,7 +536,6 @@ try { }; } catch (raw_exn) { let exn = Primitive_exceptions.internalToException(raw_exn); - let exit = 0; if (exn.RE_EXN_ID === Cycle) { let match = exn._1; if (match && match.hd === "go") { @@ -548,20 +547,40 @@ try { if (!(match$3 && !(match$3.hd !== "go" || match$3.tl))) { exit = 1; } - } else { - exit = 1; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; } } else { - exit = 1; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; } } else { - exit = 1; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; } } else { - exit = 1; - } - if (exit === 1) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -572,7 +591,6 @@ try { Error: new Error() }; } - } let String_set;