Skip to content

Commit 3e5a2d7

Browse files
committed
Make switch_names optional, and remove temp hack for testing.
1 parent aa2ac4c commit 3e5a2d7

22 files changed

+219
-192
lines changed

Diff for: jscomp/core/lam.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module Types = struct
9494
| Llet of Lam_compat.let_kind * ident * t * t
9595
| Lletrec of (ident * t) list * t
9696
| Lprim of prim_info
97-
| Lswitch of t * switch * switch_names
97+
| Lswitch of t * switch * switch_names option
9898
| Lstringswitch of t * (string * t) list * t option
9999
| Lstaticraise of int * t list
100100
| Lstaticcatch of t * (int * ident list) * t
@@ -152,7 +152,7 @@ module X = struct
152152
| Llet of Lam_compat.let_kind * ident * t * t
153153
| Lletrec of (ident * t) list * t
154154
| Lprim of prim_info
155-
| Lswitch of t * switch * switch_names
155+
| Lswitch of t * switch * switch_names option
156156
| Lstringswitch of t * (string * t) list * t option
157157
| Lstaticraise of int * t list
158158
| Lstaticcatch of t * (int * ident list) * t

Diff for: jscomp/core/lam.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ and t = private
6666
| Llet of Lam_compat.let_kind * ident * t * t
6767
| Lletrec of (ident * t) list * t
6868
| Lprim of prim_info
69-
| Lswitch of t * switch * switch_names
69+
| Lswitch of t * switch * switch_names option
7070
| Lstringswitch of t * (string * t) list * t option
7171
| Lstaticraise of int * t list
7272
| Lstaticcatch of t * (int * ident list) * t
@@ -116,7 +116,7 @@ val letrec : (ident * t) list -> t -> t
116116
val if_ : t -> t -> t -> t
117117

118118
(** constant folding*)
119-
val switch : t -> switch -> switch_names -> t
119+
val switch : t -> switch -> switch_names option -> t
120120
(** constant folding*)
121121
val stringswitch : t -> (string * t) list -> t option -> t
122122

Diff for: jscomp/core/lam_compile.ml

+18-12
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,20 @@ and compile_general_cases
518518
and compile_cases ~is_tag cxt switch_exp table default names =
519519
compile_general_cases
520520
(fun i ->
521-
if names.Lam.consts = [| "Constant" |] then None else
522-
match (if is_tag then names.Lam.blocks.(i) else names.consts.(i)) with
523-
| s -> Some s
524-
| exception Invalid_argument _ -> Some "Unknown")
521+
match names with
522+
| None -> None
523+
| Some {Lam.blocks; consts} ->
524+
match (if is_tag then blocks.(i) else consts.(i)) with
525+
| s -> Some s
526+
| exception Invalid_argument _ -> Some "Unknown")
525527
(fun i ->
526-
let comment = match (if is_tag then names.Lam.blocks.(i) else names.consts.(i)) with
527-
| s -> Some s
528-
| exception Invalid_argument _ -> Some "Unknown" in
528+
let comment =
529+
match names with
530+
| None -> None
531+
| Some {Lam.blocks; consts} ->
532+
match (if is_tag then blocks.(i) else consts.(i)) with
533+
| s -> Some s
534+
| exception Invalid_argument _ -> Some "Unknown" in
529535
{(E.small_int i) with comment})
530536
E.int_equal
531537
cxt
@@ -534,7 +540,7 @@ and compile_cases ~is_tag cxt switch_exp table default names =
534540
switch_exp
535541
table
536542
default
537-
and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) names =
543+
and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) (names : Lam.switch_names option) =
538544
(* TODO: if default is None, we can do some optimizations
539545
Use switch vs if/then/else
540546
@@ -765,15 +771,15 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
765771
Js_output.append_output
766772
(Js_output.make (S.declare_variable ~kind:Variable v :: declares) )
767773
(Js_output.append_output lbody (Js_output.make (
768-
compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[| "Constant" |]; blocks=[||]}) ~value:(E.var v )))
774+
compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete (Some {consts=[||]; blocks=[||]})) ~value:(E.var v )))
769775
| Declare (kind, id)
770776
(* declare first this we will do branching*) ->
771777
let declares = S.declare_variable ~kind id :: declares in
772778
let new_cxt = {lambda_cxt with jmp_table = jmp_table; continuation = Assign id } in
773779
let lbody = compile_lambda new_cxt body in
774780
Js_output.append_output (Js_output.make declares)
775781
(Js_output.append_output lbody
776-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[|"Constant"|]; blocks=[||]})))
782+
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete (Some {consts=[||]; blocks=[||]}))))
777783
(* place holder -- tell the compiler that
778784
we don't know if it's complete
779785
*)
@@ -782,13 +788,13 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
782788
let lbody = compile_lambda new_cxt body in
783789
Js_output.append_output (Js_output.make declares)
784790
(Js_output.append_output lbody
785-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[|"Constant"|]; blocks=[||]})))
791+
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete (Some {consts=[||]; blocks=[||]}))))
786792
| Assign _ ->
787793
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
788794
let lbody = compile_lambda new_cxt body in
789795
Js_output.append_output (Js_output.make declares)
790796
(Js_output.append_output lbody
791-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[|"Constant"|]; blocks=[||]})))
797+
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete (Some {consts=[||]; blocks=[||]}))))
792798

