Skip to content

Commit 8af5a57

Browse files
committed
add needed runtime support for check exists
TODO: coordination from bsb 1. Adding a flag instead of change existing behavior (-bs-checkcmj) 2. Restat on ninja for build cmj, build cmi alone does not need it
1 parent 9ecd79e commit 8af5a57

9 files changed

+160
-28
lines changed

jscomp/compiler.ninja

+4-4
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ build core/js_cmi_datasets.cmx : optc core/js_cmi_datasets.ml | ext/string_map.c
330330
build core/js_cmi_datasets.cmi : optc core/js_cmi_datasets.mli | ext/string_map.cmi
331331
build core/js_cmj_datasets.cmx : optc core/js_cmj_datasets.ml | ext/string_map.cmx core/js_cmj_format.cmx core/js_cmj_datasets.cmi
332332
build core/js_cmj_datasets.cmi : optc core/js_cmj_datasets.mli | ext/string_map.cmi core/js_cmj_format.cmi
333-
build core/js_cmj_format.cmx : optc core/js_cmj_format.ml | ext/string_map.cmx core/lam_arity.cmx core/lam.cmx core/js_packages_info.cmx ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_namespace.cmx core/js_cmj_format.cmi
333+
build core/js_cmj_format.cmx : optc core/js_cmj_format.ml | ext/string_map.cmx core/lam_constant.cmx core/lam_arity.cmx core/lam.cmx core/js_packages_info.cmx ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_namespace.cmx ext/ext_array.cmx core/js_cmj_format.cmi
334334
build core/js_cmj_format.cmi : optc core/js_cmj_format.mli | ext/string_map.cmi core/lam_arity.cmi core/lam.cmi core/js_packages_info.cmi ext/ext_namespace.cmi
335335
build core/js_cmj_load.cmx : optc core/js_cmj_load.ml | core/js_cmj_format.cmx core/config_util.cmx depends/bs_exception.cmx core/js_cmj_load.cmi
336336
build core/js_cmj_load.cmi : optc core/js_cmj_load.mli | core/js_cmj_format.cmi
@@ -388,7 +388,7 @@ build core/js_op_util.cmx : optc core/js_op_util.ml | core/js_op.cmx core/j.cmx
388388
build core/js_op_util.cmi : optc core/js_op_util.mli | core/js_op.cmx core/j.cmx
389389
build core/js_output.cmx : optc core/js_output.ml | core/lam_compile_context.cmx core/js_stmt_make.cmx core/js_exp_make.cmx core/js_dump.cmx core/js_analyzer.cmx core/j.cmx ext/ext_list.cmx core/js_output.cmi
390390
build core/js_output.cmi : optc core/js_output.mli | core/lam_compile_context.cmi core/j.cmx
391-
build core/js_packages_info.cmx : optc core/js_packages_info.ml | core/lam_module_ident.cmx ext/ext_sys.cmx ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_path.cmx ext/ext_namespace.cmx ext/ext_filename.cmx core/config_util.cmx depends/bs_exception.cmx core/js_packages_info.cmi
391+
build core/js_packages_info.cmx : optc core/js_packages_info.ml | core/lam_module_ident.cmx ext/ext_sys.cmx ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_path.cmx ext/ext_namespace.cmx ext/ext_list.cmx ext/ext_filename.cmx core/config_util.cmx depends/bs_exception.cmx core/js_packages_info.cmi
392392
build core/js_packages_info.cmi : optc core/js_packages_info.mli | core/lam_module_ident.cmi ext/ext_namespace.cmi
393393
build core/js_packages_state.cmx : optc core/js_packages_state.ml | core/js_packages_info.cmx ext/ext_pervasives.cmx ext/ext_namespace.cmx core/js_packages_state.cmi
394394
build core/js_packages_state.cmi : optc core/js_packages_state.mli | core/js_packages_info.cmi
@@ -411,7 +411,7 @@ build core/lam.cmx : optc core/lam.ml | core/lam_primitive.cmx core/lam_constant
411411
build core/lam.cmi : optc core/lam.mli | core/lam_primitive.cmi core/lam_constant.cmi core/lam_compat.cmi syntax/external_ffi_types.cmi syntax/external_arg_spec.cmi
412412
build core/lam_analysis.cmx : optc core/lam_analysis.ml | core/lam_constant.cmx core/lam.cmx ext/ext_list.cmx core/lam_analysis.cmi
413413
build core/lam_analysis.cmi : optc core/lam_analysis.mli | core/lam.cmi
414-
build core/lam_arity.cmx : optc core/lam_arity.ml | core/lam_arity.cmi
414+
build core/lam_arity.cmx : optc core/lam_arity.ml | ext/ext_list.cmx core/lam_arity.cmi
415415
build core/lam_arity.cmi : optc core/lam_arity.mli |
416416
build core/lam_arity_analysis.cmx : optc core/lam_arity_analysis.ml | core/lam_stats.cmx core/lam_compile_env.cmx core/lam_arity.cmx core/lam.cmx ext/ident_hashtbl.cmx ext/ext_list.cmx core/lam_arity_analysis.cmi
417417
build core/lam_arity_analysis.cmi : optc core/lam_arity_analysis.mli | core/lam_stats.cmi core/lam_arity.cmi core/lam.cmi
@@ -636,7 +636,7 @@ build ext/ext.cmxa : archive ext/ext_array.cmx ext/ext_bytes.cmx ext/ext_char.cm
636636
build common/common.cmxa : archive common/bs_loc.cmx common/bs_version.cmx common/js_config.cmx common/bs_warnings.cmx common/ext_log.cmx common/lam_methname.cmx common/ml_binary.cmx
637637
build syntax/syntax.cmxa : archive syntax/bs_syntaxerr.cmx syntax/bs_ast_iterator.cmx syntax/ast_utf8_string.cmx syntax/ast_compatible.cmx syntax/ast_utf8_string_interp.cmx syntax/ast_literal.cmx syntax/ast_comb.cmx syntax/ast_core_type.cmx syntax/bs_ast_invariant.cmx syntax/ast_payload.cmx syntax/ast_attributes.cmx syntax/bs_ast_mapper.cmx syntax/external_arg_spec.cmx syntax/external_ffi_types.cmx syntax/ast_polyvar.cmx syntax/external_process.cmx syntax/ast_pat.cmx syntax/ast_external_mk.cmx syntax/ast_exp.cmx syntax/ast_util.cmx syntax/ast_core_type_class_type.cmx syntax/ast_signature.cmx syntax/ast_structure.cmx syntax/ast_derive.cmx syntax/ast_derive_util.cmx syntax/ast_derive_abstract.cmx syntax/ast_derive_constructor.cmx syntax/ast_derive_dyn.cmx syntax/ast_derive_js_mapper.cmx syntax/ast_derive_projector.cmx syntax/ast_tuple_pattern_flatten.cmx syntax/ast_exp_apply.cmx syntax/ast_exp_extension.cmx syntax/ast_lift.cmx syntax/ast_primitive.cmx syntax/ast_tdcls.cmx syntax/ppx_entry.cmx
638638
build depends/depends.cmxa : archive depends/bs_exception.cmx depends/ast_extract.cmx depends/binary_ast.cmx
639-
build core/core.cmxa : archive core/bs_conditional_initial.cmx core/config_util.cmx core/config_whole_compiler.cmx core/lam_tag_info.cmx core/lam_compat.cmx core/js_op.cmx core/js_fun_env.cmx core/js_closure.cmx core/js_call_info.cmx core/j.cmx core/js_fold.cmx core/js_analyzer.cmx core/lam_pointer_info.cmx core/lam_compile_util.cmx core/js_runtime_modules.cmx core/js_op_util.cmx core/js_exp_make.cmx core/js_arr.cmx core/js_stmt_make.cmx core/js_ast_util.cmx core/js_cmi_datasets.cmx core/lam_arity.cmx core/primitive_compat.cmx core/lam_primitive.cmx core/lam_constant.cmx core/lam.cmx core/lam_module_ident.cmx core/js_packages_info.cmx core/js_cmj_format.cmx core/js_cmj_datasets.cmx core/js_cmj_load.cmx core/js_number.cmx core/js_fold_basic.cmx core/js_dump_string.cmx core/js_dump_lit.cmx core/js_dump_property.cmx core/js_dump.cmx core/js_dump_import_export.cmx core/ocaml_types.cmx core/lam_compile_env.cmx core/js_packages_state.cmx core/js_name_of_module_id.cmx core/js_dump_program.cmx core/ocaml_parse.cmx core/lam_id_kind.cmx core/lam_stats.cmx core/lam_print.cmx core/lam_hit.cmx core/lam_analysis.cmx core/lam_util.cmx core/lam_inline_util.cmx core/lam_var_stats.cmx core/lam_closure.cmx core/lam_arity_analysis.cmx core/lam_stats_export.cmx core/js_of_lam_module.cmx core/lam_compile_global.cmx core/lam_bounded_vars.cmx core/lam_beta_reduce_util.cmx core/lam_beta_reduce.cmx core/lam_pass_remove_alias.cmx core/lam_free_variables.cmx core/lam_pass_eliminate_ref.cmx core/lam_pass_count.cmx core/lam_pass_lets_dce.cmx core/lam_subst.cmx core/lam_exit_count.cmx core/lam_pass_exits.cmx core/lam_group.cmx core/lam_pass_deep_flatten.cmx core/lam_pass_collect.cmx core/lam_eta_conversion.cmx core/lam_pass_alpha_conversion.cmx core/lam_scc.cmx core/lam_convert.cmx core/lam_compile_context.cmx core/lam_iter.cmx core/lam_exit_code.cmx core/js_of_lam_tuple.cmx core/js_of_lam_exception.cmx core/js_of_lam_array.cmx core/js_long.cmx core/lam_dispatch_primitive.cmx core/js_of_lam_string.cmx core/js_of_lam_block.cmx core/lam_compile_const.cmx core/js_of_lam_polyvar.cmx core/js_of_lam_variant.cmx core/js_of_lam_option.cmx core/lam_compile_external_call.cmx core/js_of_lam_float_record.cmx core/lam_compile_primitive.cmx core/lam_compile_external_obj.cmx core/js_output.cmx core/js_of_lam_record.cmx core/lam_compile.cmx core/lam_dce.cmx core/lam_coercion.cmx core/lam_check.cmx core/js_shake.cmx core/js_map.cmx core/js_pass_tailcall_inline.cmx core/js_pass_scope.cmx core/js_pass_flatten_and_mark_dead.cmx core/js_pass_flatten.cmx core/js_pass_debug.cmx core/lam_compile_main.cmx core/js_implementation.cmx core/lam_group_pass.cmx core/ocaml_batch_compile.cmx core/ocaml_options.cmx
639+
build core/core.cmxa : archive core/bs_conditional_initial.cmx core/config_util.cmx core/config_whole_compiler.cmx core/lam_tag_info.cmx core/lam_compat.cmx core/js_op.cmx core/js_fun_env.cmx core/js_closure.cmx core/js_call_info.cmx core/j.cmx core/js_fold.cmx core/js_analyzer.cmx core/lam_pointer_info.cmx core/lam_compile_util.cmx core/js_runtime_modules.cmx core/js_op_util.cmx core/js_exp_make.cmx core/js_arr.cmx core/js_stmt_make.cmx core/js_ast_util.cmx core/js_cmi_datasets.cmx core/lam_constant.cmx core/lam_arity.cmx core/primitive_compat.cmx core/lam_primitive.cmx core/lam.cmx core/lam_module_ident.cmx core/js_packages_info.cmx core/js_cmj_format.cmx core/js_cmj_datasets.cmx core/js_cmj_load.cmx core/js_number.cmx core/js_fold_basic.cmx core/js_dump_string.cmx core/js_dump_lit.cmx core/js_dump_property.cmx core/js_dump.cmx core/js_dump_import_export.cmx core/ocaml_types.cmx core/lam_compile_env.cmx core/js_packages_state.cmx core/js_name_of_module_id.cmx core/js_dump_program.cmx core/ocaml_parse.cmx core/lam_id_kind.cmx core/lam_stats.cmx core/lam_print.cmx core/lam_hit.cmx core/lam_analysis.cmx core/lam_util.cmx core/lam_inline_util.cmx core/lam_var_stats.cmx core/lam_closure.cmx core/lam_arity_analysis.cmx core/lam_stats_export.cmx core/js_of_lam_module.cmx core/lam_compile_global.cmx core/lam_bounded_vars.cmx core/lam_beta_reduce_util.cmx core/lam_beta_reduce.cmx core/lam_pass_remove_alias.cmx core/lam_free_variables.cmx core/lam_pass_eliminate_ref.cmx core/lam_pass_count.cmx core/lam_pass_lets_dce.cmx core/lam_subst.cmx core/lam_exit_count.cmx core/lam_pass_exits.cmx core/lam_group.cmx core/lam_pass_deep_flatten.cmx core/lam_pass_collect.cmx core/lam_eta_conversion.cmx core/lam_pass_alpha_conversion.cmx core/lam_scc.cmx core/lam_convert.cmx core/lam_compile_context.cmx core/lam_iter.cmx core/lam_exit_code.cmx core/js_of_lam_tuple.cmx core/js_of_lam_exception.cmx core/js_of_lam_array.cmx core/js_long.cmx core/lam_dispatch_primitive.cmx core/js_of_lam_string.cmx core/js_of_lam_block.cmx core/lam_compile_const.cmx core/js_of_lam_polyvar.cmx core/js_of_lam_variant.cmx core/js_of_lam_option.cmx core/lam_compile_external_call.cmx core/js_of_lam_float_record.cmx core/lam_compile_primitive.cmx core/lam_compile_external_obj.cmx core/js_output.cmx core/js_of_lam_record.cmx core/lam_compile.cmx core/lam_dce.cmx core/lam_coercion.cmx core/lam_check.cmx core/js_shake.cmx core/js_map.cmx core/js_pass_tailcall_inline.cmx core/js_pass_scope.cmx core/js_pass_flatten_and_mark_dead.cmx core/js_pass_flatten.cmx core/js_pass_debug.cmx core/lam_compile_main.cmx core/js_implementation.cmx core/lam_group_pass.cmx core/ocaml_batch_compile.cmx core/ocaml_options.cmx
640640
build super_errors/super_errors.cmxa : archive super_errors/super_warnings.cmx super_errors/super_misc.cmx super_errors/super_location.cmx super_errors/super_env.cmx super_errors/super_typetexp.cmx super_errors/super_reason_react.cmx super_errors/super_typemod.cmx super_errors/super_typecore.cmx super_errors/super_pparse.cmx super_errors/super_main.cmx
641641
build outcome_printer/outcome_printer.cmxa : archive outcome_printer/outcome_printer_ns.cmx outcome_printer/reason_syntax_util.cmx outcome_printer/tweaked_reason_oprint.cmx outcome_printer/reason_outcome_printer_main.cmx
642642
build bsb/bsb.cmxa : archive bsb/bsb_build_schemas.cmx bsb/bsb_log.cmx bsb/bsb_exception.cmx bsb/bsb_pkg.cmx bsb/bsb_build_util.cmx bsb/bsb_unix.cmx bsb/bsb_dir_index.cmx bsb/bsb_db.cmx bsb/bsb_file_groups.cmx bsb/bsb_config.cmx bsb/bsb_parse_sources.cmx bsb/bsb_clean.cmx bsb/bsb_watcher_gen.cmx bsb/bsb_warning.cmx bsb/bsb_package_specs.cmx bsb/bsb_config_types.cmx bsb/bsb_default.cmx bsb/bsb_config_parse.cmx bsb/bsb_file.cmx bsb/bsb_helper_dep_graph.cmx bsb/bsb_helper_depfile_gen.cmx bsb/bsb_helper_extract.cmx bsb/bsb_helper_linker.cmx bsb/bsb_helper_packer.cmx bsb/bsb_merlin_gen.cmx bsb/bsb_namespace_map_gen.cmx bsb/bsb_ninja_check.cmx bsb/bsb_rule.cmx bsb/bsb_ninja_util.cmx bsb/bsb_ninja_global_vars.cmx bsb/bsb_ninja_file_groups.cmx bsb/bsb_ninja_gen.cmx bsb/bsb_ninja_regen.cmx bsb/bsb_query.cmx bsb/bsb_regex.cmx bsb/oCamlRes.cmx bsb/bsb_templates.cmx bsb/bsb_theme_init.cmx bsb/bsb_world.cmx

