Skip to content

Commit d54416f

Browse files
committed
optimize assert false with the flag -bs-no-assertfalse, remove one unsafe primitive in Belt_List with this flag
1 parent c95c6b5 commit d54416f

15 files changed

+50
-45
lines changed

jscomp/core/lam.ml

+4
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,10 @@ let if_ (a : t) (b : t) (c : t) : t =
737737

738738
| _ ->
739739
match b, c with
740+
| _, Lconst (Const_pointer (_, Pt_assertfalse))
741+
-> seq a b (* TODO: we could customize more cases *)
742+
| Lconst (Const_pointer (_, Pt_assertfalse)), _
743+
-> seq a c
740744
| Lconst(Const_js_true), Lconst(Const_js_false)
741745
->
742746
if has_boolean_type a != None then a

jscomp/core/lam_compile_util.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,8 @@ let comment_of_pointer_info (x : Lam_pointer_info.t)=
6767
match x with
6868
| Pt_constructor {name;_}
6969
| Pt_variant {name} -> Some name
70-
(* | Pt_module_alias -> module_alias *)
70+
| Pt_assertfalse -> Some "assert_false"
7171
| Pt_na -> None
72+
| Pt_module_alias
73+
| Pt_builtin_boolean
74+
| Pt_shape_none -> assert false

jscomp/core/lam_constant_convert.ml

+9-8
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ let rec convert_constant ( const : Lambda.structured_constant) : Lam_constant.t
3838
| Const_base (Const_int32 i) -> (Const_int32 i)
3939
| Const_base (Const_int64 i) -> (Const_int64 i)
4040
| Const_base (Const_nativeint i) -> (Const_nativeint i)
41-
| Const_pointer(0, Pt_constructor{name = "()"; cstrs = 1,0})
41+
| Const_pointer(0, Pt_constructor{name = "()"; const = 1; non_const = 0})
4242
-> Const_js_undefined
4343
| Const_pointer(i,p) ->
4444
begin match p with
45-
| Pt_constructor {name;cstrs} -> Const_pointer(i, Pt_constructor {name; cstrs})
46-
| Pt_variant {name} -> Const_pointer(i,Pt_variant {name})
47-
| Pt_module_alias -> Const_module_alias
48-
| Pt_builtin_boolean -> if i = 0 then Const_js_false else Const_js_true
49-
| Pt_shape_none ->
50-
Lam_constant.lam_none
51-
| Pt_na -> Const_pointer(i, Pt_na)
45+
| Pt_module_alias -> Const_module_alias
46+
| Pt_builtin_boolean -> if i = 0 then Const_js_false else Const_js_true
47+
| Pt_shape_none ->
48+
Lam_constant.lam_none
49+
| Pt_assertfalse
50+
| Pt_constructor _
51+
| Pt_variant _
52+
| Pt_na -> Const_pointer(i, p)
5253
end
5354
| Const_float_array (s) -> Const_float_array(s)
5455
| Const_immstring s -> Const_immstring s

jscomp/core/lam_pointer_info.ml

+9-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
type t =
27-
| Pt_constructor of {name : string ; cstrs : int * int}
28-
| Pt_variant of {name : string }
29-
(* | Pt_module_alias *)
30-
| Pt_na
26+
type t = Lambda.pointer_info =
27+
| Pt_constructor of {name : string; const : int ; non_const : int}
28+
| Pt_variant of {name : string}
29+
| Pt_module_alias (* IMPOSSIBLE *)
30+
| Pt_builtin_boolean (* IMPOSSIBLE *)
31+
| Pt_shape_none (* IMPOSSIBLE *)
32+
| Pt_assertfalse
33+
| Pt_na
34+

jscomp/core/lam_pointer_info.mli

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

2525

26-
type t =
27-
| Pt_constructor of {name : string ; cstrs : int * int}
28-
| Pt_variant of { name : string}
29-
(* | Pt_module_alias *)
30-
| Pt_na
26+
type t = Lambda.pointer_info =
27+
| Pt_constructor of {name : string; const : int ; non_const : int}
28+
| Pt_variant of {name : string}
29+
| Pt_module_alias (* IMPOSSIBLE *)
30+
| Pt_builtin_boolean (* IMPOSSIBLE *)
31+
| Pt_shape_none (* IMPOSSIBLE *)
32+
| Pt_assertfalse
33+
| Pt_na

jscomp/others/belt_List.ml

+5-8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
]}
6060
*)
6161

62+
[@@@bs.config {flags = [| "-bs-noassertfalse" |]}]
63+
6264
type 'a t = 'a list
6365