793799
and compile_sequand
794800
(l : Lam.t) (r : Lam.t) (lambda_cxt : Lam_compile_context.t) =

Diff for: jscomp/core/lam_convert.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,12 @@ let convert (exports : Ident_set.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
759759
Lam.apply fn (Ext_list.append_one args x) outer_loc App_na
760760
| _ ->
761761
Lam.apply f [x] outer_loc App_na
762-
and convert_switch (e : Lambda.lambda) (s : Lambda.lambda_switch) (names : Lambda.switch_names) =
762+
and convert_switch (e : Lambda.lambda) (s : Lambda.lambda_switch) (names : Lambda.switch_names option) =
763763
let e = convert_aux e in
764-
let names = {Lam.consts=names.consts; blocks = names.blocks} in
764+
let names = match names with
765+
| None -> None
766+
| Some {consts; blocks} ->
767+
Some {Lam.consts; blocks} in
765768
match s with
766769
| {
767770
sw_failaction = None ;

Diff for: jscomp/test/complex_if_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function escaped(s) {
9898
}
9999
}
100100
switch (exit) {
101-
case 1 :
101+
case /* Unknown */1 :
102102
s$prime[n] = /* "\\" */92;
103103
n = n + 1 | 0;
104104
s$prime[n] = 48 + (c / 100 | 0) | 0;
@@ -107,7 +107,7 @@ function escaped(s) {
107107
n = n + 1 | 0;
108108
s$prime[n] = 48 + c % 10 | 0;
109109
break;
110-
case 2 :
110+
case /* Unknown */2 :
111111
s$prime[n] = /* "\\" */92;
112112
n = n + 1 | 0;
113113
s$prime[n] = c;

Diff for: jscomp/test/ext_bytes_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function escaped(s) {
100100
}
101101
}
102102
switch (exit) {
103-
case 1 :
103+
case /* Unknown */1 :
104104
s$prime[n] = /* "\\" */92;
105105
n = n + 1 | 0;
106106
s$prime[n] = 48 + (c / 100 | 0) | 0;
@@ -109,7 +109,7 @@ function escaped(s) {
109109
n = n + 1 | 0;
110110
s$prime[n] = 48 + c % 10 | 0;
111111
break;
112-
case 2 :
112+
case /* Unknown */2 :
113113
s$prime[n] = /* "\\" */92;
114114
n = n + 1 | 0;
115115
s$prime[n] = c;

Diff for: jscomp/test/flow_parser_reg_test.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -1459,14 +1459,14 @@ function get_result_and_clear_state(param) {
14591459
}
14601460
}
14611461
switch (exit) {
1462-
case 1 :
1462+
case /* Unknown */1 :
14631463
var match$4 = lex_token[0];
14641464
match$1 = /* tuple */[
14651465
match$4[0],
14661466
match$4[2]
14671467
];
14681468
break;
1469-
case 2 :
1469+
case /* Unknown */2 :
14701470
match$1 = /* tuple */[
14711471
from_lb(env[/* lex_source */0], env[/* lex_lb */1]),
14721472
Lexing.lexeme(env[/* lex_lb */1])
@@ -6478,7 +6478,7 @@ function primary(env) {
64786478
}
64796479
}
64806480
switch (exit) {
6481-
case 1 :
6481+
case /* Unknown */1 :
64826482
var match$6 = primitive(token$5);
64836483
if (match$6 !== undefined) {
64846484
token$4(env, token$5);
@@ -6493,7 +6493,7 @@ function primary(env) {
64936493
/* Any */0
64946494
];
64956495
}
6496-
case 2 :
6496+
case /* Unknown */2 :
64976497
var raw$2 = Curry._2(Parser_env_Peek.value, undefined, env);
64986498
token$4(env, token$5);
64996499
var value$2 = token$5 === /* T_TRUE */29;
@@ -6655,7 +6655,7 @@ function function_param_list_without_parens(env) {
66556655
exit = 1;
66566656
}
66576657
switch (exit) {
6658-
case 1 :
6658+
case /* Unknown */1 :
66596659
var acc_000 = param(env$1);
66606660
var acc$1 = /* :: */[
66616661
acc_000,
@@ -6666,7 +6666,7 @@ function function_param_list_without_parens(env) {
66666666
}
66676667
_acc = acc$1;
66686668
continue ;
6669-
case 2 :
6669+
case /* Unknown */2 :
66706670
var rest = t === /* T_ELLIPSIS */11 ? (token$4(env$1, /* T_ELLIPSIS */11), param(env$1)) : undefined;
66716671
return /* tuple */[
66726672
rest,
@@ -7006,7 +7006,7 @@ function properties(allow_static, env, _param) {
70067006
exit = 1;
70077007
}
70087008
switch (exit) {
7009-
case 1 :
7009+
case /* Unknown */1 :
70107010
var match$1 = Curry._2(Parser_env_Peek.token, undefined, env);
70117011
var match$2;
70127012
var exit$1 = 0;
@@ -7057,13 +7057,13 @@ function properties(allow_static, env, _param) {
70577057
callProperties
70587058
];
70597059
continue ;
7060-
case 2 :
7060+
case /* Unknown */2 :
70617061
return /* tuple */[
70627062
List.rev(acc),
70637063
List.rev(indexers),
70647064
List.rev(callProperties)
70657065
];
7066-
case 3 :
7066+
case /* Unknown */3 :
70677067
var call_prop = call_property(env, start_loc, $$static);
70687068
semicolon$1(env);
70697069
_param = /* tuple */[
@@ -7383,7 +7383,7 @@ function param_list(env, _param) {
73837383
exit = 1;
73847384
}
73857385
switch (exit) {
7386-
case 1 :
7386+
case /* Unknown */1 :
73877387
var match = param$1(env);
73887388
var $$default = match[1];
73897389
var has_default$1 = has_default || $$default !== undefined;
@@ -7402,7 +7402,7 @@ function param_list(env, _param) {
74027402
has_default$1
74037403
];
74047404
continue ;
7405-
case 2 :
7405+
case /* Unknown */2 :
74067406
var rest = t === /* T_ELLIPSIS */11 ? (token$4(env, /* T_ELLIPSIS */11), Curry._2(Parse.identifier_with_type, env, /* StrictParamName */28)) : undefined;
74077407
if (Curry._2(Parser_env_Peek.token, undefined, env) !== /* T_RPAREN */4) {
74087408
error$1(env, /* ParameterAfterRestParameter */47);
@@ -8438,7 +8438,7 @@ function primary$1(env) {
84388438
}
84398439
}
84408440
switch (exit) {
8441-
case 1 :
8441+
case /* Unknown */1 :
84428442
if (Curry._2(Parser_env_Peek.is_identifier, undefined, env)) {
84438443
var id$1 = Curry._2(Parse.identifier, undefined, env);
84448444
return /* tuple */[
@@ -8458,7 +8458,7 @@ function primary$1(env) {
84588458
]])
84598459
];
84608460
}
8461-
case 2 :
8461+
case /* Unknown */2 :
84628462
var raw$4 = Curry._2(Parser_env_Peek.value, undefined, env);
84638463
token$4(env, token$5);
84648464
var value$4 = /* Boolean */Block.__(1, [token$5 === /* T_TRUE */29]);
@@ -9697,15 +9697,15 @@ function init(env, start_loc, key, async, generator) {
96979697
exit = 1;
96989698
}
96999699
switch (exit) {
9700-
case 1 :
9700+
case /* Unknown */1 :
97019701
token$4(env, /* T_COLON */77);
97029702
match$1 = /* tuple */[
97039703
Curry._1(Parse.assignment, env),
97049704
false,
97059705
false
97069706
];
97079707
break;
9708-
case 2 :
9708+
case /* Unknown */2 :
97099709
var tmp;
97109710
switch (key.tag | 0) {
97119711
case /* Literal */0 :
@@ -9733,7 +9733,7 @@ function init(env, start_loc, key, async, generator) {
97339733
false
97349734
];
97359735
break;
9736-
case 3 :
9736+
case /* Unknown */3 :
97379737
var typeParameters = Curry._1(type_parameter_declaration$1, env);
97389738
var match$2 = function_params(env);
97399739
var rest = match$2[2];
@@ -10108,7 +10108,7 @@ function class_element(env) {
1010810108
)
1010910109
) : 2;
1011010110
switch (exit) {
10111-
case 2 :
10111+
case /* Unknown */2 :
1011210112
var env$1 = env;
1011310113
var start_loc$1 = start_loc;
1011410114
var decorators$1 = decorators;
@@ -10125,7 +10125,7 @@ function class_element(env) {
1012510125
/* decorators */decorators$1
1012610126
]
1012710127
]]);
10128-
case 3 :
10128+
case /* Unknown */3 :
1012910129
return init$1(env, start_loc, decorators, key$1, async, generator$1, $$static);
1013010130

1013110131
}
@@ -10145,7 +10145,7 @@ function class_element(env) {
1014510145
)
1014610146
) : 2;
1014710147
switch (exit$1) {
10148-
case 2 :
10148+
case /* Unknown */2 :
1014910149
var env$2 = env;
1015010150
var start_loc$2 = start_loc;
1015110151
var decorators$2 = decorators;
@@ -10162,7 +10162,7 @@ function class_element(env) {
1016210162
/* decorators */decorators$2
1016310163
]
1016410164
]]);
10165-
case 3 :
10165+
case /* Unknown */3 :
1016610166
return init$1(env, start_loc, decorators, key$1, async, generator$1, $$static);
1016710167

1016810168
}
@@ -10899,7 +10899,7 @@ function declare_export_declaration($staropt$star, env) {
1089910899
exit = 1;
1090010900
}
1090110901
switch (exit) {
10902-
case 1 :
10902+
case /* Unknown */1 :
1090310903
var match$7 = Curry._2(Parser_env_Peek.token, undefined, env$1);
1090410904
if (typeof match$7 === "number") {
1090510905
if (match$7 !== 51) {
@@ -10934,7 +10934,7 @@ function declare_export_declaration($staropt$star, env) {
1093410934
/* source */source$2
1093510935
]])
1093610936
];
10937-
case 2 :
10937+
case /* Unknown */2 :
1093810938
var token$5 = Curry._2(Parser_env_Peek.token, undefined, env$1);
1093910939
var match$10;
1094010940
var exit$2 = 0;
@@ -10966,7 +10966,7 @@ function declare_export_declaration($staropt$star, env) {
1096610966
exit$2 = 3;
1096710967
}
1096810968
switch (exit$2) {
10969-
case 3 :
10969+
case /* Unknown */3 :
1097010970
throw [
1097110971
Caml_builtin_exceptions.assert_failure,
1097210972
/* tuple */[
@@ -10975,7 +10975,7 @@ function declare_export_declaration($staropt$star, env) {
1097510975
17
1097610976
]
1097710977
];
10978-
case 4 :
10978+
case /* Unknown */4 :
1097910979
if (typeof token$5 === "number") {
1098010980
if (token$5 !== 25) {
1098110981
if (token$5 !== 26) {
@@ -12480,7 +12480,7 @@ function module_item(env) {
1248012480
exit = 1;
1248112481
}
1248212482
switch (exit) {
12483-
case 1 :
12483+
case /* Unknown */1 :
1248412484
var match$8 = Curry._2(Parser_env_Peek.token, undefined, env$2);
1248512485
var exportKind = typeof match$8 === "number" && match$8 === 59 ? (token$3(env$2), /* ExportType */0) : /* ExportValue */1;
1248612486
token$4(env$2, /* T_LCURLY */1);
@@ -12506,7 +12506,7 @@ function module_item(env) {
1250612506
/* exportKind */exportKind
1250712507
]])
1250812508
];
12509-
case 2 :
12509+
case /* Unknown */2 :
1251012510
var stmt = Curry._2(Parse.statement_list_item, decorators$1, env$2);
1251112511
var match$11 = stmt[1];
1251212512
var loc$1 = stmt[0];

0 commit comments

Comments
 (0)