Skip to content

Commit 0c46274

Browse files
committed
Compiler: revove --write-shape flag
1 parent a3f5103 commit 0c46274

File tree

7 files changed

+28
-125
lines changed

7 files changed

+28
-125
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: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,7 @@ let output_gen
5555
if standalone then header ~custom_header fmt;
5656
if Config.Flag.header () then jsoo_header fmt build_info;
5757
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-
if false
64-
then
65-
Shape.Store.save'
66-
(Filename.remove_extension name ^ Shape.Store.ext)
67-
(StringMap.bindings shapes));
58+
StringMap.iter (fun name shape -> Shape.Store.set ~name shape) shapes;
6859
match source_map, sm with
6960
| None, _ | _, None -> ()
7061
| Some { output_file = output; source_map; keep_empty }, Some sm ->
@@ -172,7 +163,6 @@ let run
172163
; include_runtime
173164
; effects
174165
; shape_files
175-
; write_shape
176166
} =
177167
let source_map_base =
178168
Option.map ~f:(fun spec -> spec.Source_map.Encoding_spec.source_map) source_map
@@ -400,7 +390,7 @@ let run
400390
{ code; cmis = StringSet.empty; debug = Parse_bytecode.Debug.default_summary }
401391
in
402392
output_gen
403-
~write_shape
393+
~write_shape:false
404394
~standalone:true
405395
~custom_header
406396
~build_info:(Build_info.create `Runtime)
@@ -450,7 +440,7 @@ let run
450440
in
451441
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
452442
output_gen
453-
~write_shape
443+
~write_shape:false
454444
~standalone:true
455445
~custom_header
456446
~build_info:(Build_info.create `Exe)
@@ -490,7 +480,7 @@ let run
490480
in
491481
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
492482
output_gen
493-
~write_shape
483+
~write_shape:true
494484
~standalone:false
495485
~custom_header
496486
~build_info:(Build_info.create `Cmo)
@@ -525,7 +515,7 @@ let run
525515
failwith "use [-o dirname/] or remove [--keep-unit-names]"
526516
in
527517
output_gen
528-
~write_shape
518+
~write_shape:false
529519
~standalone:false
530520
~custom_header
531521
~build_info:(Build_info.create `Runtime)
@@ -562,7 +552,7 @@ let run
562552
t1
563553
(Ocaml_compiler.Cmo_format.name cmo);
564554
output_gen
565-
~write_shape
555+
~write_shape:true
566556
~standalone:false
567557
~custom_header
568558
~build_info:(Build_info.create `Cma)
@@ -614,7 +604,7 @@ let run
614604
, shapes )
615605
in
616606
output_gen
617-
~write_shape
607+
~write_shape:true
618608
~standalone:false
619609
~custom_header
620610
~build_info:(Build_info.create `Cma)

compiler/lib/driver.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,6 @@ let full ~shapes ~standalone ~wrap_with_fun ~profile ~link ~source_map ~formatte
710710
let shapes_v = optimized_code.shapes in
711711
StringMap.iter
712712
(fun name shape ->
713-
Shape.Store.set ~name shape;
714713
if shapes
715714
then
716715
Pretty_print.string

compiler/lib/parse_bytecode.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ module State = struct
585585
; globals : globals
586586
; immutable : unit Code.Var.Hashtbl.t
587587
; module_or_not : Ocaml_compiler.module_or_not Ident.Tbl.t
588-
; includes : string list
589588
}
590589

591590
let fresh_var state =
@@ -670,7 +669,7 @@ module State = struct
670669

671670
let pop_handler state = { state with handlers = List.tl state.handlers }
672671

673-
let initial includes g immutable =
672+
let initial g immutable =
674673
{ accu = Unset
675674
; stack = []
676675
; env = [||]
@@ -679,7 +678,6 @@ module State = struct
679678
; globals = g
680679
; immutable
681680
; module_or_not = Ident.Tbl.create 0
682-
; includes
683681
}
684682

685683
let rec print_stack f l =
@@ -829,7 +827,7 @@ let get_global state instrs i =
829827
(match g.named_value.(i) with
830828
| None -> ()
831829
| Some name -> (
832-
match Shape.Store.load ~name ~paths:state.includes with
830+
match Shape.Store.load ~name with
833831
| None -> ()
834832
| Some shape -> Shape.State.assign x shape));
835833
x, state, instrs
@@ -2548,9 +2546,9 @@ type one =
25482546
; debug : Debug.summary
25492547
}
25502548

