Skip to content

Commit f7b1008

Browse files
committed
Compiler: remove --write-shape flag
1 parent 8d5addd commit f7b1008

File tree

9 files changed

+281
-384
lines changed

9 files changed

+281
-384
lines changed

compiler/bin-js_of_ocaml/cmd_arg.ml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ type t =
6565
; wrap_with_fun : [ `Iife | `Named of string | `Anonymous ]
6666
; target_env : Target_env.t
6767
; shape_files : string list
68-
; write_shape : bool
6968
; (* toplevel *)
7069
dynlink : bool
7170
; linkall : bool
@@ -120,10 +119,6 @@ let options =
120119
let doc = "load shape file [$(docv)]." in
121120
Arg.(value & opt_all string [] & info [ "load-shape" ] ~docv:"FILE" ~doc)
122121
in
123-
let write_shape =
124-
let doc = "Emit shape files" in
125-
Arg.(value & flag & info [ "write-shape" ] ~doc)
126-
in
127122
let input_file =
128123
let doc =
129124
"Compile the bytecode program [$(docv)]. "
@@ -328,8 +323,7 @@ let options =
328323
js_files
329324
keep_unit_names
330325
effects
331-
shape_files
332-
write_shape =
326+
shape_files =
333327
let inline_source_content = not sourcemap_don't_inline_content in
334328
let chop_extension s = try Filename.chop_extension s with Invalid_argument _ -> s in
335329
let runtime_files = js_files in
@@ -401,7 +395,6 @@ let options =
401395
; keep_unit_names
402396
; effects
403397
; shape_files
404-
; write_shape
405398
}
406399
in
407400
let t =
@@ -435,8 +428,7 @@ let options =
435428
$ js_files
436429
$ keep_unit_names
437430
$ effects
438-
$ shape_files
439-
$ write_shape)
431+
$ shape_files)
440432
in
441433
Term.ret t
442434

@@ -666,7 +658,6 @@ let options_runtime_only =
666658
; keep_unit_names = false
667659
; effects
668660
; shape_files = []
669-
; write_shape = false
670661
}
671662
in
672663
let t =

compiler/bin-js_of_ocaml/cmd_arg.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type t =
3838
]
3939
; target_env : Target_env.t
4040
; shape_files : string list
41-
; write_shape : bool
4241
; (* toplevel *)
4342
dynlink : bool
4443
; linkall : bool

compiler/bin-js_of_ocaml/compile.ml

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,7 @@ let output_gen
5454
Driver.configure fmt;
5555
if standalone then header ~custom_header fmt;
5656
if Config.Flag.header () then jsoo_header fmt build_info;
57-
let sm, shapes = f ~standalone ~shapes:write_shape ~source_map (k, fmt) in
58-
(if write_shape
59-
then
60-
match output_file with
61-
| `Stdout -> ()
62-
| `Name name ->
63-
Shape.Store.save'
64-
(Filename.remove_extension name ^ Shape.Store.ext)
65-
(StringMap.bindings shapes));
57+
let sm = f ~standalone ~shapes:write_shape ~source_map (k, fmt) in
6658
match source_map, sm with
6759
| None, _ | _, None -> ()
6860
| Some { output_file = output; source_map; keep_empty }, Some sm ->
@@ -140,11 +132,6 @@ let sourcemap_of_infos ~base l =
140132

141133
let sourcemap_of_info ~base info = sourcemap_of_infos ~base [ info ]
142134

143-
let map_fst f (x, y) = f x, y
144-
145-
let merge_shape a b =
146-
StringMap.union (fun _name s1 s2 -> if Shape.equal s1 s2 then Some s1 else None) a b
147-
148135
let run
149136
{ Cmd_arg.common
150137
; profile
@@ -170,7 +157,6 @@ let run
170157
; include_runtime
171158
; effects
172159
; shape_files
173-
; write_shape
174160
} =
175161
let source_map_base =
176162
Option.map ~f:(fun spec -> spec.Source_map.Encoding_spec.source_map) source_map
@@ -273,7 +259,7 @@ let run
273259
output_file =
274260
if check_sourcemap then check_debug one;
275261
let init_pseudo_fs = fs_external && standalone in
276-
let sm =
262+
let sm, shapes =
277263
match output_file with
278264
| `Stdout, formatter ->
279265
let instr =
@@ -326,6 +312,7 @@ let run
326312
Driver.f' ~standalone ~link:`Needed ?profile ~wrap_with_fun pfs_fmt code));
327313
res
328314
in
315+
StringMap.iter (fun name shape -> Shape.Store.set ~name shape) shapes;
329316
if times () then Format.eprintf "compilation: %a@." Timer.print t;
330317
sm
331318
in
@@ -398,7 +385,7 @@ let run
398385
{ code; cmis = StringSet.empty; debug = Parse_bytecode.Debug.default_summary }
399386
in
400387
output_gen
401-
~write_shape
388+
~write_shape:false
402389
~standalone:true
403390
~custom_header
404391
~build_info:(Build_info.create `Runtime)
@@ -415,7 +402,7 @@ let run
415402
~shapes
416403
~link:`All
417404
output_file
418-
|> map_fst (sourcemap_of_info ~base:source_map_base))
405+
|> sourcemap_of_info ~base:source_map_base)
419406
| (`Stdin | `File _) as bytecode ->
420407
let kind, ic, close_ic, include_dirs =
421408
match bytecode with
@@ -448,7 +435,7 @@ let run
448435
in
449436
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
450437
output_gen
451-
~write_shape
438+
~write_shape:false
452439
~standalone:true
453440
~custom_header
454441
~build_info:(Build_info.create `Exe)
@@ -463,7 +450,7 @@ let run
463450
~source_map
464451
~link:(if linkall then `All else `Needed)
465452
output_file
466-
|> map_fst (sourcemap_of_info ~base:source_map_base))
453+
|> sourcemap_of_info ~base:source_map_base)
467454
| `Cmo cmo ->
468455
let output_file =
469456
match output_file, keep_unit_names with
@@ -488,7 +475,7 @@ let run
488475
in
489476
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
490477
output_gen
491-
~write_shape
478+
~write_shape:true
492479
~standalone:false
493480
~custom_header
494481
~build_info:(Build_info.create `Cmo)
@@ -497,17 +484,16 @@ let run
497484
(fun ~standalone ~shapes ~source_map output ->
498485
match include_runtime with
499486
| true ->
500-
let sm1, sh1 =
487+
let sm1 =
501488
output_partial_runtime ~standalone ~shapes ~source_map output
502489
in
503-
let sm2, sh2 =
490+
let sm2 =
504491
output_partial cmo code ~standalone ~shapes ~source_map output
505492
in
506-
( sourcemap_of_infos ~base:source_map_base [ sm1; sm2 ]
507-
, merge_shape sh1 sh2 )
493+
sourcemap_of_infos ~base:source_map_base [ sm1; sm2 ]
508494
| false ->
509495
output_partial cmo code ~standalone ~shapes ~source_map output
510-
|> map_fst (sourcemap_of_info ~base:source_map_base))
496+
|> sourcemap_of_info ~base:source_map_base)
511497
| `Cma cma when keep_unit_names ->
512498
(if include_runtime
513499
then
@@ -523,15 +509,15 @@ let run
523509
failwith "use [-o dirname/] or remove [--keep-unit-names]"
524510
in
525511
output_gen
526-
~write_shape
512+
~write_shape:false
527513
~standalone:false
528514
~custom_header
529515
~build_info:(Build_info.create `Runtime)
530516
~source_map
531517
(`Name output_file)
532518
(fun ~standalone ~shapes ~source_map output ->
533519
output_partial_runtime ~standalone ~shapes ~source_map output
534-
|> map_fst (sourcemap_of_info ~base:source_map_base)));
520+
|> sourcemap_of_info ~base:source_map_base));
535521
List.iter cma.lib_units ~f:(fun cmo ->
536522
let output_file =
537523
match output_file with
@@ -560,15 +546,15 @@ let run
560546
t1
561547
(Ocaml_compiler.Cmo_format.name cmo);
562548
output_gen
563-
~write_shape
549+
~write_shape:true
564550
~standalone:false
565551
~custom_header
566552
~build_info:(Build_info.create `Cma)
567553
~source_map
568554
(`Name output_file)
569555
(fun ~standalone ~shapes ~source_map output ->
570556
output_partial ~standalone ~shapes ~source_map cmo code output
571-
|> map_fst (sourcemap_of_info ~base:source_map_base)))
557+
|> sourcemap_of_info ~base:source_map_base))
572558
| `Cma cma ->
573559
let f ~standalone ~shapes ~source_map output =
574560
(* Always compute shapes because it can be used by other units of the cma *)
@@ -599,20 +585,15 @@ let run
599585
(Ocaml_compiler.Cmo_format.name cmo);
600586
output_partial ~standalone ~shapes ~source_map cmo code output)
601587
in
602-
let sm_and_shapes =
588+
let sm =
603589
match runtime with
604590
| None -> units
605591
| Some x -> x :: units
606592
in
607-
let shapes =
608-
List.fold_left sm_and_shapes ~init:StringMap.empty ~f:(fun acc (_, s) ->
609-
merge_shape s acc)
610-
in
611-
( sourcemap_of_infos ~base:source_map_base (List.map sm_and_shapes ~f:fst)
612-
, shapes )
593+
sourcemap_of_infos ~base:source_map_base sm
613594
in
614595
output_gen
615-
~write_shape
596+
~write_shape:true
616597
~standalone:false
617598
~custom_header
618599
~build_info:(Build_info.create `Cma)

