Skip to content

Commit bb628ef

Browse files
committed
clean up, reverse exception inlining
1 parent cd9c2a1 commit bb628ef

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed

jscomp/bin/whole_compiler.ml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64529,7 +64529,7 @@ let not_ loc x : t =
6452964529

6453064530
let may_depend = Lam_module_ident.Hash_set.add
6453164531

64532-
(** drop Lseq (L)*)
64532+
(** drop Lseq (List! ) etc *)
6453364533
let rec drop_global_marker (lam : t) =
6453464534
match lam with
6453564535
| Lsequence(Lprim{primitive=Pgetglobal id; args = []}, rest) ->
@@ -64803,23 +64803,18 @@ let scc (groups : bindings) ( lam : t) ( body : t)
6480364803
type required_modules = Lam_module_ident.Hash_set.t
6480464804

6480564805

64806-
let convert exports lam =
64806+
let convert exports lam : _ * _ =
6480764807
let alias = Ident_hashtbl.create 64 in
6480864808
let may_depends = Lam_module_ident.Hash_set.create 0 in
6480964809
let rec
6481064810
aux (lam : Lambda.lambda) : t =
6481164811
match lam with
6481264812
| Lvar x ->
6481364813
let var = Ident_hashtbl.find_default alias x x in
64814-
if var == x then
64815-
Lvar var
64816-
else
64817-
if Ident.is_predef_exn var then
64818-
Lprim {primitive = Pglobal_exception var;args = []; loc= Location.none }
64819-
else if Ident.persistent var then
64814+
if Ident.persistent var then
6482064815
Lprim {primitive = Pgetglobal var; args = []; loc = Location.none}
64821-
else Lvar var
64822-
64816+
else
64817+
Lvar var
6482364818
| Lconst x ->
6482464819
Lconst x
6482564820
| Lapply (fn,args,loc)
@@ -64902,13 +64897,11 @@ let convert exports lam =
6490264897
if Ident_set.mem id exports then
6490364898
Llet(kind, id, Lvar new_u, aux body)
6490464899
else aux body
64905-
| _ , Lprim (Pgetglobal u,[], _)
64900+
| Alias , Lprim (Pgetglobal u,[], _) when not (Ident.is_predef_exn u)
6490664901
->
64907-
Ident_hashtbl.add alias id u;
64908-
if not @@ Ident.is_predef_exn u then
64909-
begin
64910-
may_depend may_depends (Lam_module_ident.of_ml u)
64911-
end;
64902+
Ident_hashtbl.add alias id u;
64903+
may_depend may_depends (Lam_module_ident.of_ml u);
64904+
6491264905
if Ident_set.mem id exports then
6491364906
Llet(kind, id, Lvar u, aux body)
6491464907
else aux body

jscomp/core/lam.ml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,23 +1363,18 @@ let scc (groups : bindings) ( lam : t) ( body : t)
13631363
type required_modules = Lam_module_ident.Hash_set.t
13641364

13651365

1366-
let convert exports lam =
1366+
let convert exports lam : _ * _ =
13671367
let alias = Ident_hashtbl.create 64 in
13681368
let may_depends = Lam_module_ident.Hash_set.create 0 in
13691369
let rec
13701370
aux (lam : Lambda.lambda) : t =
13711371
match lam with
13721372
| Lvar x ->
13731373
let var = Ident_hashtbl.find_default alias x x in
1374-
if var == x then
1375-
Lvar var
1376-
else
1377-
if Ident.is_predef_exn var then
1378-
Lprim {primitive = Pglobal_exception var;args = []; loc= Location.none }
1379-
else if Ident.persistent var then
1374+
if Ident.persistent var then
13801375
Lprim {primitive = Pgetglobal var; args = []; loc = Location.none}
1381-
else Lvar var
1382-
1376+
else
1377+
Lvar var
13831378
| Lconst x ->
13841379
Lconst x
13851380
| Lapply (fn,args,loc)
@@ -1462,13 +1457,11 @@ let convert exports lam =
14621457
if Ident_set.mem id exports then
14631458
Llet(kind, id, Lvar new_u, aux body)
14641459
else aux body
1465-
| _ , Lprim (Pgetglobal u,[], _)
1460+
| Alias , Lprim (Pgetglobal u,[], _) when not (Ident.is_predef_exn u)
14661461
->
1467-
Ident_hashtbl.add alias id u;
1468-
if not @@ Ident.is_predef_exn u then
1469-
begin
1470-
may_depend may_depends (Lam_module_ident.of_ml u)
1471-
end;
1462+
Ident_hashtbl.add alias id u;
1463+
may_depend may_depends (Lam_module_ident.of_ml u);
1464+
14721465
if Ident_set.mem id exports then
14731466
Llet(kind, id, Lvar u, aux body)
14741467
else aux body

jscomp/test/exception_alias.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions");
44
var List = require("../../lib/js/list");
55

6+
var a0 = Caml_builtin_exceptions.not_found;
7+
68
var b = List.length(/* :: */[
79
1,
810
/* :: */[
@@ -59,17 +61,15 @@ var List$1 = /* module */[
5961
/* length */3
6062
];
6163

62-
var a0 = Caml_builtin_exceptions.not_found;
63-
64-
var a1 = Caml_builtin_exceptions.not_found;
64+
var a1 = a0;
6565

66-
var a2 = Caml_builtin_exceptions.not_found;
66+
var a2 = a0;
6767

68-
var a3 = Caml_builtin_exceptions.not_found;
68+
var a3 = a0;
6969

70-
var a4 = Caml_builtin_exceptions.not_found;
70+
var a4 = a0;
7171

72-
var a5 = Caml_builtin_exceptions.not_found;
72+
var a5 = a0;
7373

7474
exports.a0 = a0;
7575
exports.a1 = a1;

jscomp/test/global_exception_regression_test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ var Block = require("../../lib/js/block");
44
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions");
55
var Mt = require("./mt");
66

7+
var v = Caml_builtin_exceptions.not_found;
8+
9+
var u = Caml_builtin_exceptions.not_found;
10+
11+
var s = Caml_builtin_exceptions.end_of_file;
12+
713
var suites_000 = /* tuple */[
814
"not_found_equal",
915
function () {
1016
return /* Eq */Block.__(0, [
11-
Caml_builtin_exceptions.not_found,
12-
Caml_builtin_exceptions.not_found
17+
u,
18+
v
1319
]);
1420
}
1521
];
@@ -19,8 +25,8 @@ var suites_001 = /* :: */[
1925
"not_found_not_equal_end_of_file",
2026
function () {
2127
return /* Neq */Block.__(1, [
22-
Caml_builtin_exceptions.not_found,
23-
Caml_builtin_exceptions.end_of_file
28+
u,
29+
s
2430
]);
2531
}
2632
],
@@ -34,12 +40,6 @@ var suites = /* :: */[
3440

3541
Mt.from_pair_suites("global_exception_regression_test.ml", suites);
3642

37-
var v = Caml_builtin_exceptions.not_found;
38-
39-
var u = Caml_builtin_exceptions.not_found;
40-
41-
var s = Caml_builtin_exceptions.end_of_file;
42-
4343
exports.v = v;
4444
exports.u = u;
4545
exports.s = s;

0 commit comments

Comments
 (0)