Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions jscomp/core/bs_conditional_initial.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ let setup_env () =
Translcore.wrap_single_field_record := Transl_single_field_record.wrap_single_field_record;
Translmod.eval_rec_bindings := Compile_rec_module.eval_rec_bindings;
Typemod.should_hide := Typemod_hide.should_hide;
#if 0 then
Matching.make_test_sequence_variant_constant := Polyvar_pattern_match.make_test_sequence_variant_constant;
Matching.call_switcher_variant_constant := Polyvar_pattern_match.call_switcher_variant_constant;
Matching.call_switcher_variant_constr := Polyvar_pattern_match.call_switcher_variant_constr;
#end
Clflags.no_std_include := true;
Warnings.parse_options false Bsc_warnings.defaults_w;
Warnings.parse_options true Bsc_warnings.defaults_warn_error;
Expand Down
100 changes: 30 additions & 70 deletions jscomp/core/polyvar_pattern_match.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,36 @@

type lam = Lambda.lambda

type hash_names = (int * string) list

module Map_lambda = struct
open Map_gen
type key =
| Bottom of int
| Normalized of lam
type input = (int * (string * lam)) list
type output = (hash_names * lam) list
module Coll = Hash.Make(struct
type t = lam
let equal = Pervasives.(=)
let hash = Hashtbl.hash
end)
type value = {
stamp : int ;
hash_names_act : hash_names * lam
}

let bottom_id = ref (-1)
let bottom () = incr bottom_id ; Bottom !bottom_id
let compare_key (x : key) (y : key) = Pervasives.compare x y
let old_order = ref 1
let next_id () =
incr old_order; !old_order
let rec adjust (tree : _ Map_gen.t as 'a) x replace : 'a =
match tree with
| Empty ->
singleton x (replace None)
| Leaf {k ; v} ->
let c = compare_key x k in
if c = 0 then singleton x (replace (Some v)) else
if c < 0 then
Map_gen.unsafe_two_elements x (replace None) k v
else
Map_gen.unsafe_two_elements k v x (replace None)
| Node ({l; k ; r} as tree) ->
let c = compare_key x k in
if c = 0 then
Map_gen.unsafe_node x (replace (Some tree.v)) l r tree.h
else if c < 0 then
bal (adjust l x replace ) k tree.v r
else
bal l k tree.v (adjust r x replace )


let of_list (int_lambda_list : (int * (string * lam)) list) : (key, (int * string) list * lam * int ) t=
Ext_list.fold_left int_lambda_list empty (fun acc (hash,(name,lam)) ->
let key =
match Lambda.make_key lam with
| None -> bottom ()
| Some key -> Normalized key in
adjust acc key (function
| None -> [hash, name], lam, next_id ()
| Some (acc,action,stamp) -> (hash,name) :: acc, action, stamp
))
let rec values_aux s acc =
match s with
| Empty -> acc
| Leaf {v} -> v :: acc
| Node {l;v;r} ->
values_aux l (v ::values_aux r acc)
let values s : ((int * string) list * lam) list =
Ext_list.sort_via_arrayf ( values_aux s [])
(fun (_,_,d0) (_,_,d1) -> compare d0 d1)
(fun (a,b,_) -> (a,b))

end
let convert (xs : input) : output =
let coll = Coll.create 63 in
let os : value list ref = ref [] in
xs |> List.iteri (fun i (hash,(name,act)) ->
match Lambda.make_key act with
| None -> os := { stamp = i; hash_names_act = ([hash,name],act)} :: !os
| Some key ->
Coll.add_or_update coll key
~update:(fun ({hash_names_act = hash_names, act } as acc) ->
{acc with hash_names_act = (hash,name) :: hash_names, act })
{hash_names_act = [hash,name],act; stamp = i }
);
let result =
Coll.to_list coll (fun _ value -> value )
@ !os in
Ext_list.sort_via_arrayf result (fun x y -> compare x.stamp y.stamp ) (fun x -> x.hash_names_act )

let or_list (arg : lam) (hash_names : (int * string) list) =
match hash_names with
Expand All @@ -103,7 +77,7 @@ let make_test_sequence_variant_constant
(fail : lam option) (arg : lam)
(int_lambda_list : (int * (string * lam) ) list) : lam =
let int_lambda_list : ((int * string) list * lam) list =
Map_lambda.(values (of_list int_lambda_list)) in
convert int_lambda_list in
match int_lambda_list, fail with
| (_, act) :: rest, None
| rest, Some act ->
Expand All @@ -112,19 +86,6 @@ let make_test_sequence_variant_constant
Lifthenelse (predicate,act1, acc))
| [], None -> assert false

