Skip to content

Commit 0e031a1

Browse files
committed
split js_block_runtime
1 parent 0211d4d commit 0e031a1

File tree

5 files changed

+112
-64
lines changed

5 files changed

+112
-64
lines changed

jscomp/core/js_block_runtime.ml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(* Copyright (C) 2019- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
let tag_is_zero (tag : J.expression) =
27+
match tag.expression_desc with
28+
| Number (Int {i = 0l; _}) -> true
29+
| _ -> false;;
30+
31+
let needBlockRuntimeInDebugMode
32+
(tag : J.expression)
33+
(tag_info : J.tag_info) =
34+
match tag_info with
35+
| Blk_variant _
36+
| Blk_module _
37+
| Blk_record _
38+
| Blk_constructor _ -> true
39+
#if OCAML_VERSION =~ ">4.03.0" then
40+
| Blk_record_inlined _ -> true
41+
#end
42+
43+
| Blk_tuple
44+
| Blk_array
45+
#if OCAML_VERSION =~ ">4.03.0" then
46+
| Blk_record_ext _ -> false
47+
#end
48+
| Blk_extension_slot -> false
49+
| Blk_na -> not (tag_is_zero tag )
50+
51+
let needBlockRuntimeInReleaseMode (tag : J.expression) (tag_info : J.tag_info) =
52+
match tag_info with
53+
| Blk_variant _
54+
| Blk_module _
55+
| Blk_record _
56+
| Blk_tuple
57+
| Blk_array -> false
58+
#if OCAML_VERSION =~ ">4.03.0" then
59+
| Blk_record_inlined (_,_,1)
60+
#end
61+
| Blk_constructor (_, 1)
62+
| Blk_na -> not (tag_is_zero tag)
63+
#if OCAML_VERSION =~ ">4.03.0" then
64+
| Blk_record_inlined _
65+
#end
66+
| Blk_constructor _ -> true
67+
#if OCAML_VERSION =~ ">4.03.0" then
68+
| Blk_record_ext _
69+
#end
70+
| Blk_extension_slot -> false
71+
(* converted to [Pcreate_extension] in the beginning*)
72+
73+
74+
(* Used to decide whether we should add [require('block')]*)
75+
let needBlockRuntime tag info =
76+
if !Js_config.debug then
77+
needBlockRuntimeInDebugMode tag info
78+
else needBlockRuntimeInReleaseMode tag info

jscomp/core/js_block_runtime.mli

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(* Copyright (C) 2019- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
val tag_is_zero :
26+
J.expression -> bool
27+
28+
val needBlockRuntime:
29+
J.expression ->
30+
J.tag_info ->
31+
bool

jscomp/core/js_dump.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ and expression_desc cxt (level:int) f x : cxt =
860860
as an array, note exception or open variant it is outer-most is
861861
simply an array
862862
*)
863-
let needBlockRuntime = Js_fold_basic.needBlockRuntime tag tag_info in
863+
let needBlockRuntime = Js_block_runtime.needBlockRuntime tag tag_info in
864864
let is_debug = !Js_config.debug in
865865
if not needBlockRuntime then
866866
expression_desc cxt level f (Array (el, mutable_flag))
@@ -886,7 +886,7 @@ and expression_desc cxt (level:int) f x : cxt =
886886
P.paren_group f 1 (fun _ -> arguments cxt f [
887887
E.str name;
888888
E.array mutable_flag el])
889-
| Blk_constructor(name,number) when number = 1 && Js_fold_basic.tag_is_zero tag
889+
| Blk_constructor(name,number) when number = 1 && Js_block_runtime.tag_is_zero tag
890890
-> (* has to be debug mode *)
891891
pp_block_simple_variant f ;
892892
P.paren_group f 1 (fun _ -> arguments cxt f

jscomp/core/js_fold_basic.ml

+1-54
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,6 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
let tag_is_zero (tag : J.expression) =
27-
match tag.expression_desc with
28-
| Number (Int {i = 0l; _}) -> true
29-
| _ -> false;;
30-
31-
let needBlockRuntimeInDebugMode
32-
(tag : J.expression)
33-
(tag_info : J.tag_info) =
34-
match tag_info with
35-
| Blk_variant _
36-
| Blk_module _
37-
| Blk_record _
38-
| Blk_constructor _ -> true
39-
#if OCAML_VERSION =~ ">4.03.0" then
40-
| Blk_record_inlined _ -> true
41-
#end
42-
43-
| Blk_tuple
44-
| Blk_array
45-
#if OCAML_VERSION =~ ">4.03.0" then
46-
| Blk_record_ext _ -> false
47-
#end
48-
| Blk_extension_slot -> false
49-
| Blk_na -> not (tag_is_zero tag )
50-
51-
let needBlockRuntimeInReleaseMode (tag : J.expression) (tag_info : J.tag_info) =
52-
match tag_info with
53-
| Blk_variant _
54-
| Blk_module _
55-
| Blk_record _
56-
| Blk_tuple
57-
| Blk_array -> false
58-
#if OCAML_VERSION =~ ">4.03.0" then
59-
| Blk_record_inlined (_,_,1)
60-
#end
61-
| Blk_constructor (_, 1)
62-
| Blk_na -> not (tag_is_zero tag)
63-
#if OCAML_VERSION =~ ">4.03.0" then
64-
| Blk_record_inlined _
65-
#end
66-
| Blk_constructor _ -> true
67-
#if OCAML_VERSION =~ ">4.03.0" then
68-
| Blk_record_ext _
69-
#end
70-
| Blk_extension_slot -> false
71-
(* converted to [Pcreate_extension] in the beginning*)
72-
73-
74-
(* Used to decide whether we should add [require('block')]*)
75-
let needBlockRuntime tag info =
76-
if !Js_config.debug then
77-
needBlockRuntimeInDebugMode tag info
78-
else needBlockRuntimeInReleaseMode tag info
7926

8027
class count_deps (add : Ident.t -> unit ) =
8128
object(self)
@@ -123,7 +70,7 @@ class count_hard_dependencies =
12370
super#expression x
12471
| {expression_desc = Caml_block(_,_, tag, tag_info); _}
12572
->
126-
if needBlockRuntime tag tag_info then
73+
if Js_block_runtime.needBlockRuntime tag tag_info then
12774
add_lam_module_ident hard_dependencies
12875
(Lam_module_ident.of_runtime
12976
(Ident.create_persistent Js_runtime_modules.block))

jscomp/core/js_fold_basic.mli

-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525

2626

2727

28-
29-
val tag_is_zero : J.expression -> bool
30-
31-
val needBlockRuntime :
32-
J.expression ->
33-
J.tag_info ->
34-
bool
35-
3628
(** A module to calculate hard dependency based on JS IR in module [J] *)
3729

3830
val depends_j : J.expression -> Ident_set.t -> Ident_set.t

0 commit comments

Comments
 (0)