diff --git a/src/action_exec.ml b/src/action_exec.ml index 07ce145ade6..da671ed3d41 100644 --- a/src/action_exec.ml +++ b/src/action_exec.ml @@ -182,9 +182,11 @@ and exec_list l ~ectx ~dir ~env ~stdout_to ~stderr_to = | [t] -> exec t ~ectx ~dir ~env ~stdout_to ~stderr_to | t :: rest -> - (let stdout_to = Process.Output.multi_use stdout_to in - let stderr_to = Process.Output.multi_use stderr_to in - exec t ~ectx ~dir ~env ~stdout_to ~stderr_to) >>= fun () -> + let* () = + let stdout_to = Process.Output.multi_use stdout_to in + let stderr_to = Process.Output.multi_use stderr_to in + exec t ~ectx ~dir ~env ~stdout_to ~stderr_to + in exec_list rest ~ectx ~dir ~env ~stdout_to ~stderr_to let exec ~targets ~context ~env t = diff --git a/src/context.ml b/src/context.ml index 72d64a8ce06..19b33169561 100644 --- a/src/context.ml +++ b/src/context.ml @@ -247,8 +247,8 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets in let get_tool_using_findlib_config prog = let open Option.O in - findlib_config >>= fun conf -> - Findlib.Config.get conf prog >>= fun s -> + let* conf = findlib_config in + let* s = Findlib.Config.get conf prog in match Filename.analyze_program_name s with | In_path | Relative_to_current_dir -> which s | Absolute -> Some (Path.of_filename_relative_to_initial_cwd s) @@ -559,8 +559,7 @@ let create_for_opam ~root ~env ~env_nodes ~targets ~profile | None -> Utils.program_not_found "opam" ~loc:None | Some fn -> fn in - opam_version opam env - >>= fun version -> + let* version = opam_version opam env in let args = List.concat [ [ "config"; "env" ] @@ -571,8 +570,7 @@ let create_for_opam ~root ~env ~env_nodes ~targets ~profile ; if version < (2, 0, 0) then [] else ["--set-switch"] ] in - Process.run_capture ~env Strict opam args - >>= fun s -> + let* s = Process.run_capture ~env Strict opam args in let vars = Dune_lang.parse_string ~fname:"" ~mode:Single s |> Dune_lang.Decoder.(parse (list (pair string string)) Univ_map.empty) diff --git a/src/dune_file.ml b/src/dune_file.ml index c3dcb361980..5723f3dafc2 100644 --- a/src/dune_file.ml +++ b/src/dune_file.ml @@ -52,7 +52,7 @@ let relative_file = let variants_field = field_o "variants" ( - Syntax.since Stanza.syntax (1, 9) >>= fun () -> + let* () = Syntax.since Stanza.syntax (1, 9) in located (list Variant.decode >>| Variant.Set.of_list)) (* Parse and resolve "package" fields *) @@ -904,30 +904,30 @@ module Library = struct and+ no_keep_locs = field_b "no_keep_locs" ~check:(Syntax.deprecated_in Stanza.syntax (1, 7)) and+ sub_systems = - return () >>= fun () -> + let* () = return () in Sub_system_info.record_parser () and+ project = Dune_project.get_exn () and+ dune_version = Syntax.get_exn Stanza.syntax and+ virtual_modules = field_o "virtual_modules" ( - Syntax.since Stanza.syntax (1, 7) - >>= fun () -> Ordered_set_lang.decode) + Syntax.since Stanza.syntax (1, 7) >>> + Ordered_set_lang.decode) and+ implements = field_o "implements" ( - Syntax.since Stanza.syntax (1, 7) - >>= fun () -> located Lib_name.decode) + Syntax.since Stanza.syntax (1, 7) >>> + located Lib_name.decode) and+ variant = field_o "variant" ( - Syntax.since Stanza.syntax (1, 9) - >>= fun () -> located Variant.decode) + Syntax.since Stanza.syntax (1, 9) >>> + located Variant.decode) and+ default_implementation = field_o "default_implementation" ( - Syntax.since Stanza.syntax (1, 9) - >>= fun () -> located Lib_name.decode) + Syntax.since Stanza.syntax (1, 9) >>> + located Lib_name.decode) and+ private_modules = field_o "private_modules" ( - Syntax.since Stanza.syntax (1, 2) - >>= fun () -> Ordered_set_lang.decode) + let* () = Syntax.since Stanza.syntax (1, 2) in + Ordered_set_lang.decode) and+ stdlib = field_o "stdlib" (Syntax.since Stdlib.syntax (0, 1) >>> Stdlib.decode) in @@ -2121,11 +2121,11 @@ module Stanzas = struct (let+ x = Dune_env.Stanza.decode in [Dune_env.T x]) ; "include_subdirs", - (Dune_project.get_exn () >>= fun p -> + (let* project = Dune_project.get_exn () in let+ () = Syntax.since Stanza.syntax (1, 1) and+ t = let enable_qualified = - Option.is_some (Dune_project.find_extension_args p Coq.key) in + Option.is_some (Dune_project.find_extension_args project Coq.key) in Include_subdirs.decode ~enable_qualified and+ loc = loc in [Include_subdirs (loc, t)]) diff --git a/src/dune_package.ml b/src/dune_package.ml index 3318344f208..e9f445c7ec8 100644 --- a/src/dune_package.ml +++ b/src/dune_package.ml @@ -277,11 +277,13 @@ module Or_meta = struct let decode ~dir = let open Dune_lang.Decoder in - (* fields @@ *) fields - (field_b "use_meta" >>= function - | true -> return Use_meta - | false -> decode ~dir >>| fun p -> Dune_package p) + (let* use_meta = field_b "use_meta" in + if use_meta then + return Use_meta + else + let+ package = decode ~dir in + Dune_package package) let load p = Vfile.load p ~f:(fun _ -> decode ~dir:(Path.parent_exn p)) end diff --git a/src/fiber/fiber.ml b/src/fiber/fiber.ml index 6f0c80d388f..ec44a091a5d 100644 --- a/src/fiber/fiber.ml +++ b/src/fiber/fiber.ml @@ -210,15 +210,17 @@ let map t ~f = t >>| f let bind t ~f = t >>= f let both a b = - a >>= fun x -> - b >>= fun y -> + let* x = a in + let* y = b in return (x, y) let all l = let rec loop l acc = match l with | [] -> return (List.rev acc) - | t :: l -> t >>= fun x -> loop l (x :: acc) + | t :: l -> + let* x = t in + loop l (x :: acc) in loop l [] @@ -228,7 +230,9 @@ let map_all l ~f = let rec loop l acc = match l with | [] -> return (List.rev acc) - | x :: l -> f x >>= fun x -> loop l (x :: acc) + | x :: l -> + let* x = f x in + loop l (x :: acc) in loop l [] @@ -236,7 +240,9 @@ let map_all_unit l ~f = let rec loop l = match l with | [] -> return () - | x :: l -> f x >>= fun () -> loop l + | x :: l -> + let* () = f x in + loop l in loop l @@ -361,8 +367,8 @@ let collect_errors f = ~on_error:(fun e l -> e :: l) let finalize f ~finally = - wait_errors f >>= fun res -> - finally () >>= fun () -> + let* res = wait_errors f in + let* () = finally () in match res with | Ok x -> return x | Error () -> never @@ -441,7 +447,7 @@ module Once = struct | Running fut -> Future.wait fut | Not_started f -> t.state <- Starting; - fork f >>= fun fut -> + let* fut = fork f in t.state <- Running fut; Future.wait fut | Starting -> @@ -478,7 +484,7 @@ module Mutex = struct k () let with_lock t f = - lock t >>= fun () -> + let* () = lock t in finalize f ~finally:(fun () -> unlock t) let create () = diff --git a/src/file_bindings.ml b/src/file_bindings.ml index 153bcfba957..e5f74657ad1 100644 --- a/src/file_bindings.ml +++ b/src/file_bindings.ml @@ -55,9 +55,9 @@ module Unexpanded = struct { src; dst = None } | List (_, [_; Atom (_, A "as"); _]) -> enter - (decode >>= fun src -> + (let* src = decode in keyword "as" >>> - decode >>= fun dst -> + let* dst = decode in return { src; dst = Some dst }) | sexp -> of_sexp_error (Dune_lang.Ast.loc sexp) diff --git a/src/installed_dune_file.ml b/src/installed_dune_file.ml index b42dfcf8cd9..0009f375b03 100644 --- a/src/installed_dune_file.ml +++ b/src/installed_dune_file.ml @@ -59,7 +59,7 @@ let of_sexp = in sum [ "dune", - (version >>= fun version -> + (let* version = version in set (Syntax.key Stanza.syntax) version (let+ parsing_context = get_all and+ sub_systems = list raw diff --git a/src/merlin.ml b/src/merlin.ml index 94a131cc19d..91ece4781ce 100644 --- a/src/merlin.ml +++ b/src/merlin.ml @@ -144,16 +144,18 @@ let pp_flags sctx ~expander ~dir_kind { preprocess; libname; _ } = begin match action with | Run (exe, args) -> let open Option.O in - List.destruct_last args >>= (fun (args, input_file) -> + let* (args, input_file) = List.destruct_last args in + let* args = if String_with_vars.is_var input_file ~name:"input-file" then Some args else - None) - >>= fun args -> - Expander.Option.expand_path expander exe >>= fun exe -> - List.map ~f:(Expander.Option.expand_str expander) args - |> Option.List.all - >>= fun args -> + None + in + let* exe = Expander.Option.expand_path expander exe in + let* args = + List.map ~f:(Expander.Option.expand_str expander) args + |> Option.List.all + in (Path.to_absolute_filename exe :: args) |> List.map ~f:quote_for_merlin |> String.concat ~sep:" " diff --git a/src/ocaml-config/dune b/src/ocaml-config/dune index 1e97fd5f070..904abcf5883 100644 --- a/src/ocaml-config/dune +++ b/src/ocaml-config/dune @@ -1,5 +1,6 @@ (library (name ocaml_config) (public_name dune._ocaml_config) + (preprocess future_syntax) (libraries stdune) (synopsis "[Internal] Interpret the output of 'ocamlc -config'")) diff --git a/src/ocaml-config/ocaml_config.ml b/src/ocaml-config/ocaml_config.ml index 73b148be6af..afa48844181 100644 --- a/src/ocaml-config/ocaml_config.ml +++ b/src/ocaml-config/ocaml_config.ml @@ -228,7 +228,7 @@ module Vars = struct | None -> Error (Printf.sprintf "Unrecognized line: %S" line) in - loop [] lines >>= fun vars -> + let* vars = loop [] lines in Result.map_error (String.Map.of_list vars) ~f:(fun (var, _, _) -> Printf.sprintf "Variable %S present twice." var) diff --git a/src/ordered_set_lang.ml b/src/ordered_set_lang.ml index d0b09694da5..fe1d65910bf 100644 --- a/src/ordered_set_lang.ml +++ b/src/ordered_set_lang.ml @@ -67,10 +67,10 @@ module Parse = struct let+ to_remove = junk >>> many [] kind in Diff (Union (List.rev acc), to_remove) | Some _ -> - one kind >>= fun x -> + let* x = one kind in many (x :: acc) kind in - Stanza.file_kind () >>= fun kind -> + let* kind = Stanza.file_kind () in match kind with | Dune -> many [] kind | Jbuild -> one kind @@ -85,7 +85,7 @@ module Parse = struct let without_include ~elt = generic ~elt ~inc:( enter - (loc >>= fun loc -> + (let* loc = loc in Errors.fail loc "(:include ...) is not allowed here")) end diff --git a/src/predicate_lang.ml b/src/predicate_lang.ml index 5c08ee4c4e7..0f9a11b5481 100644 --- a/src/predicate_lang.ml +++ b/src/predicate_lang.ml @@ -20,7 +20,7 @@ module Ast = struct let decode elt = let open Stanza.Decoder in - let elt = elt >>| fun e -> Element e in + let elt = let+ e = elt in Element e in let rec one (kind : Dune_lang.Syntax.t) = peek_exn >>= function | Atom (loc, A "\\") -> Errors.fail loc "unexpected \\" @@ -61,10 +61,10 @@ module Ast = struct junk >>> many union [] kind >>| fun to_remove -> diff (k (List.rev acc)) to_remove | Some _ -> - one kind >>= fun x -> + let* x = one kind in many k (x :: acc) kind in - Stanza.file_kind () >>= fun kind -> + let* kind = Stanza.file_kind () in match kind with | Dune -> many union [] kind | Jbuild -> one kind diff --git a/src/preprocessing.ml b/src/preprocessing.ml index b3602b78dfe..070bf4ae4d4 100644 --- a/src/preprocessing.ml +++ b/src/preprocessing.ml @@ -373,9 +373,8 @@ let build_ppx_driver sctx ~dep_kind ~target ~dir_kind ~pps ~pp_names = (* Extend the dependency stack as we don't have locations at this point *) Dep_path.prepend_exn e (Preprocess pp_names)) - (pps - >>= Lib.closure ~linking:true - >>= fun pps -> + (let* pps = pps in + let* pps = Lib.closure ~linking:true pps in match jbuild_driver with | None -> let+ driver = diff --git a/src/print_diff.ml b/src/print_diff.ml index 98d586285ea..6cfce63554e 100644 --- a/src/print_diff.ml +++ b/src/print_diff.ml @@ -26,13 +26,14 @@ let print ?(skip_trailing_cr=Sys.win32) path1 path2 = | None -> fallback () | Some prog -> Format.eprintf "%a@?" Errors.print loc; - Process.run ~dir ~env:Env.initial Strict prog - (List.concat - [ ["-u"] - ; if skip_trailing_cr then ["--strip-trailing-cr"] else [] - ; [ file1; file2 ] - ]) - >>= fun () -> + let* () = + Process.run ~dir ~env:Env.initial Strict prog + (List.concat + [ ["-u"] + ; if skip_trailing_cr then ["--strip-trailing-cr"] else [] + ; [ file1; file2 ] + ]) + in fallback () in match !Clflags.diff_command with @@ -42,8 +43,7 @@ let print ?(skip_trailing_cr=Sys.win32) path1 path2 = let cmd = sprintf "%s %s %s" cmd (quote_for_shell file1) (quote_for_shell file2) in - Process.run ~dir ~env:Env.initial Strict sh [arg; cmd] - >>= fun () -> + let* () = Process.run ~dir ~env:Env.initial Strict sh [arg; cmd] in die "command reported no differences: %s" (if Path.is_root dir then cmd @@ -56,16 +56,17 @@ let print ?(skip_trailing_cr=Sys.win32) path1 path2 = match Bin.which ~path:(Env.path Env.initial) "patdiff" with | None -> normal_diff () | Some prog -> - Process.run ~dir ~env:Env.initial Strict prog - [ "-keep-whitespace" - ; "-location-style"; "omake" - ; if Lazy.force Colors.stderr_supports_colors then - "-unrefined" - else - "-ascii" - ; file1 - ; file2 - ] - >>= fun () -> + let* () = + Process.run ~dir ~env:Env.initial Strict prog + [ "-keep-whitespace" + ; "-location-style"; "omake" + ; if Lazy.force Colors.stderr_supports_colors then + "-unrefined" + else + "-ascii" + ; file1 + ; file2 + ] + in (* Use "diff" if "patdiff" reported no differences *) normal_diff () diff --git a/src/stanza.ml b/src/stanza.ml index 21523a1b604..aba99b997f0 100644 --- a/src/stanza.ml +++ b/src/stanza.ml @@ -54,27 +54,28 @@ module Decoder = struct switch_file_kind ~jbuild:(enter t) ~dune:( - try_ - t - (function - | Parens_no_longer_necessary _ as exn -> raise exn - | exn -> - try_ - (enter - (loc >>= fun loc -> - (if is_record then - peek >>= function - | Some (List _) -> - raise (Parens_no_longer_necessary (loc, exn)) - | _ -> t - else - t) - >>= fun _ -> - raise (Parens_no_longer_necessary (loc, exn)))) - (function - | Parens_no_longer_necessary _ as exn -> raise exn - | _ -> raise exn)) - ) + try_ + t + (function + | Parens_no_longer_necessary _ as exn -> raise exn + | exn -> + try_ + (enter + (let* loc = loc in + let* _ = + if is_record then + peek >>= function + | Some (List _) -> + raise (Parens_no_longer_necessary (loc, exn)) + | _ -> t + else + t + in + raise (Parens_no_longer_necessary (loc, exn)))) + (function + | Parens_no_longer_necessary _ as exn -> raise exn + | _ -> raise exn)) + ) let record parse = parens_removed_in_dune_generic (fields parse) ~is_record:true diff --git a/src/stdune/result.ml b/src/stdune/result.ml index 6c56c24a298..cb9a3aef453 100644 --- a/src/stdune/result.ml +++ b/src/stdune/result.ml @@ -43,12 +43,21 @@ let to_option = function let errorf fmt = Printf.ksprintf (fun x -> Error x) fmt +let both a b = + match a with + | Error e -> Error e + | Ok a -> + match b with + | Error e -> Error e + | Ok b -> Ok (a, b) + module O = struct let ( >>= ) t f = bind t ~f let ( >>| ) t f = map t ~f let (let*) = (>>=) let (let+) = (>>|) + let (and+) = both end open O diff --git a/src/stdune/result.mli b/src/stdune/result.mli index a0967122eb4..119603ba7c1 100644 --- a/src/stdune/result.mli +++ b/src/stdune/result.mli @@ -27,6 +27,7 @@ module O : sig val ( >>= ) : ('a, 'error) t -> ('a -> ('b, 'error) t) -> ('b, 'error) t val (let*) : ('a, 'error) t -> ('a -> ('b, 'error) t) -> ('b, 'error) t + val (and+) : ('a, 'error) t -> ('b, 'error) t -> ('a * 'b, 'error) t val (let+) : ('a, 'error) t -> ('a -> 'b) -> ('b, 'error) t end diff --git a/src/sub_system.ml b/src/sub_system.ml index f0e0d11bbef..7a750898138 100644 --- a/src/sub_system.ml +++ b/src/sub_system.ml @@ -125,14 +125,15 @@ module Register_end_point(M : End_point) = struct let gen info (c : Library_compilation_context.t) = let open Result.O in let backends = - Lib.Compile.direct_requires c.compile_info >>= fun deps -> - Lib.Compile.pps c.compile_info >>= fun pps -> - (match M.Info.backends info with - | None -> Ok None - | Some l -> - Result.List.map l ~f:(M.Backend.resolve (Scope.libs c.scope)) - >>| Option.some) - >>= fun written_by_user -> + let* deps = Lib.Compile.direct_requires c.compile_info in + let* pps = Lib.Compile.pps c.compile_info in + let* written_by_user = + match M.Info.backends info with + | None -> Ok None + | Some l -> + Result.List.map l ~f:(M.Backend.resolve (Scope.libs c.scope)) + >>| Option.some + in M.Backend.Selection_error.or_exn ~loc:(M.Info.loc info) (M.Backend.select_extensible_backends ?written_by_user diff --git a/src/syntax.ml b/src/syntax.ml index eaafa7cdd40..ec6d9a1a67a 100644 --- a/src/syntax.ml +++ b/src/syntax.ml @@ -172,17 +172,17 @@ let desc () = let deleted_in t ver = let open Version.Infix in - get_exn t >>= fun current_ver -> + let* current_ver = get_exn t in if current_ver < ver then return () else begin - desc () >>= fun (loc, what) -> + let* (loc, what) = desc () in Error.deleted_in loc t ver ~what end let deprecated_in t ver = let open Version.Infix in - get_exn t >>= fun current_ver -> + let* current_ver = get_exn t in if current_ver < ver then return () else begin @@ -192,17 +192,17 @@ let deprecated_in t ver = let renamed_in t ver ~to_ = let open Version.Infix in - get_exn t >>= fun current_ver -> + let* current_ver = get_exn t in if current_ver < ver then return () else begin - desc () >>= fun (loc, what) -> + let+ (loc, what) = desc () in Error.renamed_in loc t ver ~what ~to_ end let since ?(fatal=true) t ver = let open Version.Infix in - get_exn t >>= fun current_ver -> + let* current_ver = get_exn t in if current_ver >= ver then return () else diff --git a/src/workspace.ml b/src/workspace.ml index 5460c71dcc5..61286f8ea87 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -7,7 +7,7 @@ let syntax = Stanza.syntax let env_field = field_o "env" - (Syntax.since syntax (1, 1) >>= fun () -> + (Syntax.since syntax (1, 1) >>> Dune_env.Stanza.decode) module Context = struct @@ -59,7 +59,7 @@ module Context = struct and+ targets = field "targets" (list Target.t) ~default:[Target.Native] and+ profile = field "profile" string ~default:profile and+ toolchain = - field_o "toolchain" (Syntax.since syntax (1, 5) >>= fun () -> string) + field_o "toolchain" (Syntax.since syntax (1, 5) >>> string) and+ loc = loc in { targets @@ -165,13 +165,12 @@ include Versioned_file.Make(struct type t = unit end) let () = Lang.register syntax () let t ?x ?profile:cmdline_profile () = - Versioned_file.no_more_lang >>= fun () -> - env_field >>= fun env -> - field "profile" string ~default:Config.default_build_profile - >>= fun profile -> + let* () = Versioned_file.no_more_lang in + let* env = env_field in + let* profile = + field "profile" string ~default:Config.default_build_profile in let profile = Option.value cmdline_profile ~default:profile in - multi_field "context" (Context.t ~profile ~x) - >>| fun contexts -> + let+ contexts = multi_field "context" (Context.t ~profile ~x) in let defined_names = ref String.Set.empty in let merlin_context = List.fold_left contexts ~init:None ~f:(fun acc ctx -> diff --git a/src/wrapped.ml b/src/wrapped.ml index fc439d9da40..926ac930472 100644 --- a/src/wrapped.ml +++ b/src/wrapped.ml @@ -10,8 +10,8 @@ let decode = [ "true", return (Simple true) ; "false", return (Simple false) ; "transition", - Syntax.since Stanza.syntax (1, 2) >>= fun () -> - string >>| fun x -> Yes_with_transition x + Syntax.since Stanza.syntax (1, 2) >>> + let+ x = string in Yes_with_transition x ] let encode =