Skip to content

Commit fe821ec

Browse files
authored
Merge pull request #2107 from BuckleScript/bs_js
make Types.signature surface small, fix API and clean an old optimization
2 parents 507192c + 0127d63 commit fe821ec

11 files changed

+178
-197
lines changed

jscomp/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ CORE_SRCS= js_runtime_modules \
265265
config_util \
266266
js_packages_info\
267267
js_packages_state\
268-
type_int_to_string type_util ocaml_stdlib_slots bs_conditional_initial ocaml_options ocaml_parse\
268+
ocaml_types \
269+
ocaml_stdlib_slots \
270+
bs_conditional_initial \
271+
ocaml_options \
272+
ocaml_parse\
269273
js_op\
270274
lam_module_ident\
271275
lam_arity\

jscomp/all.depend

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ depends/binary_ast.cmx : common/ml_binary.cmx depends/ast_extract.cmx \
277277
core/config_util.cmi :
278278
core/js_packages_info.cmi : core/lam_module_ident.cmi
279279
core/js_packages_state.cmi : core/js_packages_info.cmi
280-
core/type_util.cmi :
280+
core/ocaml_types.cmi :
281281
core/bs_conditional_initial.cmi :
282282
core/ocaml_options.cmi :
283283
core/ocaml_parse.cmi :
@@ -338,8 +338,8 @@ core/js_of_lam_variant.cmi : core/j.cmx
338338
core/js_pass_flatten_and_mark_dead.cmi : core/j.cmx
339339
core/js_ast_util.cmi : core/j.cmx
340340
core/lam_dce.cmi : core/lam_group.cmi
341-
core/lam_compile_env.cmi : core/lam_module_ident.cmi core/lam.cmi \
342-
core/js_packages_info.cmi core/js_cmj_format.cmi
341+
core/lam_compile_env.cmi : core/ocaml_types.cmi core/lam_module_ident.cmi \
342+
core/lam.cmi core/js_packages_info.cmi core/js_cmj_format.cmi
343343
core/lam_stats_util.cmi : core/lam_stats.cmi core/lam_arity.cmi core/lam.cmi
344344
core/lam_stats_export.cmi : core/lam_stats.cmi core/lam_module_ident.cmi \
345345
core/lam.cmi core/js_cmj_format.cmi ext/ident_map.cmi
@@ -387,9 +387,8 @@ core/js_packages_info.cmx : core/lam_module_ident.cmx ext/ext_sys.cmx \
387387
depends/bs_exception.cmx core/js_packages_info.cmi
388388
core/js_packages_state.cmx : core/js_packages_info.cmx \
389389
ext/ext_pervasives.cmx ext/ext_namespace.cmx core/js_packages_state.cmi
390-
core/type_int_to_string.cmx :
391-
core/type_util.cmx : core/type_int_to_string.cmx common/ext_log.cmx \
392-
core/type_util.cmi
390+
core/ocaml_types.cmx : common/ext_log.cmx ext/ext_list.cmx \
391+
core/ocaml_types.cmi
393392
core/ocaml_stdlib_slots.cmx :
394393
core/bs_conditional_initial.cmx : common/bs_version.cmx \
395394
core/bs_conditional_initial.cmi
@@ -512,7 +511,7 @@ core/lam_dce.cmx : core/lam_group.cmx core/lam_analysis.cmx core/lam.cmx \
512511
ext/ext_pervasives.cmx ext/ext_list.cmx ext/ext_ident.cmx \
513512
core/lam_dce.cmi
514513
core/lam_group_pass.cmx : core/lam.cmx
515-
core/lam_compile_env.cmx : core/type_util.cmx ext/string_map.cmx \
514+
core/lam_compile_env.cmx : ext/string_map.cmx core/ocaml_types.cmx \
516515
ext/literals.cmx core/lam_module_ident.cmx core/lam.cmx \
517516
core/js_stmt_make.cmx core/js_exp_make.cmx common/js_config.cmx \
518517
core/js_cmj_load.cmx core/js_cmj_format.cmx ext/ext_string.cmx \
@@ -566,7 +565,7 @@ core/js_of_lam_option.cmx : core/js_runtime_modules.cmx core/js_exp_make.cmx \
566565
core/js_output.cmx : core/lam_compile_context.cmx core/lam_analysis.cmx \
567566
core/lam.cmx core/js_stmt_make.cmx core/js_exp_make.cmx core/js_dump.cmx \
568567
core/js_analyzer.cmx core/j.cmx ext/ext_list.cmx core/js_output.cmi
569-
core/lam_compile_global.cmx : core/type_util.cmx core/lam_module_ident.cmx \
568+
core/lam_compile_global.cmx : core/ocaml_types.cmx core/lam_module_ident.cmx \
570569
core/lam_compile_env.cmx core/lam.cmx core/js_stmt_make.cmx \
571570
core/js_output.cmx core/js_of_lam_module.cmx core/js_exp_make.cmx \
572571
core/j.cmx ext/ext_list.cmx core/lam_compile_global.cmi

