Skip to content

Commit 5c6c666

Browse files
committed
fix: punt on all the refactoring
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent 2d89b48 commit 5c6c666

File tree

12 files changed

+73
-54
lines changed

12 files changed

+73
-54
lines changed

src/dune_lang/lib_mode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module Cm_kind = struct
7171
end
7272

7373
let of_cm_kind : Cm_kind.t -> t = function
74-
| Ocaml (Cmi | Cmo | Cmt | Cmti) -> Ocaml Byte
74+
| Ocaml (Cmi | Cmo) -> Ocaml Byte
7575
| Ocaml Cmx -> Ocaml Native
7676
| Melange (Cmi | Cmj) -> Melange
7777
;;

src/dune_lang/pform.ml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,32 +219,60 @@ end
219219
module Artifact = struct
220220
open Ocaml
221221

222+
type mod_ =
223+
| Cm_kind of Ocaml.Cm_kind.t
224+
| Cmt
225+
| Cmti
226+
227+
let dyn_of_mod_ =
228+
let open Dyn in
229+
function
230+
| Cm_kind x -> Ocaml.Cm_kind.to_dyn x
231+
| Cmt -> variant "Cmt" []
232+
| Cmti -> variant "Cmti" []
233+
;;
234+
222235
type t =
223-
| Mod of Cm_kind.t
236+
| Mod of mod_
224237
| Lib of Mode.t
225238

239+
let compare_mod x y =
240+
match x, y with
241+
| Cm_kind x, Cm_kind y -> Ocaml.Cm_kind.compare x y
242+
| Cm_kind _, _ -> Lt
243+
| _, Cm_kind _ -> Gt
244+
| Cmt, Cmt -> Eq
245+
| Cmt, _ -> Lt
246+
| _, Cmt -> Gt
247+
| Cmti, Cmti -> Eq
248+
;;
249+
226250
let compare x y =
227251
match x, y with
228-
| Mod x, Mod y -> Cm_kind.compare x y
252+
| Mod x, Mod y -> compare_mod x y
229253
| Mod _, _ -> Lt
230254
| _, Mod _ -> Gt
231255
| Lib x, Lib y -> Mode.compare x y
232256
;;
233257

234258
let ext = function
235-
| Mod cm_kind -> Cm_kind.ext cm_kind
259+
| Mod Cmt -> ".cmt"
260+
| Mod Cmti -> ".cmti"
261+
| Mod (Cm_kind cm_kind) -> Cm_kind.ext cm_kind
236262
| Lib mode -> Mode.compiled_lib_ext mode
237263
;;
238264

239265
let all =
240-
List.map ~f:(fun kind -> Mod kind) Cm_kind.all
241-
@ List.map ~f:(fun mode -> Lib mode) Mode.all
266+
Mod Cmt
267+
:: Mod Cmti
268+
:: (List.map ~f:(fun kind -> Mod (Cm_kind kind)) Cm_kind.all
269+
@ List.map ~f:(fun mode -> Lib mode) Mode.all)
242270
;;
243271

244272
let to_dyn a =
245273
let open Dyn in
246274
match a with
247-
| Mod cm_kind -> variant "Mod" [ Cm_kind.to_dyn cm_kind ]
275+
| Mod cm_kind -> variant "Mod" [ dyn_of_mod_ cm_kind ]
248276
| Lib mode -> variant "Lib" [ Mode.to_dyn mode ]
249277
;;
250278
end

src/dune_lang/pform.mli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ module Var : sig
101101
end
102102

103103
module Artifact : sig
104+
type mod_ =
105+
| Cm_kind of Ocaml.Cm_kind.t
106+
| Cmt
107+
| Cmti
108+
104109
type t =
105-
| Mod of Ocaml.Cm_kind.t
110+
| Mod of mod_
106111
| Lib of Ocaml.Mode.t
107112

108113
val compare : t -> t -> Ordering.t

src/dune_rules/check_rules.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Import
22

33
let dev_files =
4-
[ Cm_kind.ext Cmt; Cm_kind.ext Cmti; Cm_kind.ext Cmi ]
4+
[ Ml_kind.cmt_ext Impl; Ml_kind.cmt_ext Intf; Cm_kind.ext Cmi ]
55
|> List.map ~f:(String.drop_prefix_if_exists ~prefix:".")
66
|> Glob.matching_extensions
77
;;