jscomp/core/js_cmj_format.ml

+48-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626

27-
27+
[@@@ocaml.warning "+9"]
2828

2929

3030
type arity =
@@ -96,10 +96,52 @@ let from_string s : t =
9696
"cmj files have incompatible versions, please rebuilt using the new compiler : %s"
9797
__LOC__
9898

99-
let to_file name (v : t) =
100-
let oc = open_out_bin name in
101-
output_string oc cmj_magic_number;
102-
output_value oc v;
103-
close_out oc
99+
let rec for_sure_not_changed (name : string) ({npm_package_path ; effect; cmj_case ; values} : t) =
100+
if Sys.file_exists name then
101+
let data = from_file name in
102+
Js_packages_info.equal data.npm_package_path npm_package_path &&
103+
for_sure_effect data.effect effect &&
104+
data.cmj_case = cmj_case &&
105+
for_sure_equal data.values values
106+
else false
107+
and for_sure_effect (x : string option) (y : string option) =
108+
match x, y with
109+
| None, None -> true
110+
| Some _, Some _ -> true (* we dont care about what effect it has when making use of cmj*)
111+
| None, Some _ -> false
112+
| Some _, None -> false
113+
and for_sure_equal valuesa valuesb =
114+
String_map.equal fore_sure_cmj_value valuesa valuesb
115+
and fore_sure_cmj_value (x : cmj_value) {arity; closed_lambda} =
116+
for_sure_arity x.arity arity &&
117+
for_sure_eq_optional_lambda x.closed_lambda closed_lambda
118+
and for_sure_arity (x : arity) y =
119+
match x, y with
120+
| Single x0, Single y0 -> Lam_arity.equal x0 y0
121+
| Submodule xs, Submodule ys ->
122+
Ext_array.for_all2_no_exn Lam_arity.equal xs ys
123+
| Single _, Submodule _ -> false
124+
| Submodule _, Single _ -> false
125+
and for_sure_eq_optional_lambda
126+
(lama : Lam.t option) lamb =
127+
match lama,lamb with
128+
| None, None -> true
129+
| None, Some _
130+
| Some _ , None -> false
131+
| Some a, Some b -> for_sure_lam a b
132+
and for_sure_lam (a : Lam.t) (b : Lam.t) =
133+
match a, b with
134+
| Lconst a0, Lconst b0 ->
135+
Lam_constant.eq_approx a0 b0
136+
| _, _ -> false
137+
(* This may cause some build system always rebuild
138+
maybe should not be turned on by default
139+
*)
140+
let to_file name ~check_exists (v : t) =
141+
if not (check_exists && for_sure_not_changed name v) then
142+
let oc = open_out_bin name in
143+
output_string oc cmj_magic_number;
144+
output_value oc v;
145+
close_out oc
104146

