Skip to content

Commit 909fda9

Browse files
authored
Merge pull request #4298 from BuckleScript/fix_4280
fix #4280
2 parents 6553be4 + 0304ac3 commit 909fda9

20 files changed

+1613
-1216
lines changed

jscomp/common/ext_log.ml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@
3333

3434
type 'a logging = ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a
3535

36-
let err str f =
37-
Format.fprintf Format.err_formatter ("%s " ^^ f ^^ "@.") str
38-
39-
let ierr b str f =
40-
if b then
41-
Format.fprintf Format.err_formatter ("%s " ^^ f) str
42-
else
43-
Format.ifprintf Format.err_formatter ("%s " ^^ f) str
44-
45-
let warn str f =
46-
Format.fprintf Format.err_formatter ("WARN: %s " ^^ f ^^ "@.") str
47-
48-
49-
50-
let iwarn b str f =
51-
if b then
52-
Format.fprintf Format.err_formatter ("WARN: %s " ^^ f) str
53-
else
54-
Format.ifprintf Format.err_formatter ("WARN: %s " ^^ f) str
5536

5637
(* TODO: add {[@.]} later for all *)
5738
let dwarn ?(__POS__: (string * int * int * int) option) f =
@@ -62,13 +43,3 @@ let dwarn ?(__POS__: (string * int * int * int) option) f =
6243
Format.fprintf Format.err_formatter ("WARN: %s,%d " ^^ f ^^ "@.") file line
6344
else
6445
Format.ifprintf Format.err_formatter ("WARN: " ^^ f ^^ "@.")
65-
66-
let info str f =
67-
Format.fprintf Format.err_formatter ("INFO: %s " ^^ f) str
68-
69-
let iinfo b str f =
70-
if b then
71-
Format.fprintf Format.err_formatter ("INFO: %s " ^^ f) str
72-
else
73-
Format.fprintf Format.err_formatter ("INFO: %s " ^^ f) str
74-

jscomp/common/ext_log.mli

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,10 @@
4242
type 'a logging = ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a
4343

4444

45-
val err : string -> 'a logging
46-
val ierr : bool -> string -> 'a logging
47-
val warn : string -> 'a logging
48-
val iwarn : bool -> string -> 'a logging
45+
46+
4947

5048
val dwarn :
5149
?__POS__:(string * int * int *int) ->
5250
'a logging
5351

54-
val info : string -> 'a logging
55-
val iinfo : bool -> string -> 'a logging

jscomp/core/js_pass_scope.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030

3131

32-
let _l idents =
33-
Ext_log.err __LOC__ "hey .. %s@."
34-
(String.concat "," @@ Ext_list.map idents (fun i -> i.Ident.name ) )
3532

