From 27b460c32089bcc6a31061942f74e2cc8d633af1 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Mon, 6 Aug 2018 08:32:59 +0000 Subject: [PATCH] Use pattern matching when possible Signed-off-by: Etienne Millon --- src/exe.ml | 16 +++++++++------- src/gen_rules.ml | 5 +++-- src/jbuild.ml | 10 ++-------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/exe.ml b/src/exe.ml index bc23399a..a6085537 100644 --- a/src/exe.ml +++ b/src/exe.ml @@ -76,25 +76,27 @@ module Linkage = struct let flags = match m.kind with | Exe -> - if wanted_mode = Native && real_mode = Byte then - ["-custom"] - else - [] + begin + match wanted_mode, real_mode with + | Native, Byte -> ["-custom"] + | _ -> [] + end | Object -> o_flags | Shared_object -> let so_flags = - if ctx.os_type = "Win32" then + if String.equal ctx.os_type "Win32" then so_flags_windows else so_flags_unix in - if real_mode = Native then + match real_mode with + | Native -> (* The compiler doesn't pass these flags in native mode. This looks like a bug in the compiler. *) List.concat_map ctx.native_c_libraries ~f:(fun flag -> ["-cclib"; flag]) @ so_flags - else + | Byte -> so_flags in { ext diff --git a/src/gen_rules.ml b/src/gen_rules.ml index c4b434f5..caafa74a 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -487,9 +487,10 @@ module Gen(P : Install_rules.Params) = struct let l = let has_native = Option.is_some ctx.ocamlopt in List.filter_map (L.Set.to_list exes.modes) ~f:(fun (mode : L.t) -> - if not has_native && mode.mode = Native then + match has_native, mode.mode with + | false, Native -> None - else + | _ -> Some (Exe.Linkage.of_user_config ctx mode)) in (* If bytecode was requested but not native or best version, diff --git a/src/jbuild.ml b/src/jbuild.ml index 9ad3b66d..6a115aa3 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -870,15 +870,9 @@ module Mode_conf = struct let default = of_list [Byte; Best] let eval t ~has_native = - let best : Mode.t = - if has_native then - Native - else - Byte - in let has_best = mem t Best in - let byte = mem t Byte || (has_best && best = Byte) in - let native = best = Native && (mem t Native || has_best) in + let byte = mem t Byte || (has_best && (not has_native)) in + let native = has_native && (mem t Native || has_best) in { Mode.Dict.byte; native } end end