6466
module A = Belt_Array
@@ -73,12 +75,7 @@ external mutableCell :
7375
*)
7476
external unsafeMutateTail :
7577
'a t -> 'a t -> unit = "#setfield1"
76-
(*
77-
- the cell is not empty
78-
- it is mutated
79-
*)
80-
external unsafeTail :
81-
'a t -> 'a t = "%field1"
78+
8279
(*
8380
- the cell is not empty
8481
*)
@@ -789,9 +786,9 @@ let partitionU l p =
789786
let b = p h [@bs] in
790787
partitionAux p t nextX nextY;
791788
if b then
792-
nextX, unsafeTail nextY
789+
nextX, (match nextY with _ :: tail -> tail | [] -> assert false)
793790
else
794-
unsafeTail nextX, nextY
791+
(match nextX with _ :: tail -> tail | [] -> assert false) , nextY
795792

796793
let partition l p = partitionU l (fun [@bs] x -> p x)
797794

jscomp/others/belt_internalMapInt.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# 4 "others/internal_map.cppo.ml"
1+
# 1 "others/internal_map.cppo.ml"
2+
[@@@bs.config {flags = [| "-bs-noassertfalse" |]}]
3+
# 5 "others/internal_map.cppo.ml"
24
type key = int
35

4-
# 9 "others/internal_map.cppo.ml"
6+
# 10 "others/internal_map.cppo.ml"
57
module N = Belt_internalAVLtree
68
module A = Belt_Array
79
module S = Belt_SortArray

jscomp/others/belt_internalMapString.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# 2 "others/internal_map.cppo.ml"
1+
# 1 "others/internal_map.cppo.ml"
2+
[@@@bs.config {flags = [| "-bs-noassertfalse" |]}]
3+
# 3 "others/internal_map.cppo.ml"
24
type key = string
35

4-
# 9 "others/internal_map.cppo.ml"
6+
# 10 "others/internal_map.cppo.ml"
57
module N = Belt_internalAVLtree
68
module A = Belt_Array
79
module S = Belt_SortArray

jscomp/others/internal_map.cppo.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[@@@bs.config {flags = [| "-bs-noassertfalse" |]}]
12
#ifdef TYPE_STRING
23
type key = string
34
#elif defined TYPE_INT

jscomp/others/release.ninja

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -bs-noassertfalse -open Bs_stdlib_mini -I ./runtime
2+
bsc_flags = -no-keep-locs -absname -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
33

44
rule cc
55
command = $bsc -bs-cmi -bs-cmj $bsc_flags -I others $in

lib/es6/belt_internalMapInt.js

-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ function mergeU(s1, s2, f) {
197197
} else if (s2 === undefined) {
198198
return ;
199199
}
200-
if (s2 === undefined) {
201-
return /* assert false */0;
202-
}
203200
var v2 = s2.key;
204201
var d2 = s2.value;
205202
var l2 = s2.left;

lib/es6/belt_internalMapString.js

-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ function mergeU(s1, s2, f) {
197197
} else if (s2 === undefined) {
198198
return ;
199199
}
200-
if (s2 === undefined) {
201-
return /* assert false */0;
202-
}
203200
var v2 = s2.key;
204201
var d2 = s2.value;
205202
var l2 = s2.left;

lib/js/belt_internalMapInt.js

-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ function mergeU(s1, s2, f) {
197197
} else if (s2 === undefined) {
198198
return ;
199199
}
200-
if (s2 === undefined) {
201-
return /* assert false */0;
202-
}
203200
var v2 = s2.key;
204201
var d2 = s2.value;
205202
var l2 = s2.left;

lib/js/belt_internalMapString.js

-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ function mergeU(s1, s2, f) {
197197
} else if (s2 === undefined) {
198198
return ;
199199
}
200-
if (s2 === undefined) {
201-
return /* assert false */0;
202-
}
203200
var v2 = s2.key;
204201
var d2 = s2.value;
205202
var l2 = s2.left;

scripts/ninja.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ async function othersNinja(devmode = true) {
973973
var ninjaCwd = "others";
974974

975975
var templateOthersRules = `
976-
bsc_flags = ${commonBsFlags} -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -bs-noassertfalse -open Bs_stdlib_mini -I ./runtime
976+
bsc_flags = ${commonBsFlags} -bs-cross-module-opt -bs-package-name bs-platform -bs-package-output commonjs:lib/js -bs-package-output es6:lib/es6 -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I ./runtime
977977
${ruleCC(ninjaCwd)}
978978
${
979979
devmode

0 commit comments

Comments
 (0)