jscomp/bin/whole_compiler.ml

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -83668,55 +83668,54 @@ let (+>) = Lam_module_ident.Hash.add cached_tbl
8366883668

8366983669
let cached_find_ml_id_pos id pos env : ident_info =
8367083670
let oid = Lam_module_ident.of_ml id in
83671-
begin match Lam_module_ident.Hash.find_opt cached_tbl oid with
83671+
match Lam_module_ident.Hash.find_opt cached_tbl oid with
83672+
| None ->
83673+
let cmj_path, cmj_table =
83674+
Js_cmj_load.find_cmj (id.name ^ Literals.suffix_cmj) in
83675+
begin match
83676+
Type_util.find_serializable_signatures_by_path id env with
8367283677
| None ->
83673-
let cmj_path, cmj_table =
83674-
Js_cmj_load.find_cmj (id.name ^ Literals.suffix_cmj) in
83675-
begin match
83676-
Type_util.find_serializable_signatures_by_path id env with
83677-
| None ->
83678-
assert false (*TODO: more informative error message *)
83679-
(* not_found id *)
83680-
| Some signature ->
83681-
oid +> Visit {signature = signature;
83682-
cmj_table ; cmj_path } ;
83683-
let name = (Type_util.get_name signature pos ) in
83684-
let arity, closed_lambda =
83685-
begin match String_map.find_opt name cmj_table.values with
83686-
| Some {arity ; closed_lambda} -> arity, closed_lambda
83687-
| None -> Js_cmj_format.single_na, None
83688-
end in
83689-
{id;
83690-
name ;
83691-
signature ;
83692-
arity ;
83693-
closed_lambda =
83694-
if Js_config.get_cross_module_inline () then
83695-
closed_lambda
83696-
else None
83697-
}
83698-
end
83699-
| Some (Visit {signature = serializable_sigs ; cmj_table = { values ; _} } ) ->
83700-
let name = (Type_util.get_name serializable_sigs pos ) in
83701-
let arity , closed_lambda = (
83702-
match String_map.find_opt name values with
83703-
| Some {arity; closed_lambda;_} ->
83704-
arity, closed_lambda
83705-
| None -> Js_cmj_format.single_na, None
83706-
) in
83707-
{ id;
83708-
name;
83709-
signature = serializable_sigs;
83710-
arity;
83711-
closed_lambda =
83712-
if Js_config.get_cross_module_inline () then
83713-
closed_lambda
83714-
else None
83715-
(* TODO shall we cache the arity ?*)
83716-
}
83717-
| Some (Runtime _) -> assert false
83718-
| Some External -> assert false
83719-
end
83678+
assert false (*TODO: more informative error message *)
83679+
| Some signature ->
83680+
oid +> Visit {signature; cmj_table ; cmj_path } ;
83681+
let name = Type_util.get_name signature pos in
83682+
let arity, closed_lambda =
83683+
match String_map.find_opt name cmj_table.values with
83684+
| Some {arity ; closed_lambda} -> arity, closed_lambda
83685+
| None -> Js_cmj_format.single_na, None
83686+
in
83687+
{id;
83688+
name ;
83689+
signature ;
83690+
arity ;
83691+
closed_lambda =
83692+
if Js_config.get_cross_module_inline () then
83693+
closed_lambda
83694+
else None
83695+
}
83696+
end
83697+
| Some (Visit {signature ; cmj_table = { values ; _} } )
83698+
->
83699+
let name = Type_util.get_name signature pos in
83700+
let arity , closed_lambda =
83701+
match String_map.find_opt name values with
83702+
| Some {arity; closed_lambda;_} ->
83703+
arity,
83704+
if Js_config.get_cross_module_inline () then
83705+
closed_lambda
83706+
else None
83707+
| None -> Js_cmj_format.single_na, None
83708+
in
83709+
{ id;
83710+
name;
83711+
signature;
83712+
arity;
83713+
closed_lambda
83714+
(* TODO shall we cache the arity ?*)
83715+
}
83716+
| Some (Runtime _) -> assert false
83717+
| Some External -> assert false
83718+
8372083719

