@@ -52,7 +52,13 @@ let output_gen ~standalone ~custom_header ~build_info ~source_map output_file f
5252 Driver. configure fmt;
5353 if standalone then header ~custom_header fmt;
5454 if Config.Flag. header () then jsoo_header fmt build_info;
55- let sm = f ~standalone ~source_map (k, fmt) in
55+ let sm, shapes = f ~standalone ~source_map (k, fmt) in
56+ (match output_file with
57+ | `Stdout -> ()
58+ | `Name name ->
59+ Shape.Store. save'
60+ (Filename. remove_extension name ^ Shape.Store. ext)
61+ (StringMap. bindings shapes));
5662 match source_map, sm with
5763 | No_sourcemap , _ | _ , None -> ()
5864 | ((Inline | File _ ) as output ), Some sm ->
@@ -70,7 +76,6 @@ let output_gen ~standalone ~custom_header ~build_info ~source_map output_file f
7076 Pretty_print. newline fmt;
7177 Pretty_print. string fmt (Printf. sprintf " //# sourceMappingURL=%s\n " urlData)
7278 in
73-
7479 match output_file with
7580 | `Stdout -> f stdout `Stdout
7681 | `Name name -> Filename. gen_file name (fun chan -> f chan `File )
@@ -130,6 +135,11 @@ let sourcemap_of_infos ~base l =
130135
131136let sourcemap_of_info ~base info = sourcemap_of_infos ~base [ info ]
132137
138+ let map_fst f (x , y ) = f x, y
139+
140+ let merge_shape a b =
141+ StringMap. union (fun _name s1 s2 -> if Shape. equal s1 s2 then Some s1 else None ) a b
142+
133143let run
134144 { Cmd_arg. common
135145 ; profile
@@ -153,6 +163,7 @@ let run
153163 ; export_file
154164 ; keep_unit_names
155165 ; include_runtime
166+ ; shape_files
156167 } =
157168 let source_map_base = Option. map ~f: snd source_map in
158169 let source_map =
@@ -172,6 +183,7 @@ let run
172183 | `Name _ , _ -> () );
173184 List. iter params ~f: (fun (s , v ) -> Config.Param. set s v);
174185 List. iter static_env ~f: (fun (s , v ) -> Eval. set_static_env s v);
186+ List. iter shape_files ~f: (fun fn -> Shape.Store. load' fn);
175187 let t = Timer. make () in
176188 let include_dirs =
177189 List. filter_map (include_dirs @ [ " +stdlib/" ]) ~f: (fun d -> Findlib. find [] d)
@@ -381,7 +393,7 @@ let run
381393 ~standalone
382394 ~link: `All
383395 output_file
384- |> sourcemap_of_info ~base: source_map_base)
396+ |> map_fst ( sourcemap_of_info ~base: source_map_base) )
385397 | (`Stdin | `File _ ) as bytecode ->
386398 let kind, ic, close_ic, include_dirs =
387399 match bytecode with
@@ -427,7 +439,7 @@ let run
427439 ~source_map
428440 ~link: (if linkall then `All else `Needed )
429441 output_file
430- |> sourcemap_of_info ~base: source_map_base)
442+ |> map_fst ( sourcemap_of_info ~base: source_map_base) )
431443 | `Cmo cmo ->
432444 let output_file =
433445 match output_file, keep_unit_names with
@@ -460,12 +472,13 @@ let run
460472 (fun ~standalone ~source_map output ->
461473 match include_runtime with
462474 | true ->
463- let sm1 = output_partial_runtime ~standalone ~source_map output in
464- let sm2 = output_partial cmo code ~standalone ~source_map output in
465- sourcemap_of_infos ~base: source_map_base [ sm1; sm2 ]
475+ let sm1, sh1 = output_partial_runtime ~standalone ~source_map output in
476+ let sm2, sh2 = output_partial cmo code ~standalone ~source_map output in
477+ ( sourcemap_of_infos ~base: source_map_base [ sm1; sm2 ]
478+ , merge_shape sh1 sh2 )
466479 | false ->
467480 output_partial cmo code ~standalone ~source_map output
468- |> sourcemap_of_info ~base: source_map_base)
481+ |> map_fst ( sourcemap_of_info ~base: source_map_base) )
469482 | `Cma cma when keep_unit_names ->
470483 (if include_runtime
471484 then
@@ -488,7 +501,7 @@ let run
488501 (`Name output_file)
489502 (fun ~standalone ~source_map output ->
490503 output_partial_runtime ~standalone ~source_map output
491- |> sourcemap_of_info ~base: source_map_base));
504+ |> map_fst ( sourcemap_of_info ~base: source_map_base) ));
492505 List. iter cma.lib_units ~f: (fun cmo ->
493506 let output_file =
494507 match output_file with
@@ -524,16 +537,16 @@ let run
524537 (`Name output_file)
525538 (fun ~standalone ~source_map output ->
526539 output_partial ~standalone ~source_map cmo code output
527- |> sourcemap_of_info ~base: source_map_base))
540+ |> map_fst ( sourcemap_of_info ~base: source_map_base) ))
528541 | `Cma cma ->
529542 let f ~standalone ~source_map output =
530- let source_map_runtime =
543+ let runtime =
531544 if not include_runtime
532545 then None
533546 else Some (output_partial_runtime ~standalone ~source_map output)
534547 in
535548
536- let source_map_units =
549+ let units =
537550 List. map cma.lib_units ~f: (fun cmo ->
538551 let t1 = Timer. make () in
539552 let code =
@@ -553,12 +566,17 @@ let run
553566 (Ocaml_compiler.Cmo_format. name cmo);
554567 output_partial ~standalone ~source_map cmo code output)
555568 in
556- let sm =
557- match source_map_runtime with
558- | None -> source_map_units
559- | Some x -> x :: source_map_units
569+ let sm_and_shapes =
570+ match runtime with
571+ | None -> units
572+ | Some x -> x :: units
573+ in
574+ let shapes =
575+ List. fold_left sm_and_shapes ~init: StringMap. empty ~f: (fun acc (_ , s ) ->
576+ merge_shape s acc)
560577 in
561- sourcemap_of_infos ~base: source_map_base sm
578+ ( sourcemap_of_infos ~base: source_map_base (List. map sm_and_shapes ~f: fst)
579+ , shapes )
562580 in
563581 output_gen
564582 ~standalone: false
0 commit comments