From 48dbcdd3bcacff79a969b6149637d35c758633e5 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Fri, 11 Oct 2024 17:38:15 -0300 Subject: [PATCH 1/8] remove assert --- compiler/syntax/src/res_core.ml | 6 -- compiler/syntax/src/res_grammar.ml | 18 ++--- compiler/syntax/src/res_token.ml | 9 +-- runtime/pervasives.res | 2 + .../expressions/expected/binary.res.txt | 4 +- .../comments/expected/blockExpr.res.txt | 10 +-- .../data/printer/expr/expected/assert.res.txt | 80 +++++-------------- .../printer/expr/expected/asyncAwait.res.txt | 2 +- .../data/printer/expr/expected/binary.res.txt | 2 +- .../data/printer/expr/expected/braced.res.txt | 4 +- .../data/printer/expr/expected/field.res.txt | 2 +- .../data/printer/expr/expected/unary.res.txt | 2 +- 12 files changed, 49 insertions(+), 92 deletions(-) diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index a4779d7b90..1599007835 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 7410b3ba38..19655f3d63 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/runtime/pervasives.res b/runtime/pervasives.res index 603d2d811a..c7558fafc3 100644 --- a/runtime/pervasives.res +++ b/runtime/pervasives.res @@ -15,6 +15,8 @@ module Pervasives = { external raise: exn => 'a = "%raise" + external assert: bool => 'a = "%assert" + @deprecated("Use custom exception instead") let failwith = s => raise(Failure(s)) 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 9f2306aa06..ca647e0fcc 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/expected/blockExpr.res.txt b/tests/syntax_tests/data/printer/comments/expected/blockExpr.res.txt index a2efeccdc3..ac82788b4e 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 +assert(// here +{ open /* inside */ Matrix // c // c2 compare(m1, m2) - // after - - // test }) +// after + +// test user.name = { // here 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..02f4f7889a 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt @@ -1,58 +1,22 @@ -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 { - 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) - -let x = assert(a + b) - -let x = @attr assert(false) - -assert(invariant["fatal"]) -assert(invariants[0]) - -assert(address["street"] = "Brusselsestraat") - -assert(true ? 0 : 1) + + Syntax error! + syntax_tests/data/printer/expr/assert.res:1:7-12 + + 1 │ assert false + 2 │ + 3 │ assert truth + + consecutive statements on a line must be separated by ';' or a newline + + + Syntax error! + syntax_tests/data/printer/expr/assert.res:13:18 + + 11 │ let x = assert module(Foo) + 12 │ let x = assert Rgb(1, 2, 3) + 13 │ let x = assert [a, b, c] + 14 │ let x = assert {x: 1, y: 3} + 15 │ let x = assert (1, 2, 3) + + Did you forget a `]` here? + 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 24dfb51c05..2c03aa41e6 100644 --- a/tests/syntax_tests/data/printer/expr/expected/binary.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/binary.res.txt @@ -383,7 +383,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)) From 429c627798969fa567139dac4dda1a0f330dc46b Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Fri, 11 Oct 2024 23:09:47 -0300 Subject: [PATCH 2/8] update --- compiler/core/lam_analysis.ml | 4 +- compiler/core/lam_compile.ml | 30 +++++++++ compiler/core/lam_compile_primitive.ml | 1 + compiler/core/lam_convert.ml | 1 + compiler/core/lam_primitive.ml | 3 +- compiler/core/lam_primitive.mli | 1 + compiler/core/lam_print.ml | 1 + compiler/ml/lambda.ml | 1 + compiler/ml/lambda.mli | 1 + compiler/ml/printlambda.ml | 1 + compiler/ml/translcore.ml | 1 + .../syntax_tests/data/printer/expr/assert.res | 62 +++++++++---------- .../data/printer/expr/expected/assert.res.txt | 12 ---- 13 files changed, 73 insertions(+), 46 deletions(-) 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 b773eff0ed..4a4047f609 100644 --- a/compiler/core/lam_compile.ml +++ b/compiler/core/lam_compile.ml @@ -1523,6 +1523,36 @@ 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 fname = loc_start.pos_fname in + let line = loc_start.pos_lnum in + let col = loc_start.pos_cnum - loc_start.pos_bol in + + let else_ = + S.throw_stmt + (E.obj + [ + (Lit "RE_EXN_ID", E.str "Assertion_failure"); + ( Lit "_1", + E.array Js_op.Immutable + [ + E.str fname; + E.int (Int32.of_int line); + E.int (Int32.of_int col); + ] ); + (Lit "Error", E.new_ (E.js_global "Error") []); + ]) + in + + Js_output.make + [S.if_ v block ~else_:[else_]] + ~value:E.undefined ~output_finished:False + | {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 efea6c977b..82391c1f51 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/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 4b080b5f14..8d4f00044c 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -232,6 +232,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/tests/syntax_tests/data/printer/expr/assert.res b/tests/syntax_tests/data/printer/expr/assert.res index 471e69f61e..edcd455edd 100644 --- a/tests/syntax_tests/data/printer/expr/assert.res +++ b/tests/syntax_tests/data/printer/expr/assert.res @@ -2,55 +2,55 @@ 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 { +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 02f4f7889a..683958358d 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt @@ -8,15 +8,3 @@ consecutive statements on a line must be separated by ';' or a newline - - Syntax error! - syntax_tests/data/printer/expr/assert.res:13:18 - - 11 │ let x = assert module(Foo) - 12 │ let x = assert Rgb(1, 2, 3) - 13 │ let x = assert [a, b, c] - 14 │ let x = assert {x: 1, y: 3} - 15 │ let x = assert (1, 2, 3) - - Did you forget a `]` here? - From 208c55255cce495f720fffed1b4688cfeac73f62 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Fri, 11 Oct 2024 23:12:03 -0300 Subject: [PATCH 3/8] update test syntax --- .../syntax_tests/data/printer/expr/assert.res | 4 +- .../data/printer/expr/expected/assert.res.txt | 70 +++++++++++++++++-- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/tests/syntax_tests/data/printer/expr/assert.res b/tests/syntax_tests/data/printer/expr/assert.res index edcd455edd..3267bac74d 100644 --- a/tests/syntax_tests/data/printer/expr/assert.res +++ b/tests/syntax_tests/data/printer/expr/assert.res @@ -1,6 +1,6 @@ -assert false +assert(false) -assert truth +assert(truth) let x = assert(true) let x = assert(12) 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 683958358d..6fc1dc92da 100644 --- a/tests/syntax_tests/data/printer/expr/expected/assert.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/assert.res.txt @@ -1,10 +1,68 @@ +assert(false) - Syntax error! - syntax_tests/data/printer/expr/assert.res:1:7-12 +assert(truth) - 1 │ assert false - 2 │ - 3 │ 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 => () + }, +) - consecutive statements on a line must be separated by ';' or a newline +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) + +let x = assert(a + b) + +let x = @attr assert(false) + +assert(invariant["fatal"]) +assert(invariants[0]) + +assert(address["street"] = "Brusselsestraat") + +assert(true ? 0 : 1) From 98934f0a289888c20ad2a22221aaae354f067f64 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Fri, 11 Oct 2024 23:22:51 -0300 Subject: [PATCH 4/8] disable test for assert in blockExpr.res --- .../data/printer/comments/blockExpr.res | 22 +++++++++---------- .../comments/expected/blockExpr.res.txt | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) 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 ac82788b4e..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 From f410680f2688e70615e6647ad2cb1e8eabe02e5a Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 14 Oct 2024 14:08:01 -0300 Subject: [PATCH 5/8] update output --- compiler/core/lam_compile.ml | 31 +-- compiler/ml/predef.mli | 1 + lib/es6/belt_List.js | 37 ++- lib/es6/belt_internalAVLset.js | 216 +++++++++++---- lib/es6/belt_internalAVLtree.js | 202 +++++++++++--- lib/es6/belt_internalMapInt.js | 23 +- lib/es6/belt_internalMapString.js | 23 +- lib/js/belt_List.js | 37 ++- lib/js/belt_internalAVLset.js | 216 +++++++++++---- lib/js/belt_internalAVLtree.js | 202 +++++++++++--- lib/js/belt_internalMapInt.js | 23 +- lib/js/belt_internalMapString.js | 23 +- runtime/rescript.json | 4 +- tests/tests/rescript.json | 4 +- tests/tests/src/bdd.js | 22 +- tests/tests/src/conditional/cond_a_none.js | 4 + tests/tests/src/equal_exception_test.js | 22 +- tests/tests/src/format_regression.js | 44 ++- tests/tests/src/fun_pattern_match.js | 102 +++++-- tests/tests/src/gpr_1150.js | 58 ++-- tests/tests/src/gpr_858_unit2_test.js | 22 +- tests/tests/src/rbset.js | 296 ++++++++++++++------- tests/tests/src/stringmatch_test.js | 30 +-- tests/tests/src/topsort_test.js | 121 +++++++-- 24 files changed, 1287 insertions(+), 476 deletions(-) diff --git a/compiler/core/lam_compile.ml b/compiler/core/lam_compile.ml index 4a4047f609..ce673885ef 100644 --- a/compiler/core/lam_compile.ml +++ b/compiler/core/lam_compile.ml @@ -1529,26 +1529,23 @@ let compile output_prefix = with | {block; value = Some v} -> let loc_start = prim_info.loc.loc_start in - let fname = loc_start.pos_fname in - let line = loc_start.pos_lnum in - let col = loc_start.pos_cnum - loc_start.pos_bol 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 else_ = - S.throw_stmt - (E.obj - [ - (Lit "RE_EXN_ID", E.str "Assertion_failure"); - ( Lit "_1", - E.array Js_op.Immutable - [ - E.str fname; - E.int (Int32.of_int line); - E.int (Int32.of_int col); - ] ); - (Lit "Error", E.new_ (E.js_global "Error") []); - ]) + let block_expr = + Js_exp_make.make_block payload Blk_extension + (E.str "Assert_failure" :: [payload]) + Immutable in + let else_ = S.throw_stmt block_expr in + Js_output.make [S.if_ v block ~else_:[else_]] ~value:E.undefined ~output_finished:False 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/lib/es6/belt_List.js b/lib/es6/belt_List.js index d34068b414..32c5258f93 100644 --- a/lib/es6/belt_List.js +++ b/lib/es6/belt_List.js @@ -1235,16 +1235,43 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_List.res", + 818, + 20 + ], + Error: new Error() + }; + } return [ nextX, - nextY.tl + tmp ]; + } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; } else { - return [ - nextX.tl, - nextY - ]; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_List.res", + 825, + 20 + ], + Error: new Error() + }; } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/lib/es6/belt_internalAVLset.js b/lib/es6/belt_internalAVLset.js index 4357ac887d..7e4ae9c927 100644 --- a/lib/es6/belt_internalAVLset.js +++ b/lib/es6/belt_internalAVLset.js @@ -55,13 +55,34 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 102, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 96, + 14 + ], + Error: new Error() + }; } if (hr <= (hl + 2 | 0)) { return { @@ -73,13 +94,34 @@ function bal(l, v, r) { 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 (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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 115, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 109, + 14 + ], + Error: new Error() + }; } function min0Aux(_n) { @@ -709,48 +751,92 @@ 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 619, + 12 + ], + Error: new Error() + }; } 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 632, + 12 + ], + Error: new Error() + }; } 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); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 649, + 12 + ], + Error: new Error() + }; } 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); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 658, + 12 + ], + Error: new Error() + }; } function heightUpdateMutate(t) { @@ -768,22 +854,44 @@ 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)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 676, + 14 + ], + Error: new Error() + }; } 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)); + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 686, + 14 + ], + Error: new Error() + }; } nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; diff --git a/lib/es6/belt_internalAVLtree.js b/lib/es6/belt_internalAVLtree.js index 3642cb9647..e5c9ffa2a9 100644 --- a/lib/es6/belt_internalAVLtree.js +++ b/lib/es6/belt_internalAVLtree.js @@ -78,13 +78,34 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 97, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 91, + 14 + ], + Error: new Error() + }; } if (hr <= (hl + 2 | 0)) { return { @@ -95,13 +116,34 @@ function bal(l, x, d, r) { 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 (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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 111, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 105, + 14 + ], + Error: new Error() + }; } function minKey0Aux(_n) { @@ -890,40 +932,90 @@ 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 782, + 12 + ], + Error: new Error() + }; } 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 795, + 12 + ], + Error: new Error() + }; } function doubleWithLeftChild(k3) { let x = k3.l; - let v = rotateWithRightChild(x); + let k3l; + if (x !== undefined) { + k3l = x; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 811, + 12 + ], + Error: new Error() + }; + } + 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; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 821, + 12 + ], + Error: new Error() + }; + } + let v = rotateWithLeftChild(k2r); k2.r = v; return rotateWithRightChild(k2); } @@ -941,22 +1033,44 @@ 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)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 840, + 14 + ], + Error: new Error() + }; } 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)); + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 850, + 14 + ], + Error: new Error() + }; } nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; diff --git a/lib/es6/belt_internalMapInt.js b/lib/es6/belt_internalMapInt.js index 5c5560017f..89fc7cbe0b 100644 --- a/lib/es6/belt_internalMapInt.js +++ b/lib/es6/belt_internalMapInt.js @@ -199,12 +199,23 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalMapInt.res", + 187, + 9 + ], + Error: new Error() + }; } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/es6/belt_internalMapString.js b/lib/es6/belt_internalMapString.js index f0d8e9c490..3b2b0529b0 100644 --- a/lib/es6/belt_internalMapString.js +++ b/lib/es6/belt_internalMapString.js @@ -199,12 +199,23 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalMapString.res", + 187, + 9 + ], + Error: new Error() + }; } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/js/belt_List.js b/lib/js/belt_List.js index 5fe5cd5bec..21815b81a4 100644 --- a/lib/js/belt_List.js +++ b/lib/js/belt_List.js @@ -1235,16 +1235,43 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_List.res", + 818, + 20 + ], + Error: new Error() + }; + } return [ nextX, - nextY.tl + tmp ]; + } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; } else { - return [ - nextX.tl, - nextY - ]; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_List.res", + 825, + 20 + ], + Error: new Error() + }; } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/lib/js/belt_internalAVLset.js b/lib/js/belt_internalAVLset.js index c80999536d..208db34b90 100644 --- a/lib/js/belt_internalAVLset.js +++ b/lib/js/belt_internalAVLset.js @@ -55,13 +55,34 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 102, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 96, + 14 + ], + Error: new Error() + }; } if (hr <= (hl + 2 | 0)) { return { @@ -73,13 +94,34 @@ function bal(l, v, r) { 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 (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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 115, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 109, + 14 + ], + Error: new Error() + }; } function min0Aux(_n) { @@ -709,48 +751,92 @@ 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 619, + 12 + ], + Error: new Error() + }; } 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 632, + 12 + ], + Error: new Error() + }; } 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); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 649, + 12 + ], + Error: new Error() + }; } 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); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 658, + 12 + ], + Error: new Error() + }; } function heightUpdateMutate(t) { @@ -768,22 +854,44 @@ 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)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 676, + 14 + ], + Error: new Error() + }; } 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)); + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLset.res", + 686, + 14 + ], + Error: new Error() + }; } nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; diff --git a/lib/js/belt_internalAVLtree.js b/lib/js/belt_internalAVLtree.js index 6bf32cb647..7a3229b0ee 100644 --- a/lib/js/belt_internalAVLtree.js +++ b/lib/js/belt_internalAVLtree.js @@ -78,13 +78,34 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 97, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 91, + 14 + ], + Error: new Error() + }; } if (hr <= (hl + 2 | 0)) { return { @@ -95,13 +116,34 @@ function bal(l, x, d, r) { 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 (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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 111, + 18 + ], + Error: new Error() + }; } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 105, + 14 + ], + Error: new Error() + }; } function minKey0Aux(_n) { @@ -890,40 +932,90 @@ 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 782, + 12 + ], + Error: new Error() + }; } 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; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 795, + 12 + ], + Error: new Error() + }; } function doubleWithLeftChild(k3) { let x = k3.l; - let v = rotateWithRightChild(x); + let k3l; + if (x !== undefined) { + k3l = x; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 811, + 12 + ], + Error: new Error() + }; + } + 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; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 821, + 12 + ], + Error: new Error() + }; + } + let v = rotateWithLeftChild(k2r); k2.r = v; return rotateWithRightChild(k2); } @@ -941,22 +1033,44 @@ 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)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 840, + 14 + ], + Error: new Error() + }; } 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)); + if (r !== undefined) { + let rl = r.l; + let rr = r.r; + if (heightGe(rr, rl)) { + return heightUpdateMutate(rotateWithRightChild(nt)); + } else { + return heightUpdateMutate(doubleWithRightChild(nt)); + } } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalAVLtree.res", + 850, + 14 + ], + Error: new Error() + }; } nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; diff --git a/lib/js/belt_internalMapInt.js b/lib/js/belt_internalMapInt.js index ef18962030..004fd2afd4 100644 --- a/lib/js/belt_internalMapInt.js +++ b/lib/js/belt_internalMapInt.js @@ -199,12 +199,23 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalMapInt.res", + 187, + 9 + ], + Error: new Error() + }; } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/js/belt_internalMapString.js b/lib/js/belt_internalMapString.js index c894e33e3c..fed76bb8e3 100644 --- a/lib/js/belt_internalMapString.js +++ b/lib/js/belt_internalMapString.js @@ -199,12 +199,23 @@ 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)); + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "belt_internalMapString.res", + 187, + 9 + ], + Error: new Error() + }; } function compareAux(_e1, _e2, vcmp) { diff --git a/runtime/rescript.json b/runtime/rescript.json index 2ec055d9db..b8b47bbd27 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" ] -} \ No newline at end of file +} diff --git a/tests/tests/rescript.json b/tests/tests/rescript.json index 69ceca9c90..50fdf9b5b7 100644 --- a/tests/tests/rescript.json +++ b/tests/tests/rescript.json @@ -11,7 +11,7 @@ "in-source": true }, "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.js b/tests/tests/src/bdd.js index 7c4d7df8ac..58e78bed06 100644 --- a/tests/tests/src/bdd.js +++ b/tests/tests/src/bdd.js @@ -396,18 +396,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", + 302, + 2 + ], + Error: new Error() + }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "bdd.res", - 302, - 2 - ], - Error: new Error() - }; + } main(); diff --git a/tests/tests/src/conditional/cond_a_none.js b/tests/tests/src/conditional/cond_a_none.js index 90d2901291..1ba5aef799 100644 --- a/tests/tests/src/conditional/cond_a_none.js +++ b/tests/tests/src/conditional/cond_a_none.js @@ -12,5 +12,9 @@ throw { Error: new Error() }; +let A = { + u: u +}; + exports.A = A; /* u Not a pure module */ diff --git a/tests/tests/src/equal_exception_test.js b/tests/tests/src/equal_exception_test.js index ace01f1143..38f17d539f 100644 --- a/tests/tests/src/equal_exception_test.js +++ b/tests/tests/src/equal_exception_test.js @@ -8,18 +8,18 @@ let Primitive_exceptions = require("rescript/lib/js/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", + 4, + 2 + ], + Error: new Error() + }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "equal_exception_test.res", - 4, - 2 - ], - Error: new Error() - }; + } function is_exception() { diff --git a/tests/tests/src/format_regression.js b/tests/tests/src/format_regression.js index 4f2a36aadf..9f1665cefa 100644 --- a/tests/tests/src/format_regression.js +++ b/tests/tests/src/format_regression.js @@ -52,14 +52,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.js b/tests/tests/src/fun_pattern_match.js index 9585a857ae..8cb7204a6b 100644 --- a/tests/tests/src/fun_pattern_match.js +++ b/tests/tests/src/fun_pattern_match.js @@ -15,44 +15,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.js b/tests/tests/src/gpr_1150.js index b5cc9c15ab..3a318fc34a 100644 --- a/tests/tests/src/gpr_1150.js +++ b/tests/tests/src/gpr_1150.js @@ -214,35 +214,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() + }; } exports.f = f; diff --git a/tests/tests/src/gpr_858_unit2_test.js b/tests/tests/src/gpr_858_unit2_test.js index 4ca3b4244e..6b3b8101e4 100644 --- a/tests/tests/src/gpr_858_unit2_test.js +++ b/tests/tests/src/gpr_858_unit2_test.js @@ -16,18 +16,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.js b/tests/tests/src/rbset.js index ceb920a14c..fd766a2ab8 100644 --- a/tests/tests/src/rbset.js +++ b/tests/tests/src/rbset.js @@ -210,60 +210,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", @@ -277,62 +322,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.js b/tests/tests/src/stringmatch_test.js index f517fd954e..b73b714c63 100644 --- a/tests/tests/src/stringmatch_test.js +++ b/tests/tests/src/stringmatch_test.js @@ -62,22 +62,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.js b/tests/tests/src/topsort_test.js index 2b432aa28a..b3c8234ceb 100644 --- a/tests/tests/src/topsort_test.js +++ b/tests/tests/src/topsort_test.js @@ -537,32 +537,120 @@ 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") { - let match$1 = match.tl; - if (match$1 && match$1.hd === "washup") { - let match$2 = match$1.tl; - if (match$2 && match$2.hd === "eat") { - let match$3 = match$2.tl; - if (!(match$3 && match$3.hd === "go" && !match$3.tl)) { - exit = 1; + if (match) { + if (match.hd === "go") { + let match$1 = match.tl; + if (match$1) { + if (match$1.hd === "washup") { + let match$2 = match$1.tl; + if (match$2) { + if (match$2.hd === "eat") { + let match$3 = match$2.tl; + if (match$3) { + if (match$3.hd === "go") { + if (match$3.tl) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; + } + + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; + } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; + } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; + } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "topsort_test.res", + 154, + 7 + ], + Error: new Error() + }; + } + } else { + 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; + 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: [ @@ -573,7 +661,6 @@ try { Error: new Error() }; } - } let String_set; From 82567901bd9f8d1ef0b48a0187b181d130ec9160 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 20 Oct 2024 16:34:06 -0300 Subject: [PATCH 6/8] add external assert --- lib/es6/Belt_List.js | 4 +- lib/es6/Belt_internalAVLset.js | 20 +- lib/es6/Belt_internalAVLtree.js | 20 +- lib/es6/Belt_internalMapInt.js | 2 +- lib/es6/Belt_internalMapString.js | 2 +- lib/es6/List.js | 37 ++- lib/js/Belt_List.js | 4 +- lib/js/Belt_internalAVLset.js | 20 +- lib/js/Belt_internalAVLtree.js | 20 +- lib/js/Belt_internalMapInt.js | 2 +- lib/js/Belt_internalMapString.js | 2 +- lib/js/List.js | 37 ++- runtime/Pervasives.res | 2 + runtime/Pervasives_mini.res | 2 +- runtime/pervasives.res | 320 ------------------------ tests/tests/src/bdd.js | 12 +- tests/tests/src/equal_exception_test.js | 12 +- 17 files changed, 119 insertions(+), 399 deletions(-) delete mode 100644 runtime/pervasives.res diff --git a/lib/es6/Belt_List.js b/lib/es6/Belt_List.js index 2e9be14525..e2e79e52e2 100644 --- a/lib/es6/Belt_List.js +++ b/lib/es6/Belt_List.js @@ -1242,7 +1242,7 @@ function partition(l, p) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_List.res", + "Belt_List.res", 818, 20 ], @@ -1261,7 +1261,7 @@ function partition(l, p) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_List.res", + "Belt_List.res", 825, 20 ], diff --git a/lib/es6/Belt_internalAVLset.js b/lib/es6/Belt_internalAVLset.js index 177cf53b31..98179c3dcd 100644 --- a/lib/es6/Belt_internalAVLset.js +++ b/lib/es6/Belt_internalAVLset.js @@ -67,7 +67,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 102, 18 ], @@ -77,7 +77,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 96, 14 ], @@ -106,7 +106,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 115, 18 ], @@ -116,7 +116,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 109, 14 ], @@ -768,7 +768,7 @@ function rotateWithLeftChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 619, 12 ], @@ -795,7 +795,7 @@ function rotateWithRightChild(k1) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 632, 12 ], @@ -813,7 +813,7 @@ function doubleWithLeftChild(k3) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 649, 12 ], @@ -831,7 +831,7 @@ function doubleWithRightChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 658, 12 ], @@ -866,7 +866,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 676, 14 ], @@ -886,7 +886,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 686, 14 ], diff --git a/lib/es6/Belt_internalAVLtree.js b/lib/es6/Belt_internalAVLtree.js index 26424245cb..ef19e48f3e 100644 --- a/lib/es6/Belt_internalAVLtree.js +++ b/lib/es6/Belt_internalAVLtree.js @@ -90,7 +90,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 97, 18 ], @@ -100,7 +100,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 91, 14 ], @@ -128,7 +128,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 111, 18 ], @@ -138,7 +138,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 105, 14 ], @@ -946,7 +946,7 @@ function rotateWithLeftChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 782, 12 ], @@ -970,7 +970,7 @@ function rotateWithRightChild(k1) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 795, 12 ], @@ -987,7 +987,7 @@ function doubleWithLeftChild(k3) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 811, 12 ], @@ -1008,7 +1008,7 @@ function doubleWithRightChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 821, 12 ], @@ -1045,7 +1045,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 840, 14 ], @@ -1065,7 +1065,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 850, 14 ], diff --git a/lib/es6/Belt_internalMapInt.js b/lib/es6/Belt_internalMapInt.js index 879bce6fa1..f73875b665 100644 --- a/lib/es6/Belt_internalMapInt.js +++ b/lib/es6/Belt_internalMapInt.js @@ -210,7 +210,7 @@ function merge(s1, s2, f) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalMapInt.res", + "Belt_internalMapInt.res", 187, 9 ], diff --git a/lib/es6/Belt_internalMapString.js b/lib/es6/Belt_internalMapString.js index dcaeacd7d8..98e18970bf 100644 --- a/lib/es6/Belt_internalMapString.js +++ b/lib/es6/Belt_internalMapString.js @@ -210,7 +210,7 @@ function merge(s1, s2, f) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalMapString.res", + "Belt_internalMapString.res", 187, 9 ], diff --git a/lib/es6/List.js b/lib/es6/List.js index 89b2209010..1df9faab94 100644 --- a/lib/es6/List.js +++ b/lib/es6/List.js @@ -1247,16 +1247,43 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "List.res", + 834, + 20 + ], + Error: new Error() + }; + } return [ nextX, - nextY.tl + tmp ]; + } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; } else { - return [ - nextX.tl, - nextY - ]; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "List.res", + 841, + 20 + ], + Error: new Error() + }; } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/lib/js/Belt_List.js b/lib/js/Belt_List.js index 9474d81efb..8f88d915c5 100644 --- a/lib/js/Belt_List.js +++ b/lib/js/Belt_List.js @@ -1242,7 +1242,7 @@ function partition(l, p) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_List.res", + "Belt_List.res", 818, 20 ], @@ -1261,7 +1261,7 @@ function partition(l, p) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_List.res", + "Belt_List.res", 825, 20 ], diff --git a/lib/js/Belt_internalAVLset.js b/lib/js/Belt_internalAVLset.js index 76b22230f3..808a58600c 100644 --- a/lib/js/Belt_internalAVLset.js +++ b/lib/js/Belt_internalAVLset.js @@ -67,7 +67,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 102, 18 ], @@ -77,7 +77,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 96, 14 ], @@ -106,7 +106,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 115, 18 ], @@ -116,7 +116,7 @@ function bal(l, v, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 109, 14 ], @@ -768,7 +768,7 @@ function rotateWithLeftChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 619, 12 ], @@ -795,7 +795,7 @@ function rotateWithRightChild(k1) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 632, 12 ], @@ -813,7 +813,7 @@ function doubleWithLeftChild(k3) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 649, 12 ], @@ -831,7 +831,7 @@ function doubleWithRightChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 658, 12 ], @@ -866,7 +866,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 676, 14 ], @@ -886,7 +886,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLset.res", + "Belt_internalAVLset.res", 686, 14 ], diff --git a/lib/js/Belt_internalAVLtree.js b/lib/js/Belt_internalAVLtree.js index b6478b5e06..3edc9bb48d 100644 --- a/lib/js/Belt_internalAVLtree.js +++ b/lib/js/Belt_internalAVLtree.js @@ -90,7 +90,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 97, 18 ], @@ -100,7 +100,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 91, 14 ], @@ -128,7 +128,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 111, 18 ], @@ -138,7 +138,7 @@ function bal(l, x, d, r) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 105, 14 ], @@ -946,7 +946,7 @@ function rotateWithLeftChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 782, 12 ], @@ -970,7 +970,7 @@ function rotateWithRightChild(k1) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 795, 12 ], @@ -987,7 +987,7 @@ function doubleWithLeftChild(k3) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 811, 12 ], @@ -1008,7 +1008,7 @@ function doubleWithRightChild(k2) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 821, 12 ], @@ -1045,7 +1045,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 840, 14 ], @@ -1065,7 +1065,7 @@ function balMutate(nt) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalAVLtree.res", + "Belt_internalAVLtree.res", 850, 14 ], diff --git a/lib/js/Belt_internalMapInt.js b/lib/js/Belt_internalMapInt.js index 059686ecab..86259bb212 100644 --- a/lib/js/Belt_internalMapInt.js +++ b/lib/js/Belt_internalMapInt.js @@ -210,7 +210,7 @@ function merge(s1, s2, f) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalMapInt.res", + "Belt_internalMapInt.res", 187, 9 ], diff --git a/lib/js/Belt_internalMapString.js b/lib/js/Belt_internalMapString.js index dc26f428a6..7e4e77c94d 100644 --- a/lib/js/Belt_internalMapString.js +++ b/lib/js/Belt_internalMapString.js @@ -210,7 +210,7 @@ function merge(s1, s2, f) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "belt_internalMapString.res", + "Belt_internalMapString.res", 187, 9 ], diff --git a/lib/js/List.js b/lib/js/List.js index 129fb6f5cf..440b6064a8 100644 --- a/lib/js/List.js +++ b/lib/js/List.js @@ -1247,16 +1247,43 @@ function partition(l, p) { let b = p(h); partitionAux(p, l.tl, nextX, nextY); if (b) { + let tmp; + if (nextY) { + tmp = nextY.tl; + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "List.res", + 834, + 20 + ], + Error: new Error() + }; + } return [ nextX, - nextY.tl + tmp ]; + } + let tmp$1; + if (nextX) { + tmp$1 = nextX.tl; } else { - return [ - nextX.tl, - nextY - ]; + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "List.res", + 841, + 20 + ], + Error: new Error() + }; } + return [ + tmp$1, + nextY + ]; } function unzip(xs) { diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index d8873a1f13..e9af3da4fe 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 9c62e80ffe..dfdc30214e 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/pervasives.res b/runtime/pervasives.res deleted file mode 100644 index c7558fafc3..0000000000 --- a/runtime/pervasives.res +++ /dev/null @@ -1,320 +0,0 @@ -/** - Since [others] depend on this file, its public mli files **should not - export types** introduced here, otherwise it would cause - conflicts here. - - If the type exported here is also exported in modules from others, - you will get a type not equivalent. -*/ -module Pervasives = { - /* Internal */ - @deprecated("Do not use. This will be removed in v13") - external __unsafe_cast: 'a => 'b = "%identity" - - /* Exceptions */ - - external raise: exn => 'a = "%raise" - - external assert: bool => 'a = "%assert" - - @deprecated("Use custom exception instead") - let failwith = s => raise(Failure(s)) - - @deprecated("Use custom exception instead") - let invalid_arg = s => raise(Invalid_argument(s)) - - @deprecated("Use custom exception instead") exception Exit - - /* Composition operators */ - - external \"|>": ('a, 'a => 'b) => 'b = "%revapply" - external \"@@": ('a => 'b, 'a) => 'b = "%apply" - - /* Debugging */ - - external __LOC__: string = "%loc_LOC" - external __FILE__: string = "%loc_FILE" - external __LINE__: int = "%loc_LINE" - external __MODULE__: string = "%loc_MODULE" - external __POS__: (string, int, int, int) = "%loc_POS" - - external __LOC_OF__: 'a => (string, 'a) = "%loc_LOC" - external __LINE_OF__: 'a => (int, 'a) = "%loc_LINE" - external __POS_OF__: 'a => ((string, int, int, int), 'a) = "%loc_POS" - - /* Comparisons */ - - external \"=": ('a, 'a) => bool = "%equal" - external \"<>": ('a, 'a) => bool = "%notequal" - external \"<": ('a, 'a) => bool = "%lessthan" - external \">": ('a, 'a) => bool = "%greaterthan" - external \"<=": ('a, 'a) => bool = "%lessequal" - external \">=": ('a, 'a) => bool = "%greaterequal" - external compare: ('a, 'a) => int = "%compare" - external min: ('a, 'a) => 'a = "%min" - external max: ('a, 'a) => 'a = "%max" - external \"==": ('a, 'a) => bool = "%eq" - external \"!=": ('a, 'a) => bool = "%noteq" - - /* Boolean operations */ - - external not: bool => bool = "%boolnot" - - external \"&&": (bool, bool) => bool = "%sequand" - - external \"||": (bool, bool) => bool = "%sequor" - - /* Integer operations */ - - external \"~-": int => int = "%negint" - external \"~+": int => int = "%identity" - external succ: int => int = "%succint" - external pred: int => int = "%predint" - external \"+": (int, int) => int = "%addint" - external \"-": (int, int) => int = "%subint" - external \"*": (int, int) => int = "%mulint" - external \"/": (int, int) => int = "%divint" - external mod: (int, int) => int = "%modint" - - @deprecated("Use Core instead. This will be removed in v13") - let abs = x => - if x >= 0 { - x - } else { - -x - } - - external land: (int, int) => int = "%andint" - external lor: (int, int) => int = "%orint" - external lxor: (int, int) => int = "%xorint" - - let lnot = x => lxor(x, -1) - - external lsl: (int, int) => int = "%lslint" - external lsr: (int, int) => int = "%lsrint" - external asr: (int, int) => int = "%asrint" - - @deprecated("Use Core instead. This will be removed in v13") - let max_int = lsr(-1, 1) - - @deprecated("Use Core instead. This will be removed in v13") - let min_int = - max_int + 1 - - /* Floating-point operations */ - - external \"~-.": float => float = "%negfloat" - external \"~+.": float => float = "%identity" - external \"+.": (float, float) => float = "%addfloat" - external \"-.": (float, float) => float = "%subfloat" - external \"*.": (float, float) => float = "%mulfloat" - external \"/.": (float, float) => float = "%divfloat" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external \"**": (float, float) => float = "pow" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external exp: float => float = "exp" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external acos: float => float = "acos" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external asin: float => float = "asin" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external atan: float => float = "atan" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external atan2: (float, float) => float = "atan2" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external cos: float => float = "cos" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external cosh: float => float = "cosh" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external log: float => float = "log" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external log10: float => float = "log10" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external log1p: float => float = "log1p" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external sin: float => float = "sin" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external sinh: float => float = "sinh" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external sqrt: float => float = "sqrt" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external tan: float => float = "tan" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external tanh: float => float = "tanh" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external ceil: float => float = "ceil" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external floor: float => float = "floor" - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") - external abs_float: float => float = "abs" - - @deprecated("Use Core instead. This will be removed in v13") - external mod_float: float => float = "%modfloat" - - @deprecated("Use Core instead. This will be removed in v13") - external float: int => float = "%floatofint" - - @deprecated("Use Core instead. This will be removed in v13") - external float_of_int: int => float = "%floatofint" - - @deprecated("Use Core instead. This will be removed in v13") - external truncate: float => int = "%intoffloat" - - @deprecated("Use Core instead. This will be removed in v13") - external int_of_float: float => int = "%intoffloat" - - @deprecated("Use Core instead. This will be removed in v13") - let infinity = 0x1p2047 - - @deprecated("Use Core instead. This will be removed in v13") - let neg_infinity = -0x1p2047 - - @deprecated("Use Core instead. This will be removed in v13") @val @scope("Number") - external nan: float = "NaN" - - @deprecated("Use Core instead. This will be removed in v13") - let max_float = 1.79769313486231571e+308 /* 0x1.ffff_ffff_ffff_fp+1023 */ - - @deprecated("Use Core instead. This will be removed in v13") - let min_float = 2.22507385850720138e-308 /* 0x1p-1022 */ - - @deprecated("Use Core instead. This will be removed in v13") - let epsilon_float = 2.22044604925031308e-16 /* 0x1p-52 */ - - @deprecated("Do not use. This will be removed in v13") - type fpclass = - | FP_normal - | FP_subnormal - | FP_zero - | FP_infinite - | FP_nan - - @deprecated("Do not use. This will be removed in v13") - let classify_float = (x: float): fpclass => - if (%raw(`isFinite`): _ => _)(x) { - if abs_float(x) >= /* 0x1p-1022 */ /* 2.22507385850720138e-308 */ min_float { - FP_normal - } else if x != 0. { - FP_subnormal - } else { - FP_zero - } - } else if (%raw(`isNaN`): _ => _)(x) { - FP_nan - } else { - FP_infinite - } - - /* String and byte sequence operations -- more in modules String and Bytes */ - - external \"^": (string, string) => string = "%string_concat" - - /* Character operations -- more in module Char */ - - @deprecated("Use Core instead. This will be removed in v13") - external int_of_char: char => int = "%identity" - - @deprecated("Use Core instead. This will be removed in v13") - external unsafe_char_of_int: int => char = "%identity" - - @deprecated("Use Core instead. This will be removed in v13") - let char_of_int = n => - if n < 0 || n > 255 { - invalid_arg("char_of_int") - } else { - unsafe_char_of_int(n) - } - - /* Unit operations */ - - external ignore: 'a => unit = "%ignore" - - /* Pair operations */ - - external fst: (('a, 'b)) => 'a = "%field0" - external snd: (('a, 'b)) => 'b = "%field1" - - /* References */ - - type ref<'a> = {mutable contents: 'a} - external ref: 'a => ref<'a> = "%makeref" - external \"!": ref<'a> => 'a = "%refget" - external \":=": (ref<'a>, 'a) => unit = "%refset" - external incr: ref => unit = "%incr" - external decr: ref => unit = "%decr" - - /* String conversion functions */ - - @deprecated("Use Core instead. This will be removed in v13") - let string_of_bool = b => - if b { - "true" - } else { - "false" - } - - @deprecated("Use Core instead. This will be removed in v13") - let bool_of_string = param => - switch param { - | "true" => true - | "false" => false - | _ => invalid_arg("bool_of_string") - } - - @deprecated("Use Core instead. This will be removed in v13") - let bool_of_string_opt = param => - switch param { - | "true" => Some(true) - | "false" => Some(false) - | _ => None - } - - @deprecated("Use Core instead. This will be removed in v13") - external string_of_int: int => string = "String" - - @deprecated("Use Core instead. This will be removed in v13") @scope("Number") - external int_of_string: string => int = "parseInt" - - let int_of_string_opt = s => - switch int_of_string(s) { - | n if n == %raw("NaN") => None - | n => Some(n) - } - - @deprecated("Use Core instead. This will be removed in v13") - external string_get: (string, int) => char = "%string_safe_get" - - /* List operations -- more in module List */ - - @deprecated("Use Core instead. This will be removed in v13") - let rec \"@" = (l1, l2) => - switch l1 { - | list{} => l2 - | list{hd, ...tl} => list{hd, ...\"@"(tl, l2)} - } - - /* Miscellaneous */ - - type int32 = int -} - -include Pervasives diff --git a/tests/tests/src/bdd.js b/tests/tests/src/bdd.js index 2a4850f0d6..0a5d860241 100644 --- a/tests/tests/src/bdd.js +++ b/tests/tests/src/bdd.js @@ -401,21 +401,13 @@ function main() { RE_EXN_ID: "Assert_failure", _1: [ "bdd.res", - 302, + 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.js b/tests/tests/src/equal_exception_test.js index 8aed32b0e1..f5871dbde7 100644 --- a/tests/tests/src/equal_exception_test.js +++ b/tests/tests/src/equal_exception_test.js @@ -13,21 +13,13 @@ function is_equal() { RE_EXN_ID: "Assert_failure", _1: [ "equal_exception_test.res", - 4, + 6, 2 ], Error: new Error() }; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "equal_exception_test.res", - 6, - 2 - ], - Error: new Error() - }; + } function is_exception() { From b48831281846595bbc8ae650d9f3747fc4b840c2 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Thu, 24 Oct 2024 15:49:24 -0300 Subject: [PATCH 7/8] update output --- compiler/core/lam_compile.ml | 12 ++- lib/es6/Belt_List.js | 20 ---- lib/es6/Belt_internalAVLset.js | 158 +++++++----------------------- lib/es6/Belt_internalAVLtree.js | 156 ++++++----------------------- lib/es6/Belt_internalMapInt.js | 10 +- lib/es6/Belt_internalMapString.js | 10 +- lib/es6/List.js | 20 ---- lib/js/Belt_List.js | 20 ---- lib/js/Belt_internalAVLset.js | 158 +++++++----------------------- lib/js/Belt_internalAVLtree.js | 156 ++++++----------------------- lib/js/Belt_internalMapInt.js | 10 +- lib/js/Belt_internalMapString.js | 10 +- lib/js/List.js | 20 ---- 13 files changed, 143 insertions(+), 617 deletions(-) diff --git a/compiler/core/lam_compile.ml b/compiler/core/lam_compile.ml index ce673885ef..11a0a783ec 100644 --- a/compiler/core/lam_compile.ml +++ b/compiler/core/lam_compile.ml @@ -1546,9 +1546,15 @@ let compile output_prefix = let else_ = S.throw_stmt block_expr in - Js_output.make - [S.if_ v block ~else_:[else_]] - ~value:E.undefined ~output_finished:False + 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 + _a | {value = None} -> assert false) | {primitive = Praise; args = [e]; _} -> ( match diff --git a/lib/es6/Belt_List.js b/lib/es6/Belt_List.js index e2e79e52e2..8a05c44dfd 100644 --- a/lib/es6/Belt_List.js +++ b/lib/es6/Belt_List.js @@ -1238,16 +1238,6 @@ function partition(l, p) { let tmp; if (nextY) { tmp = nextY.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_List.res", - 818, - 20 - ], - Error: new Error() - }; } return [ nextX, @@ -1257,16 +1247,6 @@ function partition(l, p) { let tmp$1; if (nextX) { tmp$1 = nextX.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_List.res", - 825, - 20 - ], - Error: new Error() - }; } return [ tmp$1, diff --git a/lib/es6/Belt_internalAVLset.js b/lib/es6/Belt_internalAVLset.js index 98179c3dcd..a6db542991 100644 --- a/lib/es6/Belt_internalAVLset.js +++ b/lib/es6/Belt_internalAVLset.js @@ -64,64 +64,33 @@ function bal(l, v, r) { if (lr !== undefined) { return create(create(ll, l.v, lr.l), lr.v, create(lr.r, v, r)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 102, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 96, - 14 - ], - Error: new Error() - }; - } - 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); + + } else { + if (hr <= (hl + 2 | 0)) { + return { + v: v, + h: ( + hl >= hr ? hl : hr + ) + 1 | 0, + l: l, + r: r + }; } - if (rl !== undefined) { - return create(create(l, v, rl.l), rl.v, create(rl.r, r.v, rr)); + 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)); + } + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 115, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 109, - 14 - ], - Error: new Error() - }; } function min0Aux(_n) { @@ -386,22 +355,11 @@ function checkInvariantInternal(_v) { } let l = v.l; let r = v.r; - let diff = ( + ( l !== undefined ? l.h : 0 ) - ( 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; continue; @@ -765,15 +723,7 @@ function rotateWithLeftChild(k2) { k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 619, - 12 - ], - Error: new Error() - }; + } function rotateWithRightChild(k1) { @@ -792,15 +742,7 @@ function rotateWithRightChild(k1) { k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 632, - 12 - ], - Error: new Error() - }; + } function doubleWithLeftChild(k3) { @@ -810,15 +752,7 @@ function doubleWithLeftChild(k3) { k3.l = v; return rotateWithLeftChild(k3); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 649, - 12 - ], - Error: new Error() - }; + } function doubleWithRightChild(k2) { @@ -828,15 +762,7 @@ function doubleWithRightChild(k2) { k2.r = v; return rotateWithRightChild(k2); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 658, - 12 - ], - Error: new Error() - }; + } function heightUpdateMutate(t) { @@ -863,17 +789,8 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithLeftChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 676, - 14 - ], - Error: new Error() - }; - } - if (hr > (2 + hl | 0)) { + + } else if (hr > (2 + hl | 0)) { if (r !== undefined) { let rl = r.l; let rr = r.r; @@ -883,18 +800,11 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 686, - 14 - ], - Error: new Error() - }; + + } 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 ef19e48f3e..2ed00c962b 100644 --- a/lib/es6/Belt_internalAVLtree.js +++ b/lib/es6/Belt_internalAVLtree.js @@ -87,63 +87,32 @@ function bal(l, 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)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 97, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 91, - 14 - ], - Error: new Error() - }; - } - 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); + + } else { + if (hr <= (hl + 2 | 0)) { + return { + k: x, + v: d, + h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0, + l: l, + r: r + }; } - if (rl !== undefined) { - return create(create(l, x, d, rl.l), rl.k, rl.v, create(rl.r, r.k, r.v, rr)); + 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)); + } + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 111, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 105, - 14 - ], - Error: new Error() - }; } function minKey0Aux(_n) { @@ -587,18 +556,7 @@ function checkInvariantInternal(_v) { } let l = v.l; 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() - }; - } + treeHeight(l) - treeHeight(r) | 0; checkInvariantInternal(l); _v = r; continue; @@ -943,15 +901,7 @@ function rotateWithLeftChild(k2) { k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 782, - 12 - ], - Error: new Error() - }; + } function rotateWithRightChild(k1) { @@ -967,15 +917,7 @@ function rotateWithRightChild(k1) { k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 795, - 12 - ], - Error: new Error() - }; + } function doubleWithLeftChild(k3) { @@ -983,16 +925,6 @@ function doubleWithLeftChild(k3) { let k3l; if (x !== undefined) { k3l = x; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 811, - 12 - ], - Error: new Error() - }; } let v = rotateWithRightChild(k3l); k3.l = v; @@ -1004,16 +936,6 @@ function doubleWithRightChild(k2) { let k2r; if (x !== undefined) { k2r = x; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 821, - 12 - ], - Error: new Error() - }; } let v = rotateWithLeftChild(k2r); k2.r = v; @@ -1042,17 +964,8 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithLeftChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 840, - 14 - ], - Error: new Error() - }; - } - if (hr > (2 + hl | 0)) { + + } else if (hr > (2 + hl | 0)) { if (r !== undefined) { let rl = r.l; let rr = r.r; @@ -1062,18 +975,11 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 850, - 14 - ], - Error: new Error() - }; + + } 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 f73875b665..8561e3f3c4 100644 --- a/lib/es6/Belt_internalMapInt.js +++ b/lib/es6/Belt_internalMapInt.js @@ -207,15 +207,7 @@ function merge(s1, s2, f) { 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)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalMapInt.res", - 187, - 9 - ], - Error: new Error() - }; + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/es6/Belt_internalMapString.js b/lib/es6/Belt_internalMapString.js index 98e18970bf..3918ef0719 100644 --- a/lib/es6/Belt_internalMapString.js +++ b/lib/es6/Belt_internalMapString.js @@ -207,15 +207,7 @@ function merge(s1, s2, f) { 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)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalMapString.res", - 187, - 9 - ], - Error: new Error() - }; + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/es6/List.js b/lib/es6/List.js index 1df9faab94..b2e516ef7b 100644 --- a/lib/es6/List.js +++ b/lib/es6/List.js @@ -1250,16 +1250,6 @@ function partition(l, p) { let tmp; if (nextY) { tmp = nextY.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "List.res", - 834, - 20 - ], - Error: new Error() - }; } return [ nextX, @@ -1269,16 +1259,6 @@ function partition(l, p) { let tmp$1; if (nextX) { tmp$1 = nextX.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "List.res", - 841, - 20 - ], - Error: new Error() - }; } return [ tmp$1, diff --git a/lib/js/Belt_List.js b/lib/js/Belt_List.js index 8f88d915c5..1bf0ece57c 100644 --- a/lib/js/Belt_List.js +++ b/lib/js/Belt_List.js @@ -1238,16 +1238,6 @@ function partition(l, p) { let tmp; if (nextY) { tmp = nextY.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_List.res", - 818, - 20 - ], - Error: new Error() - }; } return [ nextX, @@ -1257,16 +1247,6 @@ function partition(l, p) { let tmp$1; if (nextX) { tmp$1 = nextX.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_List.res", - 825, - 20 - ], - Error: new Error() - }; } return [ tmp$1, diff --git a/lib/js/Belt_internalAVLset.js b/lib/js/Belt_internalAVLset.js index 808a58600c..303978ce6a 100644 --- a/lib/js/Belt_internalAVLset.js +++ b/lib/js/Belt_internalAVLset.js @@ -64,64 +64,33 @@ function bal(l, v, r) { if (lr !== undefined) { return create(create(ll, l.v, lr.l), lr.v, create(lr.r, v, r)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 102, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 96, - 14 - ], - Error: new Error() - }; - } - 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); + + } else { + if (hr <= (hl + 2 | 0)) { + return { + v: v, + h: ( + hl >= hr ? hl : hr + ) + 1 | 0, + l: l, + r: r + }; } - if (rl !== undefined) { - return create(create(l, v, rl.l), rl.v, create(rl.r, r.v, rr)); + 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)); + } + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 115, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 109, - 14 - ], - Error: new Error() - }; } function min0Aux(_n) { @@ -386,22 +355,11 @@ function checkInvariantInternal(_v) { } let l = v.l; let r = v.r; - let diff = ( + ( l !== undefined ? l.h : 0 ) - ( 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; continue; @@ -765,15 +723,7 @@ function rotateWithLeftChild(k2) { k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 619, - 12 - ], - Error: new Error() - }; + } function rotateWithRightChild(k1) { @@ -792,15 +742,7 @@ function rotateWithRightChild(k1) { k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 632, - 12 - ], - Error: new Error() - }; + } function doubleWithLeftChild(k3) { @@ -810,15 +752,7 @@ function doubleWithLeftChild(k3) { k3.l = v; return rotateWithLeftChild(k3); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 649, - 12 - ], - Error: new Error() - }; + } function doubleWithRightChild(k2) { @@ -828,15 +762,7 @@ function doubleWithRightChild(k2) { k2.r = v; return rotateWithRightChild(k2); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 658, - 12 - ], - Error: new Error() - }; + } function heightUpdateMutate(t) { @@ -863,17 +789,8 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithLeftChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 676, - 14 - ], - Error: new Error() - }; - } - if (hr > (2 + hl | 0)) { + + } else if (hr > (2 + hl | 0)) { if (r !== undefined) { let rl = r.l; let rr = r.r; @@ -883,18 +800,11 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLset.res", - 686, - 14 - ], - Error: new Error() - }; + + } 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 3edc9bb48d..db4b15b247 100644 --- a/lib/js/Belt_internalAVLtree.js +++ b/lib/js/Belt_internalAVLtree.js @@ -87,63 +87,32 @@ function bal(l, 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)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 97, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 91, - 14 - ], - Error: new Error() - }; - } - 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); + + } else { + if (hr <= (hl + 2 | 0)) { + return { + k: x, + v: d, + h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0, + l: l, + r: r + }; } - if (rl !== undefined) { - return create(create(l, x, d, rl.l), rl.k, rl.v, create(rl.r, r.k, r.v, rr)); + 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)); + } + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 111, - 18 - ], - Error: new Error() - }; + } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 105, - 14 - ], - Error: new Error() - }; } function minKey0Aux(_n) { @@ -587,18 +556,7 @@ function checkInvariantInternal(_v) { } let l = v.l; 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() - }; - } + treeHeight(l) - treeHeight(r) | 0; checkInvariantInternal(l); _v = r; continue; @@ -943,15 +901,7 @@ function rotateWithLeftChild(k2) { k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 782, - 12 - ], - Error: new Error() - }; + } function rotateWithRightChild(k1) { @@ -967,15 +917,7 @@ function rotateWithRightChild(k1) { k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 795, - 12 - ], - Error: new Error() - }; + } function doubleWithLeftChild(k3) { @@ -983,16 +925,6 @@ function doubleWithLeftChild(k3) { let k3l; if (x !== undefined) { k3l = x; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 811, - 12 - ], - Error: new Error() - }; } let v = rotateWithRightChild(k3l); k3.l = v; @@ -1004,16 +936,6 @@ function doubleWithRightChild(k2) { let k2r; if (x !== undefined) { k2r = x; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 821, - 12 - ], - Error: new Error() - }; } let v = rotateWithLeftChild(k2r); k2.r = v; @@ -1042,17 +964,8 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithLeftChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 840, - 14 - ], - Error: new Error() - }; - } - if (hr > (2 + hl | 0)) { + + } else if (hr > (2 + hl | 0)) { if (r !== undefined) { let rl = r.l; let rr = r.r; @@ -1062,18 +975,11 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalAVLtree.res", - 850, - 14 - ], - Error: new Error() - }; + + } 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 86259bb212..2c83364bae 100644 --- a/lib/js/Belt_internalMapInt.js +++ b/lib/js/Belt_internalMapInt.js @@ -207,15 +207,7 @@ function merge(s1, s2, f) { 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)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalMapInt.res", - 187, - 9 - ], - Error: new Error() - }; + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/js/Belt_internalMapString.js b/lib/js/Belt_internalMapString.js index 7e4e77c94d..9ab75cc916 100644 --- a/lib/js/Belt_internalMapString.js +++ b/lib/js/Belt_internalMapString.js @@ -207,15 +207,7 @@ function merge(s1, s2, f) { 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)); } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Belt_internalMapString.res", - 187, - 9 - ], - Error: new Error() - }; + } function compareAux(_e1, _e2, vcmp) { diff --git a/lib/js/List.js b/lib/js/List.js index 440b6064a8..a9f03b538e 100644 --- a/lib/js/List.js +++ b/lib/js/List.js @@ -1250,16 +1250,6 @@ function partition(l, p) { let tmp; if (nextY) { tmp = nextY.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "List.res", - 834, - 20 - ], - Error: new Error() - }; } return [ nextX, @@ -1269,16 +1259,6 @@ function partition(l, p) { let tmp$1; if (nextX) { tmp$1 = nextX.tl; - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "List.res", - 841, - 20 - ], - Error: new Error() - }; } return [ tmp$1, From 1862b7f8f0c68585b84629ab1ec21000522b9dd9 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 17 Nov 2024 15:59:26 -0300 Subject: [PATCH 8/8] update output --- compiler/core/lam_compile.ml | 13 ++++++++----- lib/es6/Belt_internalAVLset.js | 5 ++++- lib/es6/Belt_internalAVLtree.js | 5 ++++- lib/js/Belt_internalAVLset.js | 5 ++++- lib/js/Belt_internalAVLtree.js | 5 ++++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/compiler/core/lam_compile.ml b/compiler/core/lam_compile.ml index c3a050e2f9..d2621928cc 100644 --- a/compiler/core/lam_compile.ml +++ b/compiler/core/lam_compile.ml @@ -1564,17 +1564,20 @@ let compile output_prefix = Immutable in - let else_ = S.throw_stmt block_expr 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 - _a + (* 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 diff --git a/lib/es6/Belt_internalAVLset.js b/lib/es6/Belt_internalAVLset.js index a6db542991..da87b79253 100644 --- a/lib/es6/Belt_internalAVLset.js +++ b/lib/es6/Belt_internalAVLset.js @@ -355,11 +355,14 @@ function checkInvariantInternal(_v) { } let l = v.l; let r = v.r; - ( + let diff = ( l !== undefined ? l.h : 0 ) - ( r !== undefined ? r.h : 0 ) | 0; + if (!(diff <= 2 && diff >= -2)) { + + } checkInvariantInternal(l); _v = r; continue; diff --git a/lib/es6/Belt_internalAVLtree.js b/lib/es6/Belt_internalAVLtree.js index 2ed00c962b..555df157d6 100644 --- a/lib/es6/Belt_internalAVLtree.js +++ b/lib/es6/Belt_internalAVLtree.js @@ -556,7 +556,10 @@ function checkInvariantInternal(_v) { } let l = v.l; let r = v.r; - treeHeight(l) - treeHeight(r) | 0; + let diff = treeHeight(l) - treeHeight(r) | 0; + if (!(diff <= 2 && diff >= -2)) { + + } checkInvariantInternal(l); _v = r; continue; diff --git a/lib/js/Belt_internalAVLset.js b/lib/js/Belt_internalAVLset.js index 303978ce6a..0e218d9390 100644 --- a/lib/js/Belt_internalAVLset.js +++ b/lib/js/Belt_internalAVLset.js @@ -355,11 +355,14 @@ function checkInvariantInternal(_v) { } let l = v.l; let r = v.r; - ( + let diff = ( l !== undefined ? l.h : 0 ) - ( r !== undefined ? r.h : 0 ) | 0; + if (!(diff <= 2 && diff >= -2)) { + + } checkInvariantInternal(l); _v = r; continue; diff --git a/lib/js/Belt_internalAVLtree.js b/lib/js/Belt_internalAVLtree.js index db4b15b247..f4a2ac657b 100644 --- a/lib/js/Belt_internalAVLtree.js +++ b/lib/js/Belt_internalAVLtree.js @@ -556,7 +556,10 @@ function checkInvariantInternal(_v) { } let l = v.l; let r = v.r; - treeHeight(l) - treeHeight(r) | 0; + let diff = treeHeight(l) - treeHeight(r) | 0; + if (!(diff <= 2 && diff >= -2)) { + + } checkInvariantInternal(l); _v = r; continue;