let make_test_sequence_variant_constant_2
(fail : lam option) (arg : lam)
(int_lambda_list : (int * (string * lam) ) list) : lam=
match int_lambda_list, fail with
| (_, (_,act)) :: rest, None
| rest , Some act ->
Ext_list.fold_right rest act (fun (hash1,(name,act1)) acc ->
Lifthenelse (Lprim(Pintcomp Ceq,
[arg; Lconst (Const_pointer(hash1, Pt_variant{name}))], Location.none),
act1, acc
)
)
| [], None -> assert false

let call_switcher_variant_constant
(_loc : Location.t)
Expand All @@ -133,8 +94,7 @@ let call_switcher_variant_constant
(int_lambda_list : (int * (string * lam)) list)
(_names : Lambda.switch_names option) =

let int_lambda_list : ((int * string) list * lam) list =
Map_lambda.(values (of_list int_lambda_list)) in
let int_lambda_list = convert int_lambda_list in
match int_lambda_list, fail with
| (_,act) :: rest, None
| rest, Some act ->
Expand Down
24 changes: 10 additions & 14 deletions jscomp/test/bb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@


function f(x) {
if (x !== 98) {
if (x >= 99) {
return "c";
} else {
return "a";
}
} else {
if (x === /* b */98) {
return "b";
} else if (x === /* c */99) {
return "c";
} else {
return "a";
}
}

Expand Down Expand Up @@ -57,14 +55,12 @@ function test(x) {
Error: new Error()
};
}
if (match !== 98) {
if (match >= 99) {
return "c";
} else {
return "a";
}
} else {
if (match === /* b */98) {
return "b";
} else if (match === /* c */99) {
return "c";
} else {
return "a";
}
}

Expand Down
12 changes: 5 additions & 7 deletions jscomp/test/const_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ function fff(x) {
}