105147

jscomp/core/js_cmj_format.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,8 @@ val no_pure_dummy : t
8080
val from_file : string -> t
8181
val from_string : string -> t
8282

83-
val to_file : string -> t -> unit
83+
(* Note writing the file if its content is not chnaged
84+
*)
85+
val to_file :
86+
string -> check_exists:bool -> t -> unit
8487

jscomp/core/js_packages_info.ml

+11-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ type t =
5555
name : package_name ;
5656
module_systems: package_info list
5757
}
58+
[@@@ocaml.warning "+9"]
59+
let equal (x : t) ({name; module_systems}) =
60+
x.name = name &&
61+
Ext_list.for_all2_no_exn
62+
x.module_systems module_systems
63+
(fun (a0,a1) (b0,b1) -> a0 = b0 && a1 = b1)
64+
5865
(* we don't want force people to use package *)
5966

6067
(**
@@ -72,8 +79,8 @@ let from_name name =
7279
module_systems = []
7380
}
7481
let is_empty (x : t) =
75-
match x with
76-
| { name = "_" } -> true
82+
match x.name with
83+
| "_" -> true
7784
| _ -> false
7885

7986
let string_of_module_system (ms : module_system) =
@@ -143,9 +150,9 @@ let runtime_package_path =
143150

144151

145152
let get_js_path module_system
146-
({module_systems } : t ) =
153+
(x : t ) =
147154
match List.find (fun (k,_) ->
148-
compatible k module_system) module_systems with
155+
compatible k module_system) x.module_systems with
149156
| (_, path) -> path
150157
| exception _ -> assert false
151158

