Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions jscomp/all.depend
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ core/lam_compile_context.cmx : core/lam_stats.cmx core/lam.cmx core/j.cmx \
core/js_map.cmx : core/j.cmx
core/js_fold.cmx : core/j.cmx
core/js_fold_basic.cmx : core/lam_module_ident.cmx \
core/js_runtime_modules.cmx core/js_fold.cmx core/j.cmx ext/ident_set.cmx \
core/js_fold_basic.cmi
core/js_runtime_modules.cmx core/js_fold.cmx common/js_config.cmx \
core/j.cmx ext/ident_set.cmx core/js_fold_basic.cmi
core/js_pass_scope.cmx : core/js_fun_env.cmx core/js_fold.cmx \
core/js_closure.cmx ext/ident_set.cmx common/ext_log.cmx ext/ext_list.cmx \
core/js_pass_scope.cmi
Expand Down Expand Up @@ -595,9 +595,10 @@ core/js_dump_import_export.cmx : core/js_dump_string.cmx \
core/js_dump_import_export.cmi
core/js_dump.cmx : core/js_stmt_make.cmx core/js_runtime_modules.cmx \
core/js_op_util.cmx core/js_op.cmx core/js_number.cmx core/js_fun_env.cmx \
core/js_exp_make.cmx core/js_dump_string.cmx core/js_dump_property.cmx \
core/js_dump_lit.cmx core/js_closure.cmx core/j.cmx ext/ident_set.cmx \
ext/ext_pp_scope.cmx ext/ext_pp.cmx ext/ext_list.cmx ext/ext_ident.cmx \
core/js_fold_basic.cmx core/js_exp_make.cmx core/js_dump_string.cmx \
core/js_dump_property.cmx core/js_dump_lit.cmx common/js_config.cmx \
core/js_closure.cmx core/j.cmx ext/ident_set.cmx ext/ext_pp_scope.cmx \
ext/ext_pp.cmx ext/ext_list.cmx ext/ext_ident.cmx ext/ext_array.cmx \
core/js_dump.cmi
core/js_name_of_module_id.cmx : core/lam_compile_env.cmx \
core/js_packages_state.cmx core/js_packages_info.cmx \
Expand Down
8 changes: 8 additions & 0 deletions jscomp/bin/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ val range : int -> int -> int array

