Skip to content

Commit 5cb3752

Browse files
committed
also fix for or expression
1 parent 5091233 commit 5cb3752

File tree

5 files changed

+163
-85
lines changed

5 files changed

+163
-85
lines changed

jscomp/core/lam_compile.ml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -714,20 +714,32 @@ and
714714
(* Invariant: if [should_return], then [st] will not be [NeedValue] *)
715715
->
716716
compile_lambda cxt @@ Lam.sequor l r
717-
| _ ->
718-
let l_block,l_expr =
719-
match compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} l with
720-
| {block = a; value = Some b} -> a, b
721-
| _ -> assert false
722-
in
723-
let r_block, r_expr =
724-
match compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} r with
725-
| {block = a; value = Some b} -> a, b
726-
| _ -> assert false
727-
in
728-
let args_code = Ext_list.append l_block r_block in
729-
let exp = E.or_ l_expr r_expr in
730-
Js_output.output_of_block_and_expression st should_return lam args_code exp
717+
| {should_return = ReturnFalse } ->
718+
let new_cxt = {cxt with st = NeedValue} in
719+
match compile_lambda new_cxt l with
720+
| {value = None } -> assert false
721+
| {block = l_block; value = Some l_expr} ->
722+
match compile_lambda new_cxt r with
723+
| {value = None} -> assert false
724+
| {block = []; value = Some r_expr} ->
725+
let exp = E.or_ l_expr r_expr in
726+
Js_output.output_of_block_and_expression
727+
st should_return lam l_block exp
728+
| {block = r_block; value = Some r_expr} ->
729+
let v = Ext_ident.create_tmp () in
730+
Js_output.output_of_block_and_expression
731+
st
732+
should_return
733+
lam
734+
(S.define_variable ~kind:Variable v E.caml_true
735+
:: l_block @
736+
[ S.if_ (E.not l_expr)
737+
(r_block @ [
738+
S.assign v r_expr
739+
])
740+
]
741+
)
742+
(E.var v)
731743
end
732744
| Lprim {primitive = Pdebugger ; _}
733745
->

jscomp/test/gpr_2608_test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ if (List.length(/* [] */0) > 0) {
2727

2828
var huntGrootCondition = tmp;
2929

30-
eq("File \"gpr_2608_test.ml\", line 17, characters 5-12", huntGrootCondition, /* false */0);
30+
var tmp$1 = /* true */1;
31+
32+
if (List.length(/* [] */0) < 0) {
33+
var x$1 = List.filter((function () {
34+
return +(List.hd(/* [] */0) <= 1000);
35+
}))(oppHeroes);
36+
tmp$1 = +(List.length(x$1) === 0);
37+
}
38+
39+
var huntGrootCondition2 = tmp$1;
40+
41+
eq("File \"gpr_2608_test.ml\", line 23, characters 5-12", huntGrootCondition, /* false */0);
42+
43+
eq("File \"gpr_2608_test.ml\", line 24, characters 5-12", huntGrootCondition2, /* true */1);
3144

3245
Mt.from_pair_suites("gpr_2608_test.ml", suites[0]);
3346

@@ -39,4 +52,5 @@ exports.eq = eq;
3952
exports.nearestGroots = nearestGroots;
4053
exports.oppHeroes = oppHeroes;
4154
exports.huntGrootCondition = huntGrootCondition;
55+
exports.huntGrootCondition2 = huntGrootCondition2;
4256
/* huntGrootCondition Not a pure module */

jscomp/test/gpr_2608_test.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ let huntGrootCondition =
1313
oppHeroes) in
1414
List.length x = 0
1515

16+
let huntGrootCondition2 =
17+
(List.length nearestGroots >= 0 ||
18+
let x = (List.filter (fun h -> (List.hd nearestGroots) <= 1000)
19+
oppHeroes) in
20+
List.length x = 0)
21+
1622
let () =
17-
eq __LOC__ huntGrootCondition false
23+
eq __LOC__ huntGrootCondition false;
24+
eq __LOC__ huntGrootCondition2 true
25+
1826
let () =
1927
Mt.from_pair_suites __FILE__ !suites

