Merge pull request #1100 from ocaml/remove-some-polymorphic-comparisons

Remove some polymorphic comparisons
This commit is contained in:
Etienne Millon 2018-08-08 23:42:43 +02:00 committed by GitHub
commit 87f962df10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 205 additions and 50 deletions

View File

@ -630,7 +630,7 @@ let target_hint (setup : Main.setup) path =
(* Only suggest hints for the basename, otherwise it's slow when there are lots of (* Only suggest hints for the basename, otherwise it's slow when there are lots of
files *) files *)
List.filter_map candidates ~f:(fun path -> List.filter_map candidates ~f:(fun path ->
if Path.parent_exn path = sub_dir then if Path.equal (Path.parent_exn path) sub_dir then
Some (Path.to_string path) Some (Path.to_string path)
else else
None) None)

View File

@ -431,7 +431,7 @@ let get_dir_status t ~dir =
Path.Table.find_or_add t.dirs dir ~f:(fun _ -> Path.Table.find_or_add t.dirs dir ~f:(fun _ ->
if Path.is_in_source_tree dir then if Path.is_in_source_tree dir then
Dir_status.Loaded (File_tree.files_of t.file_tree dir) Dir_status.Loaded (File_tree.files_of t.file_tree dir)
else if dir = Path.build_dir then else if Path.equal dir Path.build_dir then
(* Not allowed to look here *) (* Not allowed to look here *)
Dir_status.Loaded Path.Set.empty Dir_status.Loaded Path.Set.empty
else if not (Path.is_managed dir) then else if not (Path.is_managed dir) then
@ -901,7 +901,7 @@ and load_dir_and_get_targets t ~dir =
| [] -> assert false | [] -> assert false
| x :: l -> | x :: l ->
t.load_dir_stack <- l; t.load_dir_stack <- l;
assert (x = dir))); assert (Path.equal x dir)));
Path.Table.replace t.dirs ~key:dir ~data:Failed_to_load; Path.Table.replace t.dirs ~key:dir ~data:Failed_to_load;
reraise exn reraise exn
@ -1095,7 +1095,7 @@ The following targets are not:
| [] -> assert false | [] -> assert false
| x :: l -> | x :: l ->
t.load_dir_stack <- l; t.load_dir_stack <- l;
assert (x = dir)); assert (Path.equal x dir));
(* Compile the rules and cleanup stale artifacts *) (* Compile the rules and cleanup stale artifacts *)
List.iter rules ~f:(compile_rule t ~copy_source:false); List.iter rules ~f:(compile_rule t ~copy_source:false);
@ -1475,6 +1475,7 @@ let package_deps t pkg files =
else else
List.fold_left pkgs ~init:acc ~f:add_package List.fold_left pkgs ~init:acc ~f:add_package
and add_package acc p = and add_package acc p =
let open Package.Name.Infix in
if p = pkg then if p = pkg then
acc acc
else else
@ -1528,7 +1529,7 @@ let get_collector t ~dir =
Exn.code_error Exn.code_error
(if Path.is_in_source_tree dir then (if Path.is_in_source_tree dir then
"Build_system.get_collector called on source directory" "Build_system.get_collector called on source directory"
else if dir = Path.build_dir then else if Path.equal dir Path.build_dir then
"Build_system.get_collector called on build_dir" "Build_system.get_collector called on build_dir"
else if not (Path.is_managed dir) then else if not (Path.is_managed dir) then
"Build_system.get_collector called on external directory" "Build_system.get_collector called on external directory"

View File

@ -175,6 +175,7 @@ module Library_modules = struct
if not lib.wrapped then if not lib.wrapped then
modules modules
else else
let open Module.Name.Infix in
Module.Name.Map.map modules ~f:(fun m -> Module.Name.Map.map modules ~f:(fun m ->
if m.name = main_module_name then if m.name = main_module_name then
m m
@ -274,7 +275,7 @@ let mlds t (doc : Documentation.t) =
let map = Lazy.force t.mlds in let map = Lazy.force t.mlds in
match match
List.find_map map ~f:(fun (doc', x) -> List.find_map map ~f:(fun (doc', x) ->
Option.some_if (doc.loc = doc'.loc) x) Option.some_if (Loc.equal doc.loc doc'.loc) x)
with with
| Some x -> x | Some x -> x
| None -> | None ->
@ -409,6 +410,7 @@ let build_modules_map (d : Super_context.Dir_with_jbuild.t) ~modules =
match Module.Name.Map.of_list rev_modules with match Module.Name.Map.of_list rev_modules with
| Ok x -> x | Ok x -> x
| Error (name, _, _) -> | Error (name, _, _) ->
let open Module.Name.Infix in
let locs = let locs =
List.filter_map rev_modules ~f:(fun (n, b) -> List.filter_map rev_modules ~f:(fun (n, b) ->
Option.some_if (n = name) b.loc) Option.some_if (n = name) b.loc)
@ -549,7 +551,7 @@ module Dir_status = struct
let project_root = Path.of_local (File_tree.Dir.project ft_dir).root in let project_root = Path.of_local (File_tree.Dir.project ft_dir).root in
match Super_context.stanzas_in sctx ~dir with match Super_context.stanzas_in sctx ~dir with
| None -> | None ->
if dir = project_root || if Path.equal dir project_root ||
is_standalone (get sctx ~dir:(Path.parent_exn dir)) then is_standalone (get sctx ~dir:(Path.parent_exn dir)) then
Standalone (Some (ft_dir, None)) Standalone (Some (ft_dir, None))
else else

View File

@ -32,20 +32,28 @@ module Name : sig
val named : string -> t option val named : string -> t option
val anonymous_root : t val anonymous_root : t
module Infix : Comparable.OPS with type t = t
end = struct end = struct
type t = module T = struct
| Named of string type t =
| Anonymous of Path.t | Named of string
| Anonymous of Path.t
let compare a b =
match a, b with
| Named x, Named y -> String.compare x y
| Anonymous x, Anonymous y -> Path.compare x y
| Named _, Anonymous _ -> Lt
| Anonymous _, Named _ -> Gt
end
include T
module Infix = Comparable.Operators(T)
let anonymous_root = Anonymous Path.root let anonymous_root = Anonymous Path.root
let compare a b =
match a, b with
| Named x, Named y -> String.compare x y
| Anonymous x, Anonymous y -> Path.compare x y
| Named _, Anonymous _ -> Lt
| Anonymous _, Named _ -> Gt
let to_string_hum = function let to_string_hum = function
| Named s -> s | Named s -> s
| Anonymous p -> sprintf "<anonymous %s>" (Path.to_string_maybe_quoted p) | Anonymous p -> sprintf "<anonymous %s>" (Path.to_string_maybe_quoted p)
@ -305,6 +313,7 @@ let default_name ~dir ~packages =
| None -> Option.value_exn (Name.anonymous dir) | None -> Option.value_exn (Name.anonymous dir)
| Some (_, pkg) -> | Some (_, pkg) ->
let pkg = let pkg =
let open Package.Name.Infix in
Package.Name.Map.fold packages ~init:pkg ~f:(fun pkg acc -> Package.Name.Map.fold packages ~init:pkg ~f:(fun pkg acc ->
if acc.Package.name <= pkg.Package.name then if acc.Package.name <= pkg.Package.name then
acc acc

View File

@ -27,6 +27,8 @@ module Name : sig
(** Convert to/from an encoded string that is suitable to use in filenames *) (** Convert to/from an encoded string that is suitable to use in filenames *)
val encode : t -> string val encode : t -> string
val decode : string -> t val decode : string -> t
module Infix : Comparable.OPS with type t = t
end end
module Project_file : sig module Project_file : sig

View File

@ -76,25 +76,27 @@ module Linkage = struct
let flags = let flags =
match m.kind with match m.kind with
| Exe -> | Exe ->
if wanted_mode = Native && real_mode = Byte then begin
["-custom"] match wanted_mode, real_mode with
else | Native, Byte -> ["-custom"]
[] | _ -> []
end
| Object -> o_flags | Object -> o_flags
| Shared_object -> | Shared_object ->
let so_flags = let so_flags =
if ctx.os_type = "Win32" then if String.equal ctx.os_type "Win32" then
so_flags_windows so_flags_windows
else else
so_flags_unix so_flags_unix
in in
if real_mode = Native then match real_mode with
| Native ->
(* The compiler doesn't pass these flags in native mode. This (* The compiler doesn't pass these flags in native mode. This
looks like a bug in the compiler. *) looks like a bug in the compiler. *)
List.concat_map ctx.native_c_libraries ~f:(fun flag -> List.concat_map ctx.native_c_libraries ~f:(fun flag ->
["-cclib"; flag]) ["-cclib"; flag])
@ so_flags @ so_flags
else | Byte ->
so_flags so_flags
in in
{ ext { ext

View File

@ -487,9 +487,10 @@ module Gen(P : Install_rules.Params) = struct
let l = let l =
let has_native = Option.is_some ctx.ocamlopt in let has_native = Option.is_some ctx.ocamlopt in
List.filter_map (L.Set.to_list exes.modes) ~f:(fun (mode : L.t) -> 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 None
else | _ ->
Some (Exe.Linkage.of_user_config ctx mode)) Some (Exe.Linkage.of_user_config ctx mode))
in in
(* If bytecode was requested but not native or best version, (* If bytecode was requested but not native or best version,
@ -697,7 +698,7 @@ module Gen(P : Install_rules.Params) = struct
Option.bind (Dir_contents.lookup_module dir_contents name) Option.bind (Dir_contents.lookup_module dir_contents name)
~f:(fun buildable -> ~f:(fun buildable ->
List.find_map cctxs ~f:(fun (loc, cctx) -> List.find_map cctxs ~f:(fun (loc, cctx) ->
Option.some_if (loc = buildable.loc) cctx))) Option.some_if (Loc.equal loc buildable.loc) cctx)))
with with
| None -> | None ->
(* This happens often when passing a [-p ...] option that (* This happens often when passing a [-p ...] option that

View File

@ -870,15 +870,9 @@ module Mode_conf = struct
let default = of_list [Byte; Best] let default = of_list [Byte; Best]
let eval t ~has_native = 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 has_best = mem t Best in
let byte = mem t Byte || (has_best && best = Byte) in let byte = mem t Byte || (has_best && (not has_native)) in
let native = best = Native && (mem t Native || has_best) in let native = has_native && (mem t Native || has_best) in
{ Mode.Dict.byte; native } { Mode.Dict.byte; native }
end end
end end
@ -958,6 +952,7 @@ module Library = struct
and dune_version = Syntax.get_exn Stanza.syntax and dune_version = Syntax.get_exn Stanza.syntax
in in
let name = let name =
let open Syntax.Version.Infix in
match name, public with match name, public with
| Some n, _ -> | Some n, _ ->
Lib_name.validate n ~wrapped Lib_name.validate n ~wrapped
@ -1202,6 +1197,7 @@ module Executables = struct
in in
fun names public_names ~multi -> fun names public_names ~multi ->
let names = let names =
let open Syntax.Version.Infix in
match names, public_names with match names, public_names with
| Some names, _ -> names | Some names, _ -> names
| None, Some public_names -> | None, Some public_names ->
@ -1844,7 +1840,7 @@ module Stanzas = struct
if not (Path.exists current_file) then if not (Path.exists current_file) then
Loc.fail loc "File %s doesn't exist." Loc.fail loc "File %s doesn't exist."
(Path.to_string_maybe_quoted current_file); (Path.to_string_maybe_quoted current_file);
if List.exists include_stack ~f:(fun (_, f) -> f = current_file) then if List.exists include_stack ~f:(fun (_, f) -> Path.equal f current_file) then
raise (Include_loop (current_file, include_stack)); raise (Include_loop (current_file, include_stack));
let sexps = Io.Sexp.load ~lexer current_file ~mode:Many in let sexps = Io.Sexp.load ~lexer current_file ~mode:Many in
parse stanza_parser sexps ~lexer ~current_file ~include_stack parse stanza_parser sexps ~lexer ~current_file ~include_stack

View File

@ -242,7 +242,7 @@ let load ?extra_ignored_subtrees ?(ignore_promoted_rules=false) () =
~f:(fun dir acc -> ~f:(fun dir acc ->
let p = File_tree.Dir.project dir in let p = File_tree.Dir.project dir in
match Path.kind (File_tree.Dir.path dir) with match Path.kind (File_tree.Dir.path dir) with
| Local d when d = p.root -> p :: acc | Local d when Path.Local.equal d p.root -> p :: acc
| _ -> acc) | _ -> acc)
in in
let packages = let packages =

View File

@ -125,7 +125,7 @@ let build_cm cc ~(js_of_ocaml:Jbuild.Js_of_ocaml.t) ~src ~target =
>>> >>>
js_of_ocaml_rule sctx ~dir ~flags:(fun flags -> As flags) ~spec ~target:itarget js_of_ocaml_rule sctx ~dir ~flags:(fun flags -> As flags) ~spec ~target:itarget
] ]
@ (if target = itarget then @ (if Path.equal target itarget then
[] []
else else
[Build.symlink ~src:itarget ~dst:target]) [Build.symlink ~src:itarget ~dst:target])

View File

@ -533,7 +533,7 @@ module Dep_stack = struct
let to_required_by t ~stop_at = let to_required_by t ~stop_at =
let stop_at = stop_at.stack in let stop_at = stop_at.stack in
let rec loop acc l = let rec loop acc l =
if l == stop_at then if List.physically_equal l stop_at then
List.rev acc List.rev acc
else else
match l with match l with

View File

@ -77,3 +77,22 @@ let to_file_colon_line t =
let pp_file_colon_line ppf t = let pp_file_colon_line ppf t =
Format.pp_print_string ppf (to_file_colon_line t) Format.pp_print_string ppf (to_file_colon_line t)
let equal_position
{ Lexing.pos_fname = f_a; pos_lnum = l_a
; pos_bol = b_a; pos_cnum = c_a }
{ Lexing.pos_fname = f_b; pos_lnum = l_b
; pos_bol = b_b; pos_cnum = c_b }
=
let open Int.Infix in
String.equal f_a f_b
&& l_a = l_b
&& b_a = b_b
&& c_a = c_b
let equal
{ start = start_a ; stop = stop_a }
{ start = start_b ; stop = stop_b }
=
equal_position start_a start_b
&& equal_position stop_a stop_b

View File

@ -3,6 +3,8 @@ type t = Usexp.Loc.t =
; stop : Lexing.position ; stop : Lexing.position
} }
val equal : t -> t -> bool
val sexp_of_t : t -> Usexp.t val sexp_of_t : t -> Usexp.t
val of_lexbuf : Lexing.lexbuf -> t val of_lexbuf : Lexing.lexbuf -> t

View File

@ -1,13 +1,17 @@
open Import open Import
module Name = struct module Name = struct
type t = string module T = struct
type t = string
let compare = compare
end
include T
let t = Sexp.atom let t = Sexp.atom
let add_suffix = (^) let add_suffix = (^)
let compare = compare
let of_string = String.capitalize let of_string = String.capitalize
let to_string x = x let to_string x = x
@ -19,6 +23,7 @@ module Name = struct
module Set = String.Set module Set = String.Set
module Map = String.Map module Map = String.Map
module Top_closure = Top_closure.String module Top_closure = Top_closure.String
module Infix = Comparable.Operators(T)
end end
module Syntax = struct module Syntax = struct

View File

@ -19,6 +19,8 @@ module Name : sig
module Map : Map.S with type key = t module Map : Map.S with type key = t
module Top_closure : Top_closure.S with type key := t module Top_closure : Top_closure.S with type key := t
module Infix : Comparable.OPS with type t = t
end end
module Syntax : sig module Syntax : sig

View File

@ -60,6 +60,7 @@ module Dep_graphs = struct
end end
let parse_module_names ~(unit : Module.t) ~modules words = let parse_module_names ~(unit : Module.t) ~modules words =
let open Module.Name.Infix in
List.filter_map words ~f:(fun m -> List.filter_map words ~f:(fun m ->
let m = Module.Name.of_string m in let m = Module.Name.of_string m in
if m = unit.name then if m = unit.name then
@ -68,6 +69,7 @@ let parse_module_names ~(unit : Module.t) ~modules words =
Module.Name.Map.find modules m) Module.Name.Map.find modules m)
let is_alias_module cctx (m : Module.t) = let is_alias_module cctx (m : Module.t) =
let open Module.Name.Infix in
match CC.alias_module cctx with match CC.alias_module cctx with
| None -> false | None -> false
| Some alias -> alias.name = m.name | Some alias -> alias.name = m.name
@ -103,6 +105,7 @@ let parse_deps cctx ~file ~unit lines =
(match lib_interface_module with (match lib_interface_module with
| None -> () | None -> ()
| Some (m : Module.t) -> | Some (m : Module.t) ->
let open Module.Name.Infix in
if unit.name <> m.name && not (is_alias_module cctx unit) && if unit.name <> m.name && not (is_alias_module cctx unit) &&
List.exists deps ~f:(fun x -> Module.name x = m.name) then List.exists deps ~f:(fun x -> Module.name x = m.name) then
die "Module %a in directory %s depends on %a.\n\ die "Module %a in directory %s depends on %a.\n\

View File

@ -1,12 +1,14 @@
open Stdune open Stdune
module Name = struct module Name = struct
include Interned.Make(struct module T = Interned.Make(struct
let initial_size = 16 let initial_size = 16
let resize_policy = Interned.Conservative let resize_policy = Interned.Conservative
let order = Interned.Natural let order = Interned.Natural
end)() end)()
include T
let of_string = make let of_string = make
let opam_fn (t : t) = to_string t ^ ".opam" let opam_fn (t : t) = to_string t ^ ".opam"
@ -14,6 +16,8 @@ module Name = struct
let pp fmt t = Format.pp_print_string fmt (to_string t) let pp fmt t = Format.pp_print_string fmt (to_string t)
let t = Sexp.Of_sexp.(map string ~f:of_string) let t = Sexp.Of_sexp.(map string ~f:of_string)
module Infix = Comparable.Operators(T)
end end

View File

@ -14,6 +14,8 @@ module Name : sig
include Interned.S with type t := t include Interned.S with type t := t
val t : t Sexp.Of_sexp.t val t : t Sexp.Of_sexp.t
module Infix : Comparable.OPS with type t = t
end end
type t = type t =

View File

@ -157,6 +157,7 @@ module Map = struct
let rec expand map ~syntax_version ~pform = let rec expand map ~syntax_version ~pform =
let open Option.O in let open Option.O in
let open Syntax.Version.Infix in
let name = String_with_vars.Var.name pform in let name = String_with_vars.Var.name pform in
String.Map.find map name >>= fun v -> String.Map.find map name >>= fun v ->
let describe = String_with_vars.Var.describe in let describe = String_with_vars.Var.describe in

View File

@ -346,6 +346,7 @@ let ppx_driver_exe sctx libs ~dir_kind =
| Private scope_name -> Some scope_name | Private scope_name -> Some scope_name
| Public _ | Installed -> None | Public _ | Installed -> None
in in
let open Dune_project.Name.Infix in
match acc, scope_for_key with match acc, scope_for_key with
| Some a, Some b -> assert (a = b); acc | Some a, Some b -> assert (a = b); acc
| Some _, None -> acc | Some _, None -> acc

View File

@ -8,7 +8,7 @@ let print ?(skip_trailing_cr=Sys.win32) path1 path2 =
Path.extract_build_context_dir path1, Path.extract_build_context_dir path1,
Path.extract_build_context_dir path2 Path.extract_build_context_dir path2
with with
| Some (dir1, f1), Some (dir2, f2) when dir1 = dir2 -> | Some (dir1, f1), Some (dir2, f2) when Path.equal dir1 dir2 ->
(dir1, Path.to_string f1, Path.to_string f2) (dir1, Path.to_string f1, Path.to_string f2)
| _ -> | _ ->
(Path.root, Path.to_string path1, Path.to_string path2) (Path.root, Path.to_string path1, Path.to_string path2)

View File

@ -125,7 +125,7 @@ module Fancy = struct
in in
match stdout_to, stderr_to with match stdout_to, stderr_to with
| (File fn1 | Opened_file { filename = fn1; _ }), | (File fn1 | Opened_file { filename = fn1; _ }),
(File fn2 | Opened_file { filename = fn2; _ }) when fn1 = fn2 -> (File fn2 | Opened_file { filename = fn2; _ }) when Path.equal fn1 fn2 ->
sprintf "%s &> %s" s (Path.to_string fn1) sprintf "%s &> %s" s (Path.to_string fn1)
| _ -> | _ ->
let s = let s =

View File

@ -114,7 +114,12 @@ let report exn =
let backtrace = Printexc.get_raw_backtrace () in let backtrace = Printexc.get_raw_backtrace () in
let ppf = err_ppf in let ppf = err_ppf in
let p = report_with_backtrace exn in let p = report_with_backtrace exn in
let loc = if p.loc = Some Loc.none then None else p.loc in let loc =
if Option.equal Loc.equal p.loc (Some Loc.none) then
None
else
p.loc
in
Option.iter loc ~f:(fun loc -> Loc.print ppf loc); Option.iter loc ~f:(fun loc -> Loc.print ppf loc);
p.pp ppf; p.pp ppf;
Format.pp_print_flush ppf (); Format.pp_print_flush ppf ();

View File

@ -2,3 +2,41 @@ module type S = sig
type t type t
val compare : t -> t -> Ordering.t val compare : t -> t -> Ordering.t
end end
module type OPS = sig
type t
val (=) : t -> t -> bool
val (>=) : t -> t -> bool
val (>) : t -> t -> bool
val (<=) : t -> t -> bool
val (<) : t -> t -> bool
end
module Operators (X : S) = struct
type t = X.t
let (=) a b =
match X.compare a b with
| Eq -> true
| Gt | Lt -> false
let (>=) a b =
match X.compare a b with
| Gt | Eq -> true
| Lt -> false
let (>) a b =
match X.compare a b with
| Gt -> true
| Lt | Eq -> false
let (<=) a b =
match X.compare a b with
| Lt | Eq -> true
| Gt -> false
let (<) a b =
match X.compare a b with
| Lt -> true
| Gt | Eq -> false
end

View File

@ -2,3 +2,14 @@ module type S = sig
type t type t
val compare : t -> t -> Ordering.t val compare : t -> t -> Ordering.t
end end
module type OPS = sig
type t
val (=) : t -> t -> bool
val (>=) : t -> t -> bool
val (>) : t -> t -> bool
val (<=) : t -> t -> bool
val (<) : t -> t -> bool
end
module Operators (X : S) : OPS with type t = X.t

View File

@ -19,3 +19,5 @@ let of_string_exn s =
| exception Failure _ -> | exception Failure _ ->
failwith (Printf.sprintf "of_string_exn: invalid int %S" s) failwith (Printf.sprintf "of_string_exn: invalid int %S" s)
| s -> s | s -> s
module Infix = Comparable.Operators(T)

View File

@ -5,3 +5,5 @@ module Set : Set.S with type elt = t
module Map : Map.S with type key = t module Map : Map.S with type key = t
val of_string_exn : string -> t val of_string_exn : string -> t
module Infix : Comparable.OPS with type t = t

View File

@ -115,3 +115,5 @@ let rec nth t i =
| [], _ -> None | [], _ -> None
| x :: _, 0 -> Some x | x :: _, 0 -> Some x
| _ :: xs, i -> nth xs (i - 1) | _ :: xs, i -> nth xs (i - 1)
let physically_equal = Pervasives.(==)

View File

@ -43,3 +43,5 @@ val assoc : ('a * 'b) t -> 'a -> 'b option
val singleton : 'a -> 'a t val singleton : 'a -> 'a t
val nth : 'a t -> int -> 'a option val nth : 'a t -> int -> 'a option
val physically_equal : 'a t -> 'a t -> bool

View File

@ -52,3 +52,10 @@ let both x y =
let to_list = function let to_list = function
| None -> [] | None -> []
| Some x -> [x] | Some x -> [x]
let equal eq x y =
match (x, y) with
| None, None -> true
| Some _, None -> false
| None, Some _ -> false
| Some sx, Some sy -> eq sx sy

View File

@ -26,3 +26,5 @@ val is_none : _ t -> bool
val both : 'a t -> 'b t -> ('a * 'b) t val both : 'a t -> 'b t -> ('a * 'b) t
val to_list : 'a t -> 'a list val to_list : 'a t -> 'a list
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

View File

@ -136,6 +136,7 @@ module Local : sig
val is_root : t -> bool val is_root : t -> bool
val compare : t -> t -> Ordering.t val compare : t -> t -> Ordering.t
val compare_val : t -> t -> Ordering.t val compare_val : t -> t -> Ordering.t
val equal : t -> t -> bool
val of_string : ?error_loc:Usexp.Loc.t -> string -> t val of_string : ?error_loc:Usexp.Loc.t -> string -> t
val to_string : t -> string val to_string : t -> string
val relative : ?error_loc:Usexp.Loc.t -> t -> string -> t val relative : ?error_loc:Usexp.Loc.t -> t -> string -> t
@ -172,6 +173,11 @@ end = struct
let compare_val x y = String.compare (to_string x) (to_string y) let compare_val x y = String.compare (to_string x) (to_string y)
let equal x y =
match compare x y with
| Eq -> true
| Gt | Lt -> false
let root = make "." let root = make "."
let is_root t = t = root let is_root t = t = root

View File

@ -2,6 +2,7 @@
module Local : sig module Local : sig
type t type t
val sexp_of_t : t -> Sexp.t val sexp_of_t : t -> Sexp.t
val equal : t -> t -> bool
end end
(** In the outside world *) (** In the outside world *)
@ -31,6 +32,8 @@ val sexp_of_t : t Sexp.To_sexp.t
val compare : t -> t -> Ordering.t val compare : t -> t -> Ordering.t
(** a directory is smaller than its descendants *) (** a directory is smaller than its descendants *)
val equal : t -> t -> bool
module Set : sig module Set : sig
include Set.S with type elt = t include Set.S with type elt = t
val sexp_of_t : t Sexp.To_sexp.t val sexp_of_t : t Sexp.To_sexp.t

View File

@ -7,6 +7,7 @@ include struct
let uncapitalize_ascii = String.uncapitalize let uncapitalize_ascii = String.uncapitalize
let uppercase_ascii = String.uppercase let uppercase_ascii = String.uppercase
let lowercase_ascii = String.lowercase let lowercase_ascii = String.lowercase
let equal (a:string) b = Pervasives.(=) a b
end end
include StringLabels include StringLabels

View File

@ -1,5 +1,6 @@
include module type of struct include StringLabels end include module type of struct include StringLabels end
val equal : t -> t -> bool
val compare : t -> t -> Ordering.t val compare : t -> t -> Ordering.t
val break : t -> pos:int -> t * t val break : t -> pos:int -> t * t

View File

@ -638,7 +638,7 @@ let create
List.iter stanzas ~f:(function List.iter stanzas ~f:(function
| Dune_env.T config -> | Dune_env.T config ->
let inherit_from = let inherit_from =
if ctx_dir = Scope.root scope then if Path.equal ctx_dir (Scope.root scope) then
context_env_node context_env_node
else else
lazy (Env.get t ~dir:(Path.parent_exn ctx_dir)) lazy (Env.get t ~dir:(Path.parent_exn ctx_dir))
@ -811,7 +811,7 @@ module Action = struct
| Some host -> | Some host ->
fun exe -> fun exe ->
match Path.extract_build_context_dir exe with match Path.extract_build_context_dir exe with
| Some (dir, exe) when dir = sctx.context.build_dir -> | Some (dir, exe) when Path.equal dir sctx.context.build_dir ->
Path.append host.context.build_dir exe Path.append host.context.build_dir exe
| _ -> exe | _ -> exe

View File

@ -1,7 +1,18 @@
open Import open Import
module Version = struct module Version = struct
type t = int * int module T = struct
type t = int * int
let compare (major_a, minor_a) (major_b, minor_b) =
match Int.compare major_a major_b with
| (Gt | Lt) as ne -> ne
| Eq -> Int.compare minor_a minor_b
end
include T
module Infix = Comparable.Operators(T)
let to_string (a, b) = sprintf "%u.%u" a b let to_string (a, b) = sprintf "%u.%u" a b
@ -19,8 +30,11 @@ module Version = struct
| sexp -> | sexp ->
of_sexp_error (Sexp.Ast.loc sexp) "Atom expected" of_sexp_error (Sexp.Ast.loc sexp) "Atom expected"
let can_read ~parser_version:(pa, pb) ~data_version:(da, db) = let can_read
pa = da && db <= pb ~parser_version:(parser_major, parser_minor)
~data_version:(data_major, data_minor) =
let open Int.Infix in
parser_major = data_major && parser_minor >= data_minor
end end
module Supported_versions = struct module Supported_versions = struct
@ -92,6 +106,7 @@ let check_supported t (loc, ver) =
(String.concat ~sep:"\n" (String.concat ~sep:"\n"
(List.map (Supported_versions.supported_ranges t.supported_versions) (List.map (Supported_versions.supported_ranges t.supported_versions)
~f:(fun (a, b) -> ~f:(fun (a, b) ->
let open Version.Infix in
if a = b then if a = b then
sprintf "- %s" (Version.to_string a) sprintf "- %s" (Version.to_string a)
else else
@ -125,6 +140,7 @@ let desc () =
| Fields (loc, Some s) -> (loc, sprintf "Field '%s'" s) | Fields (loc, Some s) -> (loc, sprintf "Field '%s'" s)
let deleted_in t ver = let deleted_in t ver =
let open Version.Infix in
get_exn t >>= fun current_ver -> get_exn t >>= fun current_ver ->
if current_ver < ver then if current_ver < ver then
return () return ()
@ -134,6 +150,7 @@ let deleted_in t ver =
end end
let renamed_in t ver ~to_ = let renamed_in t ver ~to_ =
let open Version.Infix in
get_exn t >>= fun current_ver -> get_exn t >>= fun current_ver ->
if current_ver < ver then if current_ver < ver then
return () return ()
@ -143,6 +160,7 @@ let renamed_in t ver ~to_ =
end end
let since t ver = let since t ver =
let open Version.Infix in
get_exn t >>= fun current_ver -> get_exn t >>= fun current_ver ->
if current_ver >= ver then if current_ver >= ver then
return () return ()

View File

@ -16,6 +16,9 @@ module Version : sig
(** Whether the parser can read the data or not *) (** Whether the parser can read the data or not *)
val can_read : parser_version:t -> data_version:t -> bool val can_read : parser_version:t -> data_version:t -> bool
val compare : t -> t -> Ordering.t
module Infix : Comparable.OPS with type t = t
end end
type t type t