src/dune_rules/expander.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ let expand_artifact ~source t artifact arg =
191191
(match Artifacts_obj.lookup_module artifacts name with
192192
| None -> does_not_exist ~what:"Module" (Module_name.to_string name)
193193
| Some (t, m) ->
194-
(match Obj_dir.Module.cm_file t m ~kind:(Ocaml kind) with
194+
(match
195+
match kind with
196+
| Cm_kind kind -> Obj_dir.Module.cm_file t m ~kind:(Ocaml kind)
197+
| Cmt -> Obj_dir.Module.cmt_file t m ~cm_kind:(Ocaml Cmi) ~ml_kind:Impl
198+
| Cmti -> Some (Obj_dir.Module.cmti_file t m ~cm_kind:(Ocaml Cmi))
199+
with
195200
| None -> Action_builder.return [ Value.String "" ]
196201
| Some path -> dep (Path.build path)))
197202
| Lib mode ->

src/dune_rules/module_compilation.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let copy_interface ~sctx ~dir ~obj_dir ~cm_kind m =
6262

6363
let melange_args (cctx : Compilation_context.t) (cm_kind : Lib_mode.Cm_kind.t) module_ =
6464
match cm_kind with
65-
| Ocaml (Cmi | Cmo | Cmx | Cmt | Cmti) | Melange Cmi -> []
65+
| Ocaml (Cmi | Cmo | Cmx) | Melange Cmi -> []
6666
| Melange Cmj ->
6767
let melange_extension_version =
6868
let scope = Compilation_context.scope cctx in
@@ -188,15 +188,15 @@ let build_cm
188188
Command.Args.Hidden_targets
189189
[ Obj_dir.Module.cm_file_exn obj_dir m ~kind:cmi_kind ]
190190
| (Ocaml Cmo | Melange Cmj), None, true
191-
| (Ocaml (Cmo | Cmx | Cmt) | Melange Cmj), _, _ ->
191+
| (Ocaml (Cmo | Cmx) | Melange Cmj), _, _ ->
192192
Memo.return (force_read_cmi ~obj_dir ~version:ocaml.version ~cm_kind ~src m)
193-
| (Ocaml (Cmi | Cmti) | Melange Cmi), _, _ ->
193+
| (Ocaml Cmi | Melange Cmi), _, _ ->
194194
let+ () = copy_interface ~dir ~obj_dir ~sctx ~cm_kind m in
195195
Command.Args.empty))
196196
in
197197
let other_targets =
198198
match cm_kind with
199-
| Ocaml (Cmi | Cmo | Cmt | Cmti) | Melange (Cmi | Cmj) -> Command.Args.empty
199+
| Ocaml (Cmi | Cmo) | Melange (Cmi | Cmj) -> Command.Args.empty
200200
| Ocaml Cmx ->
201201
(match phase with
202202
| Some Compile ->
@@ -215,7 +215,6 @@ let build_cm
215215
let cmt_args =
216216
match cm_kind with
217217
| Ocaml Cmx -> Command.Args.empty
218-
| Ocaml (Cmt | Cmti) -> As [ "-bin-annot" ]
219218
| Ocaml (Cmi | Cmo) | Melange (Cmi | Cmj) ->
220219
if Compilation_context.bin_annot cctx
221220
then (

src/dune_rules/obj_dir.ml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module External = struct
9090
| Ocaml Cmi, Public, _ -> public_cmi_ocaml_dir t
9191
| Melange Cmi, Public, _ -> public_cmi_melange_dir t
9292
| Melange Cmj, _, _ -> t.melange_dir
93-
| Ocaml (Cmo | Cmx | Cmt | Cmti), _, _ -> t.public_dir
93+
| Ocaml (Cmo | Cmx), _, _ -> t.public_dir
9494
;;
9595

9696
let encode
@@ -165,7 +165,7 @@ module External = struct
165165
let cm_public_dir t (cm_kind : Lib_mode.Cm_kind.t) =
166166
match cm_kind with
167167
| Ocaml Cmx -> native_dir t
168-
| Ocaml (Cmo | Cmt | Cmti) -> byte_dir t
168+
| Ocaml Cmo -> byte_dir t
169169
| Ocaml Cmi -> public_cmi_ocaml_dir t
170170
| Melange Cmj -> melange_dir t
171171
| Melange Cmi -> public_cmi_melange_dir t
@@ -321,14 +321,14 @@ module Local = struct
321321
let cm_dir t (cm_kind : Lib_mode.Cm_kind.t) _ =
322322
match cm_kind with
323323
| Ocaml Cmx -> native_dir t
324-
| Ocaml (Cmo | Cmi | Cmt | Cmti) -> byte_dir t
324+
| Ocaml (Cmo | Cmi) -> byte_dir t
325325
| Melange (Cmj | Cmi) -> melange_dir t
326326
;;
327327

328328
let cm_public_dir t (cm_kind : Lib_mode.Cm_kind.t) =
329329
match cm_kind with
330330
| Ocaml Cmx -> native_dir t
331-
| Ocaml (Cmo | Cmt | Cmti) -> byte_dir t
331+
| Ocaml Cmo -> byte_dir t
332332
| Ocaml Cmi -> public_cmi_ocaml_dir t
333333
| Melange Cmj -> melange_dir t
334334
| Melange Cmi -> public_cmi_melange_dir t
@@ -513,8 +513,7 @@ module Module = struct
513513

514514
let has_impl_if_needed m ~(kind : Lib_mode.Cm_kind.t) =
515515
match kind with
516-
| Ocaml (Cmo | Cmx | Cmt) | Melange Cmj -> Module.has m ~ml_kind:Impl
517-
| Ocaml Cmti -> Module.has m ~ml_kind:Intf
516+
| Ocaml (Cmo | Cmx) | Melange Cmj -> Module.has m ~ml_kind:Impl
518517
| Ocaml Cmi | Melange Cmi -> true
519518
;;
520519

@@ -576,20 +575,17 @@ module Module = struct
576575

577576
let cmt_file t m ~(ml_kind : Ml_kind.t) ~cm_kind =
578577
let file = Module.file m ~ml_kind in
579-
let ext =
580-
match ml_kind with
581-
| Impl -> Cm_kind.ext Cmt
582-
| Intf -> Cm_kind.ext Cmti
583-
in
578+
let ext = Ml_kind.cmt_ext ml_kind in
584579
let cmi_kind = Lib_mode.Cm_kind.cmi cm_kind in
585580
Option.map file ~f:(fun _ -> obj_file t m ~kind:cmi_kind ~ext)
586581
;;
587582

588583
let cmti_file t m ~cm_kind =
589584
let ext =
590-
match Module.file m ~ml_kind:Intf with
591-
| None -> Cm_kind.ext Cmt
592-
| Some _ -> Cm_kind.ext Cmti
585+
Ml_kind.cmt_ext
586+
(match Module.file m ~ml_kind:Intf with
587+
| None -> Impl
588+
| Some _ -> Intf)
593589
in
594590
let cmi_kind = Lib_mode.Cm_kind.cmi cm_kind in
595591
obj_file t m ~kind:cmi_kind ~ext

src/ocaml/cm_kind.ml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ type t =
44
| Cmi
55
| Cmo
66
| Cmx
7-
| Cmt
8-
| Cmti
97

108
let compare x y : Ordering.t =
119
match x, y with
@@ -16,35 +14,25 @@ let compare x y : Ordering.t =
1614
| Cmo, _ -> Lt
1715
| _, Cmo -> Gt
1816
| Cmx, Cmx -> Eq
19-
| Cmx, _ -> Lt
20-
| _, Cmx -> Gt
21-
| Cmt, Cmt -> Eq
22-
| Cmt, _ -> Lt
23-
| _, Cmt -> Gt
24-
| Cmti, Cmti -> Eq
2517
;;
2618

27-
let all = [ Cmi; Cmo; Cmx; Cmt; Cmti ]
19+
let all = [ Cmi; Cmo; Cmx ]
2820

29-
let choose cmi cmo cmx cmt cmti = function
21+
let choose cmi cmo cmx = function
3022
| Cmi -> cmi
3123
| Cmo -> cmo
3224
| Cmx -> cmx
33-
| Cmt -> cmt
34-
| Cmti -> cmti
3525
;;
3626

37-
let ext = choose ".cmi" ".cmo" ".cmx" ".cmt" ".cmti"
38-
let source = choose Ml_kind.Intf Impl Impl Impl Intf
27+
let ext = choose ".cmi" ".cmo" ".cmx"
28+
let source = choose Ml_kind.Intf Impl Impl
3929

4030
let to_dyn =
4131
let open Dyn in
4232
function
4333
| Cmi -> variant "cmi" []
4434
| Cmo -> variant "cmo" []
4535
| Cmx -> variant "cmx" []
46-
| Cmt -> variant "cmt" []
47-
| Cmti -> variant "cmti" []
4836
;;
4937

5038
module Dict = struct
@@ -58,10 +46,6 @@ module Dict = struct
5846
| Cmi -> t.cmi
5947
| Cmo -> t.cmo
6048
| Cmx -> t.cmx
61-
| (Cmt | Cmti) as cm_kind ->
62-
Code_error.raise
63-
"Cm_kind.Dict.get doesnt support this case"
64-
[ "cm_kind", to_dyn cm_kind ]
6549
;;
6650

6751
let of_func f = { cmi = f ~cm_kind:Cmi; cmo = f ~cm_kind:Cmo; cmx = f ~cm_kind:Cmx }

src/ocaml/cm_kind.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ type t =
44
| Cmi
55
| Cmo
66
| Cmx
7-
| Cmt
8-
| Cmti
97

108
val compare : t -> t -> Ordering.t
119
val all : t list

src/ocaml/ml_kind.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ let choose t ~impl ~intf =
1515
let to_string = choose ~impl:"impl" ~intf:"intf"
1616
let to_dyn t = Dyn.String (to_string t)
1717

18+
let cmt_ext = function
19+
| Impl -> ".cmt"
20+
| Intf -> ".cmti"
21+
;;
22+
1823
module Dict = struct
1924
type 'a t =
2025
{ impl : 'a

0 commit comments

Comments
 (0)