jscomp/test/ocaml_typedtree_test.js

Lines changed: 87 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8958,10 +8958,22 @@ function typexp(s, ty) {
89588958
}
89598959
}
89608960
if (exit$2 === 4) {
8961-
var match$6 = more[/* desc */0];
8962-
var tmp$2;
8963-
tmp$2 = typeof match$6 === "number" || match$6.tag !== 3 ? /* false */0 : /* true */1;
8964-
var dup = s[/* for_saving */3] || +(more[/* level */1] === 100000000) || static_row(row) || tmp$2;
8961+
var tmp$2 = /* true */1;
8962+
if (!s[/* for_saving */3]) {
8963+
var tmp$3 = /* true */1;
8964+
if (more[/* level */1] !== 100000000) {
8965+
var tmp$4 = /* true */1;
8966+
if (!static_row(row)) {
8967+
var match$6 = more[/* desc */0];
8968+
var tmp$5;
8969+
tmp$5 = typeof match$6 === "number" || match$6.tag !== 3 ? /* false */0 : /* true */1;
8970+
tmp$4 = tmp$5;
8971+
}
8972+
tmp$3 = tmp$4;
8973+
}
8974+
tmp$2 = tmp$3;
8975+
}
8976+
var dup = tmp$2;
89658977
var match$7 = more[/* desc */0];
89668978
var more$prime;
89678979
var exit$3 = 0;
@@ -10171,18 +10183,22 @@ function normalize_path(lax, env, path) {
1017110183
}
1017210184
catch (exn){
1017310185
if (exn === Caml_builtin_exceptions.not_found) {
10174-
var tmp;
10175-
switch (path$1.tag | 0) {
10176-
case 0 :
10177-
tmp = +(path$1[0][/* stamp */0] !== 0);
10178-
break;
10179-
case 1 :
10180-
case 2 :
10181-
tmp = /* true */1;
10182-
break;
10183-
10186+
var tmp = /* true */1;
10187+
if (!lax) {
10188+
var tmp$1;
10189+
switch (path$1.tag | 0) {
10190+
case 0 :
10191+
tmp$1 = +(path$1[0][/* stamp */0] !== 0);
10192+
break;
10193+
case 1 :
10194+
case 2 :
10195+
tmp$1 = /* true */1;
10196+
break;
10197+
10198+
}
10199+
tmp = tmp$1;
1018410200
}
10185-
if (lax || tmp) {
10201+
if (tmp) {
1018610202
return path$1;
1018710203
} else {
1018810204
throw exn;
@@ -29035,8 +29051,10 @@ function unify3(env, t1, t1$prime, t2, t2$prime) {
2903529051
return unify_list(env, tl1, tl2);
2903629052
}));
2903729053
} else {
29038-
var partial_arg = env[0];
29039-
if (in_current_module(p1) || List.exists((function (param) {
29054+
var tmp = /* true */1;
29055+
if (!in_current_module(p1)) {
29056+
var partial_arg = env[0];
29057+
tmp = List.exists((function (param) {
2904029058
return expands_to_datatype(partial_arg, param);
2904129059
}), /* :: */[
2904229060
t1$prime,
@@ -29047,7 +29065,9 @@ function unify3(env, t1, t1$prime, t2, t2$prime) {
2904729065
/* [] */0
2904829066
]
2904929067
]
29050-
])) {
29068+
]);
29069+
}
29070+
if (tmp) {
2905129071
unify_list(env, tl1, tl2);
2905229072
} else {
2905329073
var inj;
@@ -29169,20 +29189,20 @@ function unify3(env, t1, t1$prime, t2, t2$prime) {
2916929189
var match$6 = match$5[0][1];
2917029190
if (match$6) {
2917129191
var match$7 = repr(match$6[0])[/* desc */0];
29172-
var tmp;
29192+
var tmp$1;
2917329193
if (typeof match$7 === "number") {
29174-
tmp = /* true */1;
29194+
tmp$1 = /* true */1;
2917529195
} else {
2917629196
switch (match$7.tag | 0) {
2917729197
case 0 :
2917829198
case 9 :
29179-
tmp = /* true */1;
29199+
tmp$1 = /* true */1;
2918029200
break;
2918129201
default:
29182-
tmp = /* false */0;
29202+
tmp$1 = /* false */0;
2918329203
}
2918429204
}
29185-
if (!tmp) {
29205+
if (!tmp$1) {
2918629206
set_name(nm2, nm1[0]);
2918729207
}
2918829208

@@ -62335,19 +62355,23 @@ function type_application(env, funct, sargs) {
6233562355
}
6233662356
};
6233762357
var ignored = [/* [] */0];
62338-
var match = list_labels(env, funct[/* exp_type */3]);
62339-
var tmp = /* false */0;
62340-
if (!match[1]) {
62341-
var labels = List.filter((function (l) {
62342-
return 1 - is_optional(l);
62343-
}))(match[0]);
62344-
tmp = +(List.length(labels) === List.length(sargs)) && List.for_all((function (param) {
62345-
return +(param[0] === "");
62346-
}), sargs) && List.exists((function (l) {
62347-
return +(l !== "");
62348-
}), labels) && (prerr_warning(funct[/* exp_loc */1], /* Labels_omitted */3), /* true */1);
62349-
}
62350-
var ignore_labels = classic[0] || tmp;
62358+
var tmp = /* true */1;
62359+
if (!classic[0]) {
62360+
var match = list_labels(env, funct[/* exp_type */3]);
62361+
var tmp$1 = /* false */0;
62362+
if (!match[1]) {
62363+
var labels = List.filter((function (l) {
62364+
return 1 - is_optional(l);
62365+
}))(match[0]);
62366+
tmp$1 = +(List.length(labels) === List.length(sargs)) && List.for_all((function (param) {
62367+
return +(param[0] === "");
62368+
}), sargs) && List.exists((function (l) {
62369+
return +(l !== "");
62370+
}), labels) && (prerr_warning(funct[/* exp_loc */1], /* Labels_omitted */3), /* true */1);
62371+
}
62372+
tmp = tmp$1;
62373+
}
62374+
var ignore_labels = tmp;
6235162375
var warned = [/* false */0];
6235262376
var type_args = function (_args, _omitted, _ty_fun, _ty_fun0, _ty_old, _sargs, _more_sargs) {
6235362377
while(true) {
@@ -65564,21 +65588,25 @@ function check_well_founded(env, loc, path, to_check, ty) {
6556465588
catch (raw_exn){
6556565589
var exn$1 = Js_exn.internalToOCamlException(raw_exn);
6556665590
if (exn$1 === Cannot_expand) {
65567-
var match$3 = ty$1[/* desc */0];
65568-
var tmp$1;
65569-
if (typeof match$3 === "number") {
65570-
tmp$1 = /* false */0;
65571-
} else {
65572-
switch (match$3.tag | 0) {
65573-
case 4 :
65574-
case 8 :
65575-
tmp$1 = /* true */1;
65576-
break;
65577-
default:
65578-
tmp$1 = /* false */0;
65591+
var tmp$1 = /* true */1;
65592+
if (!(recursive_types[0] && is_contractive(env, ty$1))) {
65593+
var match$3 = ty$1[/* desc */0];
65594+
var tmp$2;
65595+
if (typeof match$3 === "number") {
65596+
tmp$2 = /* false */0;
65597+
} else {
65598+
switch (match$3.tag | 0) {
65599+
case 4 :
65600+
case 8 :
65601+
tmp$2 = /* true */1;
65602+
break;
65603+
default:
65604+
tmp$2 = /* false */0;
65605+
}
6557965606
}
65607+
tmp$1 = tmp$2;
6558065608
}
65581-
var nodes = recursive_types[0] && is_contractive(env, ty$1) || tmp$1 ? /* Empty */0 : exp_nodes$1;
65609+
var nodes = tmp$1 ? /* Empty */0 : exp_nodes$1;
6558265610
return iter_type_expr((function (param) {
6558365611
return check(ty0, nodes, param);
6558465612
}), ty$1);
@@ -70707,12 +70735,16 @@ function class_expr(cl_num, val_env, met_env, _scl) {
7070770735
}
7070870736
};
7070970737
};
70710-
var labels = nonopt_labels(/* [] */0, cl$2[/* cl_type */2]);
70711-
var ignore_labels = classic[0] || +(List.length(labels) === List.length(sargs)) && List.for_all((function (param) {
70712-
return +(param[0] === "");
70713-
}), sargs) && List.exists((function (l) {
70714-
return +(l !== "");
70715-
}), labels) && (prerr_warning(cl$2[/* cl_loc */1], /* Labels_omitted */3), /* true */1);
70738+
var tmp = /* true */1;
70739+
if (!classic[0]) {
70740+
var labels = nonopt_labels(/* [] */0, cl$2[/* cl_type */2]);
70741+
tmp = +(List.length(labels) === List.length(sargs)) && List.for_all((function (param) {
70742+
return +(param[0] === "");
70743+
}), sargs) && List.exists((function (l) {
70744+
return +(l !== "");
70745+
}), labels) && (prerr_warning(cl$2[/* cl_loc */1], /* Labels_omitted */3), /* true */1);
70746+
}
70747+
var ignore_labels = tmp;
7071670748
var type_args = (function(cl$2,ignore_labels){
7071770749
return function type_args(_args, _omitted, _ty_fun, _ty_fun0, _sargs, _more_sargs) {
7071870750
while(true) {

lib/whole_compiler.ml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98090,20 +98090,32 @@ and
9809098090
(* Invariant: if [should_return], then [st] will not be [NeedValue] *)
9809198091
->
9809298092
compile_lambda cxt @@ Lam.sequor l r
98093-
| _ ->
98094-
let l_block,l_expr =
98095-
match compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} l with
98096-
| {block = a; value = Some b} -> a, b
98097-
| _ -> assert false
98098-
in
98099-
let r_block, r_expr =
98100-
match compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} r with
98101-
| {block = a; value = Some b} -> a, b
98102-
| _ -> assert false
98103-
in
98104-
let args_code = Ext_list.append l_block r_block in
98105-
let exp = E.or_ l_expr r_expr in
98106-
Js_output.output_of_block_and_expression st should_return lam args_code exp
98093+
| {should_return = ReturnFalse } ->
98094+
let new_cxt = {cxt with st = NeedValue} in
98095+
match compile_lambda new_cxt l with
98096+
| {value = None } -> assert false
98097+
| {block = l_block; value = Some l_expr} ->
98098+
match compile_lambda new_cxt r with
98099+
| {value = None} -> assert false
98100+
| {block = []; value = Some r_expr} ->
98101+
let exp = E.or_ l_expr r_expr in
98102+
Js_output.output_of_block_and_expression
98103+
st should_return lam l_block exp
98104+
| {block = r_block; value = Some r_expr} ->
98105+
let v = Ext_ident.create_tmp () in
98106+
Js_output.output_of_block_and_expression
98107+
st
98108+
should_return
98109+
lam
98110+
(S.define_variable ~kind:Variable v E.caml_true
98111+
:: l_block @
98112+
[ S.if_ (E.not l_expr)
98113+
(r_block @ [
98114+
S.assign v r_expr
98115+
])
98116+
]
98117+
)
98118+
(E.var v)
9810798119
end
9810898120
| Lprim {primitive = Pdebugger ; _}
9810998121
->

0 commit comments

Comments
 (0)