function h(x) {
if (x !== 66) {
if (x >= 67) {
return 2;
} else {
return 0;
}
} else {
if (x === /* B */66) {
return 1;
} else if (x === /* C */67) {
return 2;
} else {
return 0;
}
}

Expand Down
8 changes: 4 additions & 4 deletions jscomp/test/ext_filename_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ function chop_extension_if_any(fname) {
var os_path_separator_char = Filename.dir_sep.charCodeAt(0);

function relative_path(file_or_dir_1, file_or_dir_2) {
var relevant_dir1 = file_or_dir_1.HASH >= 781515420 ? Curry._1(Filename.dirname, file_or_dir_1.VAL) : file_or_dir_1.VAL;
var relevant_dir2 = file_or_dir_2.HASH >= 781515420 ? Curry._1(Filename.dirname, file_or_dir_2.VAL) : file_or_dir_2.VAL;
var relevant_dir1 = file_or_dir_1.HASH === /* File */781515420 ? Curry._1(Filename.dirname, file_or_dir_1.VAL) : file_or_dir_1.VAL;
var relevant_dir2 = file_or_dir_2.HASH === /* File */781515420 ? Curry._1(Filename.dirname, file_or_dir_2.VAL) : file_or_dir_2.VAL;
var dir1 = Ext_string_test.split(undefined, relevant_dir1, os_path_separator_char);
var dir2 = Ext_string_test.split(undefined, relevant_dir2, os_path_separator_char);
var go = function (_dir1, _dir2) {
Expand Down Expand Up @@ -149,13 +149,13 @@ function node_relative_path(node_modules_shorten, file1, dep_file) {
var v = Ext_string_test.find(undefined, Test_literals.node_modules, file2);
var len = file2.length;
if (!(node_modules_shorten && v >= 0)) {
return relative_path(dep_file.HASH >= 781515420 ? ({
return relative_path(dep_file.HASH === /* File */781515420 ? ({
HASH: /* File */781515420,
VAL: absolute_path(dep_file.VAL)
}) : ({
HASH: /* Dir */3405101,
VAL: absolute_path(dep_file.VAL)
}), file1.HASH >= 781515420 ? ({
}), file1.HASH === /* File */781515420 ? ({
HASH: /* File */781515420,
VAL: absolute_path(file1.VAL)
}) : ({
Expand Down
10 changes: 5 additions & 5 deletions jscomp/test/gpr_1891_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var Curry = require("../../lib/js/curry.js");

function foo(x) {
if (typeof x === "number" || x.HASH !== 3505894 || x.VAL !== 3) {
if (typeof x === "number" || !(x.HASH === /* Foo */3505894 && x.VAL === 3)) {
console.log("2");
} else {
console.log("1");
Expand All @@ -12,31 +12,31 @@ function foo(x) {
}

function foo2(x) {
if (typeof x === "number" || x.HASH !== 3505894 || x.VAL !== 3) {
if (typeof x === "number" || !(x.HASH === /* Foo */3505894 && x.VAL === 3)) {
return "xxx";
} else {
return "xxxx";
}
}

function foo3(x) {
if (typeof x === "number" || x.HASH !== 3505894 || x.VAL !== 3) {
if (typeof x === "number" || !(x.HASH === /* Foo */3505894 && x.VAL === 3)) {
return 2;
} else {
return 1;
}
}

function foo4(x, h) {
if (typeof x === "number" || x.HASH !== 3505894 || x.VAL !== 3) {
if (typeof x === "number" || !(x.HASH === /* Foo */3505894 && x.VAL === 3)) {
return ;
} else {
return Curry._1(h, undefined);
}
}

function foo5(x) {
if (typeof x === "number" || x.HASH !== 3505894 || x.VAL !== 3) {
if (typeof x === "number" || !(x.HASH === /* Foo */3505894 && x.VAL === 3)) {
console.log("x");
} else {
console.log("hi");
Expand Down
60 changes: 22 additions & 38 deletions jscomp/test/gpr_4280_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,24 @@ function string(s) {
}

function fn(authState, route) {
var exit = 0;
var onboardingRoute;
if (typeof authState === "number") {
var exit$1 = 0;
var exit = 0;
if (typeof route === "number") {
if (route >= -730831382) {
if (route !== -384135774 && route !== -384133096) {
exit$1 = 3;
} else {
exit = 2;
}
} else if (route !== -799423340 && route < -730831383) {
exit$1 = 3;
} else {
exit = 2;
if (route === /* SignUp */-384133096 || route === /* SignIn */-384135774 || route === /* Invite */-730831383 || route === /* PasswordReset */-799423340) {
div({
hd: string("LoggedOut"),
tl: /* [] */0
}, undefined);
return 1;
}
} else if (route.HASH !== 378129979) {
exit$1 = 3;
} else {
exit = 2;
} else if (route.HASH === /* Onboarding */378129979) {
onboardingRoute = route.VAL;
exit = 1;
} else {
exit = 2;
}
if (exit$1 === 3) {
if (exit === 2) {
div({
hd: string("Redirect"),
tl: /* [] */0
Expand All @@ -66,14 +61,13 @@ function fn(authState, route) {
}

} else {
var exit$2 = 0;
if (typeof route === "number" || route.HASH !== 378129979) {
exit$2 = 3;
var exit$1 = 0;
if (typeof route === "number" || route.HASH !== /* Onboarding */378129979) {
exit$1 = 2;
} else {
onboardingRoute = route.VAL;
exit = 1;
}
if (exit$2 === 3) {
if (exit$1 === 2) {
console.log(authState.VAL);
div({
hd: string("VerifyEmail"),
Expand All @@ -83,22 +77,12 @@ function fn(authState, route) {
}

}
switch (exit) {
case 1 :
console.log(onboardingRoute);
div({
hd: string("Onboarding"),
tl: /* [] */0
}, undefined);
return 0;
case 2 :
div({
hd: string("LoggedOut"),
tl: /* [] */0
}, undefined);
return 1;

}
console.log(onboardingRoute);
div({
hd: string("Onboarding"),
tl: /* [] */0
}, undefined);
return 0;
}

eq("File \"gpr_4280_test.ml\", line 46, characters 6-13", fn(/* Unauthenticated */-54822762, /* Invite */-730831383), 1);
Expand Down
Loading