compiler/lib/driver.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ let full ~standalone ~wrap_with_fun ~shapes ~profile ~link ~source_map ~formatte
730730
let shapes_v = optimized_code.shapes in
731731
StringMap.iter
732732
(fun name shape ->
733-
Shape.Store.set ~name shape;
734733
if shapes
735734
then
736735
Pretty_print.string

compiler/lib/parse_bytecode.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ module State = struct
587587
; globals : globals
588588
; immutable : unit Code.Var.Hashtbl.t
589589
; module_or_not : Ocaml_compiler.module_or_not Ident.Tbl.t
590-
; includes : string list
591590
}
592591

593592
let fresh_var state =
@@ -672,7 +671,7 @@ module State = struct
672671

673672
let pop_handler state = { state with handlers = List.tl state.handlers }
674673

675-
let initial includes g immutable =
674+
let initial g immutable =
676675
{ accu = Unset
677676
; stack = []
678677
; env = [||]
@@ -681,7 +680,6 @@ module State = struct
681680
; globals = g
682681
; immutable
683682
; module_or_not = Ident.Tbl.create 0
684-
; includes
685683
}
686684

687685
let rec print_stack f l =
@@ -831,7 +829,7 @@ let get_global state instrs i =
831829
(match g.named_value.(i) with
832830
| None -> ()
833831
| Some name -> (
834-
match Shape.Store.load ~name ~paths:state.includes with
832+
match Shape.Store.load ~name with
835833
| None -> ()
836834
| Some shape -> Shape.State.assign x shape));
837835
x, state, instrs
@@ -2538,9 +2536,9 @@ type one =
25382536
; debug : Debug.summary
25392537
}
25402538