val map2i : (int -> 'a -> 'b -> 'c ) -> 'a array -> 'b array -> 'c array

val to_list_f : ('a -> 'b) -> 'a array -> 'b list
val to_list_map : ('a -> 'b option) -> 'a array -> 'b list

val to_list_map_acc :
Expand Down Expand Up @@ -1426,6 +1427,13 @@ let map2i f a b =
else
Array.mapi (fun i a -> f i a ( Array.unsafe_get b i )) a

let rec tolist_f_aux a f i res =
if i < 0 then res else
let v = Array.unsafe_get a i in
tolist_f_aux a f (i - 1)
(f v :: res)

let to_list_f f a = tolist_f_aux a f (Array.length a - 1) []

let rec tolist_aux a f i res =
if i < 0 then res else
Expand Down
4 changes: 3 additions & 1 deletion jscomp/common/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ let dump_js = ref false
let syntax_only = ref false
let binary_ast = ref false

let bs_suffix = ref false
let bs_suffix = ref false

let debug = ref false
1 change: 1 addition & 0 deletions jscomp/common/js_config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ val binary_ast : bool ref


val bs_suffix : bool ref
val debug : bool ref
69 changes: 55 additions & 14 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -798,25 +798,66 @@ and
->
(* Note that, if we ignore more than tag [0] we loose some information
with regard tag *)
begin match tag.expression_desc, tag_info with

| Number (Int { i = 0l ; _}) ,
(Blk_tuple | Blk_array | Blk_variant _ | Blk_record _ | Blk_na | Blk_module _
| Blk_constructor (_, 1) (* Sync up with {!Js_dump}*)
)
-> expression_desc cxt l f (Array (el, mutable_flag))
(* TODO: for numbers like 248, 255 we can reverse engineer to make it
[Obj.xx_flag], but we can not do this in runtime libraries
*)

| _, _
->
P.string f L.caml_block;
P.string f L.dot ;
P.string f L.caml_block_create;
P.paren_group f 1
(fun _ -> arguments cxt f [tag; E.array mutable_flag el])
end
if Js_fold_basic.needBlockRuntime tag tag_info then begin
match tag_info with
| Blk_record labels ->
P.string f L.caml_block;
P.string f L.dot ;
P.string f L.block_record;
P.paren_group f 1
(fun _ -> arguments cxt f
[E.array Immutable
(Ext_array.to_list_f E.str labels);
E.array mutable_flag
(List.map (fun (x : J.expression) -> {x with comment = None}) el) ]
)
| Blk_module (Some labels) ->
P.string f L.caml_block;
P.string f L.dot ;
P.string f L.block_local_module;
P.paren_group f 1
(fun _ -> arguments cxt f
[E.array Immutable
(Ext_list.map E.str labels);
E.array mutable_flag
(List.map (fun (x :J.expression) -> {x with comment = None}) el)
]
)
| Blk_variant name ->
P.string f L.caml_block;
P.string f L.dot ;
P.string f L.block_poly_var;
P.paren_group f 1
(fun _ -> arguments cxt f
[
E.str name;
E.array mutable_flag el]
)
| Blk_constructor(name,_) when !Js_config.debug ->
P.string f L.caml_block;
P.string f L.dot ;
P.string f L.block_variant;
P.paren_group f 1
(fun _ -> arguments cxt f
[E.str name; E.array mutable_flag el])

| _ ->
begin
P.string f L.caml_block;
P.string f L.dot ;
P.string f L.caml_block_create;
P.paren_group f 1
(fun _ -> arguments cxt f [tag; E.array mutable_flag el])
end
end
else
expression_desc cxt l f (Array (el, mutable_flag))

| Caml_block_tag e ->
P.group f 1 (fun _ ->
let cxt = expression 15 cxt f e in
Expand Down
5 changes: 5 additions & 0 deletions jscomp/core/js_dump_lit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ let plus_plus = "++"
let minus_minus = "--"
let caml_block = "Block"
let caml_block_create = "__"
let block_record = "record"
let block_local_module = "localModule"
let block_poly_var = "polyVar"
let block_variant = "variant"

let case = "case"
61 changes: 48 additions & 13 deletions jscomp/core/js_fold_basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,52 @@



let needBlockRuntimeInDebugMode
(tag : J.expression)
(tag_info : J.tag_info) =
match tag_info with
| Blk_variant _
| Blk_module _
| Blk_record _
| Blk_constructor _ -> true
| Blk_tuple
| Blk_array
| Blk_exception
| Blk_extension -> false
| Blk_na ->
begin match tag.expression_desc with
| Number (Int { i = 0l ; _})
->
false
| _ -> true
end

let needBlockRuntimeInReleaseMode (tag : J.expression) (tag_info : J.tag_info) =
match tag_info with
| Blk_module _
| Blk_record _
| Blk_constructor (_, 1)
| Blk_variant _
| Blk_na
| Blk_tuple
| Blk_array
->
begin match tag.expression_desc with
| Number (Int { i = 0l ; _})
->
false
| _ -> true
end
| Blk_constructor _ -> true
| Blk_exception
| Blk_extension -> false
(* converted to [Pcreate_extension] in the beginning*)




let needBlockRuntime tag info =
if !Js_config.debug then
needBlockRuntimeInDebugMode tag info
else needBlockRuntimeInReleaseMode tag info

class count_deps (add : Ident.t -> unit ) =
object(self)
Expand Down Expand Up @@ -76,18 +118,11 @@ class count_hard_dependencies =
super#expression x
| {expression_desc = Caml_block(_,_, tag, tag_info); _}
->
begin match tag.expression_desc, tag_info with
| Number (Int { i = 0l ; _}) ,
(Blk_tuple | Blk_array | Blk_variant _ | Blk_record _ | Blk_na | Blk_module _
| Blk_constructor (_, 1)
) (*Sync up with {!Js_dump}*)
-> ()
| _, _
->
add_lam_module_ident hard_dependencies
if needBlockRuntime tag tag_info then
add_lam_module_ident hard_dependencies
(Lam_module_ident.of_runtime
(Ident.create_persistent Js_runtime_modules.block));
end;
(Ident.create_persistent Js_runtime_modules.block))
;
super#expression x
| _ -> super#expression x
method get_hard_dependencies = hard_dependencies
Expand Down
5 changes: 4 additions & 1 deletion jscomp/core/js_fold_basic.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@




val needBlockRuntime :
J.expression ->
J.tag_info ->
bool

(** A module to calculate hard dependency based on JS IR in module [J] *)

Expand Down
5 changes: 5 additions & 0 deletions jscomp/core/js_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ let buckle_script_flags : (string * Arg.spec * string) list =
" (experimental) Set the string to be evaluated, note this flag will be conflicted with -bs-main"
)
::
("-bs-g",
Arg.Set Js_config.debug,
" debug mode"
)
::
(
"-bs-sort-imports",
Arg.Set Js_config.sort_imports,
Expand Down
7 changes: 7 additions & 0 deletions jscomp/ext/ext_array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ let map2i f a b =
else
Array.mapi (fun i a -> f i a ( Array.unsafe_get b i )) a

let rec tolist_f_aux a f i res =
if i < 0 then res else
let v = Array.unsafe_get a i in
tolist_f_aux a f (i - 1)
(f v :: res)

let to_list_f f a = tolist_f_aux a f (Array.length a - 1) []

let rec tolist_aux a f i res =
if i < 0 then res else
Expand Down
1 change: 1 addition & 0 deletions jscomp/ext/ext_array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ val range : int -> int -> int array

val map2i : (int -> 'a -> 'b -> 'c ) -> 'a array -> 'b array -> 'c array

val to_list_f : ('a -> 'b) -> 'a array -> 'b list
val to_list_map : ('a -> 'b option) -> 'a array -> 'b list

val to_list_map_acc :
Expand Down
1 change: 1 addition & 0 deletions jscomp/others/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ belt_HashMapInt.cmj : belt_internalBucketsType.cmj belt_internalBuckets.cmj \
belt_Array.cmj belt_HashMapInt.cmi
belt_HashMapString.cmj : belt_internalBucketsType.cmj \
belt_internalBuckets.cmj belt_Array.cmj belt_HashMapString.cmi
belt_Debug.cmj :
node_process.cmi : js_dict.cmi
js_re.cmi :
js_null_undefined.cmi :
Expand Down
1 change: 1 addition & 0 deletions jscomp/others/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
dom dom_storage\
belt_HashMapInt\
belt_HashMapString\
belt_Debug\

# belt_Bag\
# belt_BagM\
Expand Down
5 changes: 5 additions & 0 deletions jscomp/others/belt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,8 @@ module HashMap = Belt_HashMap
module Option = Belt_Option


(** {!Belt.Debug}

Utilities for set up debugging
*)
module Debug = Belt_Debug
Loading