3633
(*
3734

jscomp/core/lam_compile.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ let change_tail_type_in_try
7979
Maybe_tail_is_return Tail_in_try
8080
| Not_tail | Maybe_tail_is_return Tail_in_try
8181
-> x
82+
let in_staticcatch (x : Lam_compile_context.tail_type)
83+
: Lam_compile_context.tail_type =
84+
match x with
85+
| Maybe_tail_is_return (Tail_with_name ({in_staticcatch = false} as x))
86+
->
87+
Maybe_tail_is_return (Tail_with_name ({ x with in_staticcatch = true}))
88+
| _ -> x
8289

8390
(* let change_tail_type_in_static
8491
(x : Lam_compile_context.tail_type)
@@ -745,7 +752,7 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
745752
let code_table, body = flatten_nested_caches lam in
746753
let exit_id = Ext_ident.create_tmp ~name:"exit" () in
747754
match lambda_cxt.continuation, code_table with
748-
| EffectCall (Maybe_tail_is_return (Tail_with_name ({in_staticcatch = false} as z))),
755+
| EffectCall (Maybe_tail_is_return (Tail_with_name ({in_staticcatch = false} )) as tail_type),
749756
[ code_table ]
750757
(* tail position and only one exit code *)
751758
when Lam_compile_context.no_static_raise_in_handler code_table
@@ -758,7 +765,7 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
758765
{lambda_cxt with
759766
jmp_table = jmp_table ;
760767
continuation =
761-
EffectCall (Maybe_tail_is_return (Tail_with_name { z with in_staticcatch = true}))
768+
EffectCall (in_staticcatch tail_type)
762769
} in
763770

764771
let lbody = compile_lambda new_cxt body in
@@ -804,8 +811,12 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
804811
(* place holder -- tell the compiler that
805812
we don't know if it's complete
806813
*)
807-
| EffectCall tail_type ->
808-
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
814+
| EffectCall tail_type as cont ->
815+
let continuation =
816+
let new_tail_type = (in_staticcatch tail_type) in
817+
if new_tail_type == tail_type then cont else EffectCall new_tail_type
818+
in
819+
let new_cxt = {lambda_cxt with jmp_table = jmp_table ; continuation } in
809820
let lbody = compile_lambda new_cxt body in
810821
Js_output.append_output (Js_output.make declares)
811822
(Js_output.append_output lbody

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ build test/gpr_405_test.cmj : cc_cmi test/gpr_405_test.ml | test/gpr_405_test.cm
320320
build test/gpr_405_test.cmi : cc test/gpr_405_test.mli | $stdlib
321321
build test/gpr_4069_test.cmi test/gpr_4069_test.cmj : cc test/gpr_4069_test.ml | $stdlib
322322
build test/gpr_4265_test.cmi test/gpr_4265_test.cmj : cc test/gpr_4265_test.ml | test/mt.cmj $stdlib
323+
build test/gpr_4280_test.cmi test/gpr_4280_test.cmj : cc test/gpr_4280_test.ml | test/mt.cmj $stdlib
323324
build test/gpr_441.cmi test/gpr_441.cmj : cc test/gpr_441.ml | $stdlib
324325
build test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
325326
build test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib

jscomp/test/gpr_4280_test.js

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
'use strict';
2+
3+
var Mt = require("./mt.js");
4+
5+
var suites = {
6+
contents: /* [] */0
7+
};
8+
9+
var test_id = {
10+
contents: 0
11+
};
12+
13+
function eq(loc, x, y) {
14+
return Mt.eq_suites(test_id, suites, loc, x, y);
15+
}
16+
17+
var u = {
18+
contents: 0
19+
};
20+
21+
function div(children, param) {
22+
for(var i = 0; i <= 1; ++i){
23+
u.contents = 300;
24+
console.log("nonline");
25+
}
26+
27+
}
28+
29+
function string(s) {
30+
for(var i = 0; i <= 1; ++i){
31+
u.contents = 200;
32+
console.log("no");
33+
}
34+
35+
}
36+
37+
function fn(authState, route) {
38+
var exit = 0;
39+
var onboardingRoute;
40+
if (typeof authState === "number") {
41+
var exit$1 = 0;
42+
if (typeof route === "number") {
43+
if (route >= -730831382) {
44+
if (route !== -384135774 && route !== -384133096) {
45+
exit$1 = 3;
46+
} else {
47+
exit = 2;
48+
}
49+
} else if (route !== -799423340 && route < -730831383) {
50+
exit$1 = 3;
51+
} else {
52+
exit = 2;
53+
}
54+
} else if (route[0] !== 378129979) {
55+
exit$1 = 3;
56+
} else {
57+
onboardingRoute = route[1];
58+
exit = 1;
59+
}
60+
if (exit$1 === 3) {
61+
div(/* :: */[
62+
string("Redirect"),
63+
/* [] */0
64+
], undefined);
65+
return 3;
66+
}
67+
68+
} else {
69+
var exit$2 = 0;
70+
if (typeof route === "number" || route[0] !== 378129979) {
71+
exit$2 = 3;
72+
} else {
73+
onboardingRoute = route[1];
74+
exit = 1;
75+
}
76+
if (exit$2 === 3) {
77+
console.log(authState[1]);
78+
div(/* :: */[
79+
string("VerifyEmail"),
80+
/* [] */0
81+
], undefined);
82+
return 2;
83+
}
84+
85+
}
86+
switch (exit) {
87+
case 1 :
88+
console.log(onboardingRoute);
89+
div(/* :: */[
90+
string("Onboarding"),
91+
/* [] */0
92+
], undefined);
93+
return 0;
94+
case 2 :
95+
div(/* :: */[
96+
string("LoggedOut"),
97+
/* [] */0
98+
], undefined);
99+
return 1;
100+
101+
}
102+
}
103+
104+
eq("File \"gpr_4280_test.ml\", line 46, characters 6-13", fn(/* Unauthenticated */-54822762, /* Invite */-730831383), 1);
105+
106+
eq("File \"gpr_4280_test.ml\", line 47, characters 6-13", fn(/* Unauthenticated */-54822762, /* `Onboarding */[
107+
378129979,
108+
0
109+
]), 0);
110+
111+
eq("File \"gpr_4280_test.ml\", line 48, characters 6-13", fn(/* `Unverified */[
112+
254489473,
113+
0
114+
], /* Invite */-730831383), 2);
115+
116+
eq("File \"gpr_4280_test.ml\", line 49, characters 6-13", fn(/* Unauthenticated */-54822762, /* xx */26880), 3);
117+
118+
Mt.from_pair_suites("gpr_4280_test.ml", suites.contents);
119+
120+
exports.suites = suites;
121+
exports.test_id = test_id;
122+
exports.eq = eq;
123+
exports.u = u;
124+
exports.div = div;
125+
exports.string = string;
126+
exports.fn = fn;
127+
/* Not a pure module */

jscomp/test/gpr_4280_test.ml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[@@@bs.config {flags = [|"-bs-diagnose"|]}]
2+
let suites : Mt.pair_suites ref = ref []
3+
let test_id = ref 0
4+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
5+
6+
let u = ref 0
7+
let div ~children () =
8+
for i = 0 to 1 do
9+
u := 300;
10+
Js.log "nonline"
11+
done
12+
13+
let string (s : string) =
14+
for i = 0 to 1 do
15+
u := 200;
16+
Js.log "no"
17+
done
18+
19+
let fn authState route =
20+
match (authState, route) with
21+
| (`Unauthenticated,`Onboarding onboardingRoute)
22+
| (`Unverified _,`Onboarding onboardingRoute) ->
23+
Js.Console.log onboardingRoute;
24+
div
25+
~children:[string
26+
"Onboarding"] ();
27+
0
28+
| (`Unauthenticated,`SignIn)|(`Unauthenticated,`SignUp)
29+
|(`Unauthenticated,`Invite)|(`Unauthenticated,`PasswordReset) ->
30+
div
31+
~children:[string
32+
"LoggedOut"] ();1
33+
34+
| (`Unverified user,_) ->
35+
Js.Console.log user;
36+
div
37+
~children:[string
38+
"VerifyEmail"] ();
39+
2
40+
| (`Unauthenticated,_) ->
41+
div
42+
~children:[string
43+
"Redirect"] ();3
44+
45+
46+
;; eq __LOC__ (fn (`Unauthenticated) `Invite) 1
47+
;; eq __LOC__ (fn (`Unauthenticated) (`Onboarding 0)) 0
48+
;; eq __LOC__ (fn (`Unverified 0) `Invite) 2
49+
;; eq __LOC__ (fn `Unauthenticated `xx) 3
50+
;; Mt.from_pair_suites __FILE__ !suites

0 commit comments

Comments
 (0)