@@ -52,7 +52,13 @@ let output_gen ~standalone ~custom_header ~build_info ~source_map output_file f
52
52
Driver. configure fmt;
53
53
if standalone then header ~custom_header fmt;
54
54
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));
56
62
match source_map, sm with
57
63
| No_sourcemap , _ | _ , None -> ()
58
64
| ((Inline | File _ ) as output ), Some sm ->
@@ -70,7 +76,6 @@ let output_gen ~standalone ~custom_header ~build_info ~source_map output_file f
70
76
Pretty_print. newline fmt;
71
77
Pretty_print. string fmt (Printf. sprintf " //# sourceMappingURL=%s\n " urlData)
72
78
in
73
-
74
79
match output_file with
75
80
| `Stdout -> f stdout `Stdout
76
81
| `Name name -> Filename. gen_file name (fun chan -> f chan `File )
@@ -130,6 +135,11 @@ let sourcemap_of_infos ~base l =
130
135
131
136
let sourcemap_of_info ~base info = sourcemap_of_infos ~base [ info ]
132
137
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
+
133
143
let run
134
144
{ Cmd_arg. common
135
145
; profile
@@ -153,6 +163,7 @@ let run
153
163
; export_file
154
164
; keep_unit_names
155
165
; include_runtime
166
+ ; shape_files
156
167
} =
157
168
let source_map_base = Option. map ~f: snd source_map in
158
169
let source_map =
@@ -172,6 +183,7 @@ let run
172
183
| `Name _ , _ -> () );
173
184
List. iter params ~f: (fun (s , v ) -> Config.Param. set s v);
174
185
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);
175
187
let t = Timer. make () in
176
188
let include_dirs =
177
189
List. filter_map (include_dirs @ [ " +stdlib/" ]) ~f: (fun d -> Findlib. find [] d)
@@ -381,7 +393,7 @@ let run
381
393
~standalone
382
394
~link: `All
383
395
output_file
384
- |> sourcemap_of_info ~base: source_map_base)
396
+ |> map_fst ( sourcemap_of_info ~base: source_map_base) )
385
397
| (`Stdin | `File _ ) as bytecode ->
386
398
let kind, ic, close_ic, include_dirs =
387
399
match bytecode with
@@ -427,7 +439,7 @@ let run
427
439
~source_map
428
440
~link: (if linkall then `All else `Needed )
429
441
output_file
430
- |> sourcemap_of_info ~base: source_map_base)
442
+ |> map_fst ( sourcemap_of_info ~base: source_map_base) )
431
443
| `Cmo cmo ->
432
444
let output_file =
433
445
match output_file, keep_unit_names with
@@ -460,12 +472,13 @@ let run
460
472
(fun ~standalone ~source_map output ->
461
473
match include_runtime with
462
474
| 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 )
466
479
| false ->
467
480
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) )
469
482
| `Cma cma when keep_unit_names ->
470
483
(if include_runtime
471
484
then
@@ -488,7 +501,7 @@ let run
488
501
(`Name output_file)
489
502
(fun ~standalone ~source_map output ->
490
503
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) ));
492
505
List. iter cma.lib_units ~f: (fun cmo ->
493
506
let output_file =
494
507
match output_file with
@@ -524,16 +537,16 @@ let run
524
537
(`Name output_file)
525
538
(fun ~standalone ~source_map output ->
526
539
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) ))
528
541
| `Cma cma ->
529
542
let f ~standalone ~source_map output =
530
- let source_map_runtime =
543
+ let runtime =
531
544
if not include_runtime
532
545
then None
533
546
else Some (output_partial_runtime ~standalone ~source_map output)
534
547
in
535
548
536
- let source_map_units =
549
+ let units =
537
550
List. map cma.lib_units ~f: (fun cmo ->
538
551
let t1 = Timer. make () in
539
552
let code =
@@ -553,12 +566,17 @@ let run
553
566
(Ocaml_compiler.Cmo_format. name cmo);
554
567
output_partial ~standalone ~source_map cmo code output)
555
568
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)
560
577
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 )
562
580
in
563
581
output_gen
564
582
~standalone: false
0 commit comments