2551-
let parse_bytecode ~includes code globals debug_data =
2549+
let parse_bytecode code globals debug_data =
25522550
let immutable = Code.Var.Hashtbl.create 0 in
2553-
let state = State.initial includes globals immutable in
2551+
let state = State.initial globals immutable in
25542552
Code.Var.reset ();
25552553
let blocks', joins = Blocks.analyse code in
25562554
Shape.State.reset ();
@@ -2730,7 +2728,7 @@ let from_exe
27302728
Ocaml_compiler.Symtable.GlobalMap.iter symbols ~f:(fun id n ->
27312729
globals.named_value.(n) <- Some (Ocaml_compiler.Symtable.Global.name id);
27322730
globals.is_exported.(n) <- true);
2733-
let p = parse_bytecode ~includes code globals debug_data in
2731+
let p = parse_bytecode code globals debug_data in
27342732
(* register predefined exception *)
27352733
let body =
27362734
List.fold_left predefined_exceptions ~init:[] ~f:(fun body (i, name) ->
@@ -2860,7 +2858,7 @@ let from_bytes ~prims ~debug (code : bytecode) =
28602858
t
28612859
in
28622860
let globals = make_globals 0 [||] prims in
2863-
let p = parse_bytecode ~includes:[] code globals debug_data in
2861+
let p = parse_bytecode code globals debug_data in
28642862
let gdata = Var.fresh_n "global_data" in
28652863
let need_gdata = ref false in
28662864
let find_name i =
@@ -2992,7 +2990,7 @@ module Reloc = struct
29922990
globals
29932991
end
29942992

2995-
let from_compilation_units ~includes ~include_cmis ~debug_data l =
2993+
let from_compilation_units ~includes:_ ~include_cmis ~debug_data l =
29962994
let reloc = Reloc.create () in
29972995
List.iter l ~f:(fun (compunit, code) -> Reloc.step1 reloc compunit code);
29982996
List.iter l ~f:(fun (compunit, code) -> Reloc.step2 reloc compunit code);
@@ -3001,7 +2999,7 @@ let from_compilation_units ~includes ~include_cmis ~debug_data l =
30012999
let l = List.map l ~f:(fun (_, c) -> Bytes.to_string c) in
30023000
String.concat ~sep:"" l
30033001
in
3004-
let prog = parse_bytecode ~includes code globals debug_data in
3002+
let prog = parse_bytecode code globals debug_data in
30053003
let gdata = Var.fresh_n "global_data" in
30063004
let need_gdata = ref false in
30073005
let body =

compiler/lib/shape.ml

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ type t =
2828
; res : t
2929
}
3030

31-
type shape = t
32-
3331
let rec equal a b =
3432
match a, b with
3533
| Top, Top -> true
@@ -127,89 +125,23 @@ let of_string (s : string) =
127125
parse_shape ()
128126

129127
module Store = struct
130-
let ext = ".jsoo-shape"
131-
132-
let filename ~dir ~name = Filename.concat dir (name ^ ext)
133-
134128
let t = String.Hashtbl.create 17
135129

136-
let loaded = String.Hashtbl.create 17
137-
138130
let set ~name shape = String.Hashtbl.replace t name shape
139131

140132
let get ~name = String.Hashtbl.find_opt t name
141133

142-
let magic = "JsooShape000"
143-
144134
let load' fn =
145-
let ic = open_in_bin fn in
146-
let m = really_input_string ic (String.length magic) in
147-
if String.equal m magic
148-
then (
149-
let shapes : (string * shape) list = Marshal.from_channel ic in
150-
close_in ic;
151-
List.iter shapes ~f:(fun (name, shape) -> set ~name shape))
152-
else (
153-
close_in ic;
154-
let l = file_lines_bin fn in
155-
List.iter l ~f:(fun s ->
156-
match String.drop_prefix ~prefix:"//#shape: " s with
157-
| None -> ()
158-
| Some name_n_shape -> (
159-
match String.lsplit2 name_n_shape ~on:':' with
160-
| None -> ()
161-
| Some (name, shape) -> set ~name (of_string shape))))
162-
163-
let load ~name ~paths =
164-
if String.Hashtbl.mem t name
165-
then get ~name
166-
else if not (Config.Flag.load_shapes_auto ())
167-
then None
168-
else
169-
match Fs.find_in_path paths (filename ~dir:"." ~name) with
170-
| Some f ->
171-
load' f;
172-
get ~name
173-
| None ->
174-
let rec scan : _ -> shape option = function
175-
| [] -> None
176-
| dir :: xs -> (
177-
let l =
178-
Sys.readdir dir
179-
|> Array.to_list
180-
|> List.sort ~cmp:String.compare
181-
|> List.map ~f:(fun n -> Filename.concat dir n)
182-
in
183-
match
184-
List.find_map l ~f:(fun s ->
185-
if Filename.check_suffix s ext && not (String.Hashtbl.mem loaded s)
186-
then (
187-
load' s;
188-
String.Hashtbl.add loaded s ();
189-
match get ~name with
190-
| None -> None
191-
| Some shape -> Some (s, shape))
192-
else None)
193-
with
194-
| None -> scan xs
195-
| Some (fn, shape) ->
196-
Format.eprintf "Shape: %s loaded from %s\n" name fn;
197-
Some shape)
198-
in
199-
scan paths
200-
201-
let save' fn (l : (string * shape) list) =
202-
let oc = open_out_bin fn in
203-
output_string oc magic;
204-
Marshal.to_channel oc l [];
205-
close_out oc
206-
207-
let save ~name ~dir =
208-
match get ~name with
209-
| None -> failwith (Printf.sprintf "Don't know any shape for %s" name)
210-
| Some shape ->
211-
let fn = filename ~dir ~name in
212-
save' fn [ name, shape ]
135+
let l = file_lines_bin fn in
136+
List.iter l ~f:(fun s ->
137+
match String.drop_prefix ~prefix:"//#shape: " s with
138+
| None -> ()
139+
| Some name_n_shape -> (
140+
match String.lsplit2 name_n_shape ~on:':' with
141+
| None -> ()
142+
| Some (name, shape) -> set ~name (of_string shape)))
143+
144+
let load ~name = if String.Hashtbl.mem t name then get ~name else None
213145
end
214146

215147
module State = struct

compiler/lib/shape.mli

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,13 @@ val equal : t -> t -> bool
3535
val merge : t -> t -> t
3636

3737
module Store : sig
38-
val ext : string
39-
4038
val set : name:string -> t -> unit
4139

4240
val get : name:string -> t option
4341

4442
val load' : string -> unit
4543

46-
val load : name:string -> paths:string list -> t option
47-
48-
val save : name:string -> dir:string -> unit
49-
50-
val save' : string -> (string * t) list -> unit
44+
val load : name:string -> t option
5145
end
5246

5347
module State : sig

0 commit comments

Comments
 (0)