8372183720

8372283721
type module_info = {

jscomp/core/lam_beta_reduce.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let propogate_beta_reduce
8686
(* It's not completeness, its to make it sound..
8787
Pass global module as an argument
8888
*)
89-
Lam_compile_global.query_lambda ident meta.env
89+
Lam_compile_global.expand_global_module_as_lam ident meta.env
9090
(* alias meta param ident (Module (Global ident)) Strict *)
9191
| Lprim {primitive = Pmakeblock (_, _, Immutable) ;args ; _} ->
9292
Ident_hashtbl.replace meta.ident_tbl param
@@ -145,7 +145,7 @@ let propogate_beta_reduce_with_map
145145
| Lglobal_module ident
146146
->
147147
(* It's not completeness, its to make it sound.. *)
148-
Lam_compile_global.query_lambda ident meta.env
148+
Lam_compile_global.expand_global_module_as_lam ident meta.env
149149
(* alias meta param ident (Module (Global ident)) Strict *)
150150
| Lprim {primitive = Pmakeblock (_, _, Immutable ) ; args} ->
151151
Ident_hashtbl.replace meta.ident_tbl param

jscomp/core/lam_compile_env.ml

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module S = Js_stmt_make
3535
type path = string
3636

3737
type ml_module_info = {
38-
signature : Types.signature ;
38+
signature : Ocaml_types.t;
3939
cmj_table : Js_cmj_format.t ;
4040
cmj_path : path;
4141
}
@@ -59,7 +59,7 @@ type env_value =
5959
type ident_info = {
6060
id : Ident.t;
6161
name : string;
62-
signature : Types.signature;
62+
signature : Ocaml_types.t;
6363
arity : Js_cmj_format.arity;
6464
closed_lambda : Lam.t option
6565
}
@@ -126,59 +126,58 @@ let (+>) = Lam_module_ident.Hash.add cached_tbl
126126

127127
let cached_find_ml_id_pos id pos env : ident_info =
128128
let oid = Lam_module_ident.of_ml id in
129-
begin match Lam_module_ident.Hash.find_opt cached_tbl oid with
129+
match Lam_module_ident.Hash.find_opt cached_tbl oid with
130+
| None ->
131+
let cmj_path, cmj_table =
132+
Js_cmj_load.find_cmj (id.name ^ Literals.suffix_cmj) in
133+
begin match
134+
Ocaml_types.find_serializable_signatures_by_path id env with
130135
| None ->
131-
let cmj_path, cmj_table =
132-
Js_cmj_load.find_cmj (id.name ^ Literals.suffix_cmj) in
133-
begin match
134-
Type_util.find_serializable_signatures_by_path id env with
135-
| None ->
136-
assert false (*TODO: more informative error message *)
137-
(* not_found id *)
138-
| Some signature ->
139-
oid +> Visit {signature = signature;
140-
cmj_table ; cmj_path } ;
141-
let name = (Type_util.get_name signature pos ) in
142-
let arity, closed_lambda =
143-
begin match String_map.find_opt name cmj_table.values with
144-
| Some {arity ; closed_lambda} -> arity, closed_lambda
145-
| None -> Js_cmj_format.single_na, None
146-
end in
147-
{id;
148-
name ;
149-
signature ;
150-
arity ;
151-
closed_lambda =
152-
if Js_config.get_cross_module_inline () then
153-
closed_lambda
154-
else None
155-
}
156-
end
157-
| Some (Visit {signature = serializable_sigs ; cmj_table = { values ; _} } ) ->
158-
let name = (Type_util.get_name serializable_sigs pos ) in
159-
let arity , closed_lambda = (
160-
match String_map.find_opt name values with
161-
| Some {arity; closed_lambda;_} ->
162-
arity, closed_lambda
163-
| None -> Js_cmj_format.single_na, None
164-
) in
165-
{ id;
166-
name;
167-
signature = serializable_sigs;
168-
arity;
169-
closed_lambda =
170-
if Js_config.get_cross_module_inline () then
171-
closed_lambda
172-
else None
173-
(* TODO shall we cache the arity ?*)
174-
}
175-
| Some (Runtime _) -> assert false
176-
| Some External -> assert false
177-
end
136+
assert false (*TODO: more informative error message *)
137+
| Some signature ->
138+
oid +> Visit {signature; cmj_table ; cmj_path } ;
139+
let name = Ocaml_types.get_name signature pos in
140+
let arity, closed_lambda =
141+
match String_map.find_opt name cmj_table.values with
142+
| Some {arity ; closed_lambda} -> arity, closed_lambda
143+
| None -> Js_cmj_format.single_na, None
144+
in
145+
{id;
146+
name ;
147+
signature ;
148+
arity ;
149+
closed_lambda =
150+
if Js_config.get_cross_module_inline () then
151+
closed_lambda
152+
else None
153+
}
154+
end
155+
| Some (Visit {signature ; cmj_table = { values ; _} } )
156+
->
157+
let name = Ocaml_types.get_name signature pos in
158+
let arity , closed_lambda =
159+
match String_map.find_opt name values with
160+
| Some {arity; closed_lambda;_} ->
161+
arity,
162+
if Js_config.get_cross_module_inline () then
163+
closed_lambda
164+
else None
165+
| None -> Js_cmj_format.single_na, None
166+
in
167+
{ id;
168+
name;
169+
signature;
170+
arity;
171+
closed_lambda
172+
(* TODO shall we cache the arity ?*)
173+
}
174+
| Some (Runtime _) -> assert false
175+
| Some External -> assert false
176+
178177

179178

180179
type module_info = {
181-
signature : Types.signature ;
180+
signature : Ocaml_types.t ;
182181
pure : bool
183182
}
184183
(* TODO: it does not make sense to cache
@@ -201,7 +200,7 @@ let query_and_add_if_not_exist (type u)
201200
oid +> Runtime (true,cmj_path,cmj_table) ;
202201
begin match env with
203202
| Has_env _ ->
204-
found {signature = []; pure = true}
203+
found {signature = Ocaml_types.empty; pure = true}
205204
| No_env ->
206205
found cmj_info
207206
end
@@ -212,7 +211,7 @@ let query_and_add_if_not_exist (type u)
212211
begin match env with
213212
| Has_env env ->
214213
begin match
215-
Type_util.find_serializable_signatures_by_path ( oid.id) env with
214+
Ocaml_types.find_serializable_signatures_by_path ( oid.id) env with
216215
| None -> not_found () (* actually when [not_found] in the call site, we throw... *)
217216
| Some signature ->
218217
oid +> Visit {signature = signature; cmj_table;cmj_path } ;
@@ -230,7 +229,7 @@ let query_and_add_if_not_exist (type u)
230229
begin match env with
231230
| Has_env _
232231
->
233-
found {signature = []; pure = false}
232+
found {signature = Ocaml_types.empty; pure = false}
234233
| No_env ->
235234
found (Ext_string.empty, Js_cmj_format.no_pure_dummy)
236235
(* FIXME: #154, it come from External, should be okay *)
@@ -247,14 +246,14 @@ let query_and_add_if_not_exist (type u)
247246
| Some (Runtime (pure, cmj_path,cmj_table)) ->
248247
begin match env with
249248
| Has_env _ ->
250-
found {signature = [] ; pure }
249+
found {signature = Ocaml_types.empty; pure }
251250
| No_env ->
252251
found (cmj_path, cmj_table)
253252
end
254253
| Some External ->
255254
begin match env with
256255
| Has_env _ ->
257-
found {signature = [] ; pure = false}
256+
found {signature = Ocaml_types.empty; pure = false}
258257
| No_env ->
259258
found (Ext_string.empty, Js_cmj_format.no_pure_dummy) (* External is okay *)
260259
end

jscomp/core/lam_compile_env.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type path = string
3838

3939

4040
type module_info = {
41-
signature : Types.signature ;
41+
signature : Ocaml_types.t ;
4242
pure : bool
4343
}
4444

@@ -50,7 +50,7 @@ type _ t =
5050
type ident_info = {
5151
id : Ident.t;
5252
name : string;
53-
signature : Types.signature;
53+
signature : Ocaml_types.t;
5454
arity : Js_cmj_format.arity;
5555
closed_lambda : Lam.t option
5656
}

0 commit comments

Comments
 (0)