jscomp/core/js_packages_info.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ val dump_packages_info :
5353
val add_npm_package_path :
5454
string -> t -> t
5555

56-
56+
(** Note here we compare the package info by order
57+
in theory, we can compare it by set semantics
58+
*)
59+
val equal : t -> t -> bool
5760

5861
(**
5962
generate the mdoule path so that it can be spliced here:

jscomp/core/lam_arity.ml

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ type t =
3333
*)
3434
| Arity_na
3535

36+
let equal (x : t ) y =
37+
match x with
38+
| Arity_na -> y = Arity_na
39+
| Arity_info (xs,a) ->
40+
begin match y with
41+
| Arity_info (ys,b) ->
42+
a = b && Ext_list.for_all2_no_exn xs ys (fun x y -> x =y)
43+
| Arity_na -> false
44+
end
3645
let pp = Format.fprintf
3746

3847
let print (fmt : Format.formatter) (x : t) =

jscomp/core/lam_arity.mli

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type t = private
3333
*)
3434
| Arity_na
3535

36+
val equal : t -> t -> bool
3637
val print : Format.formatter -> t -> unit
3738

3839
val print_arities_tbl :

jscomp/core/lam_compile_main.ml

+1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ let compile ~filename (output_prefix : string) env _sigs
277277
in
278278
(if not @@ !Clflags.dont_write_files then
279279
Js_cmj_format.to_file
280+
~check_exists:false
280281
(output_prefix ^ Literals.suffix_cmj) v);
281282
{J.program = program ; side_effect = v.effect ; modules = external_module_ids }
282283
)

0 commit comments

Comments
 (0)