2541-
let parse_bytecode ~includes code globals debug_data =
2539+
let parse_bytecode code globals debug_data =
25422540
let immutable = Code.Var.Hashtbl.create 0 in
2543-
let state = State.initial includes globals immutable in
2541+
let state = State.initial globals immutable in
25442542
Code.Var.reset ();
25452543
let blocks', joins = Blocks.analyse code in
25462544
Shape.State.reset ();
@@ -2725,7 +2723,7 @@ let from_exe
27252723
Ocaml_compiler.Symtable.GlobalMap.iter symbols ~f:(fun id n ->
27262724
globals.named_value.(n) <- Some (Ocaml_compiler.Symtable.Global.name id);
27272725
globals.is_exported.(n) <- true);
2728-
let p = parse_bytecode ~includes code globals debug_data in
2726+
let p = parse_bytecode code globals debug_data in
27292727
(* register predefined exception *)
27302728
let body =
27312729
List.fold_left predefined_exceptions ~init:[] ~f:(fun body (i, name) ->
@@ -2855,7 +2853,7 @@ let from_bytes ~prims ~debug (code : bytecode) =
28552853
t
28562854
in
28572855
let globals = make_globals 0 [||] prims in
2858-
let p = parse_bytecode ~includes:[] code globals debug_data in
2856+
let p = parse_bytecode code globals debug_data in
28592857
let gdata = Var.fresh_n "global_data" in
28602858
let need_gdata = ref false in
28612859
let find_name i =
@@ -2987,7 +2985,7 @@ module Reloc = struct
29872985
globals
29882986
end
29892987

2990-
let from_compilation_units ~includes ~include_cmis ~debug_data l =
2988+
let from_compilation_units ~includes:_ ~include_cmis ~debug_data l =
29912989
let reloc = Reloc.create () in
29922990
List.iter l ~f:(fun (compunit, code) -> Reloc.step1 reloc compunit code);
29932991
List.iter l ~f:(fun (compunit, code) -> Reloc.step2 reloc compunit code);
@@ -2996,7 +2994,7 @@ let from_compilation_units ~includes ~include_cmis ~debug_data l =
29962994
let l = List.map l ~f:(fun (_, c) -> Bytes.to_string c) in
29972995
String.concat ~sep:"" l
29982996
in
2999-
let prog = parse_bytecode ~includes code globals debug_data in
2997+
let prog = parse_bytecode code globals debug_data in
30002998
let gdata = Var.fresh_n "global_data" in
30012999
let need_gdata = ref false in
30023000
let body =

0 commit comments

Comments
 (0)