From cc4b4f2d700375245540b0b4b090e139263eba73 Mon Sep 17 00:00:00 2001 From: xvw Date: Tue, 24 Sep 2024 16:44:11 +0200 Subject: [PATCH] Make final sort determinist --- src/analysis/type_search.ml | 6 ++- ...ch-by-type-comparison-to-polarity-search.t | 20 +++---- tests/test-dirs/search-by-type.t/run.t | 52 +++++++++---------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/analysis/type_search.ml b/src/analysis/type_search.ml index 9ab04e5f1..e8bb75ac0 100644 --- a/src/analysis/type_search.ml +++ b/src/analysis/type_search.ml @@ -84,7 +84,11 @@ let compare_result Query_protocol.{ cost = cost_a; name = a; doc = doc_a; _ } match (c, doc_a, doc_b) with | 0, Some _, None -> 1 | 0, None, Some _ -> -1 - | 0, Some a, Some b -> Int.compare (String.length a) (String.length b) + | 0, Some doc_a, Some doc_b -> + let c = Int.compare (String.length doc_a) (String.length doc_b) in + (* Make default insertion determinist *) + if Int.equal 0 c then String.compare a b else c + | 0, None, None -> String.compare a b | _ -> c else c diff --git a/tests/test-dirs/search-by-type-comparison-to-polarity-search.t b/tests/test-dirs/search-by-type-comparison-to-polarity-search.t index dc5aa5f88..0654dbb1f 100644 --- a/tests/test-dirs/search-by-type-comparison-to-polarity-search.t +++ b/tests/test-dirs/search-by-type-comparison-to-polarity-search.t @@ -16,14 +16,14 @@ potential failures, so lifting the result in an int option). "name": "int_of_string_opt", "type": "string -> int option" } - { - "name": "Int64.of_string_opt", - "type": "string -> int64 option" - } { "name": "Int32.of_string_opt", "type": "string -> int32 option" } + { + "name": "Int64.of_string_opt", + "type": "string -> int64 option" + } { "name": "Sys.getenv_opt", "type": "string -> string option" @@ -132,17 +132,17 @@ map). "name": "Seq.map", "type": "('a -> 'b) -> 'a Stdlib__Seq.t -> 'b Stdlib__Seq.t" } - { - "name": "List.filter_map", - "type": "('a -> 'b option) -> 'a list -> 'b list" - } { "name": "List.concat_map", "type": "('a -> 'b list) -> 'a list -> 'b list" } { - "name": "ListLabels.filter_map", - "type": "f:('a -> 'b option) -> 'a list -> 'b list" + "name": "List.filter_map", + "type": "('a -> 'b option) -> 'a list -> 'b list" + } + { + "name": "ListLabels.concat_map", + "type": "f:('a -> 'b list) -> 'a list -> 'b list" } diff --git a/tests/test-dirs/search-by-type.t/run.t b/tests/test-dirs/search-by-type.t/run.t index 849b3de60..06b4a4da4 100644 --- a/tests/test-dirs/search-by-type.t/run.t +++ b/tests/test-dirs/search-by-type.t/run.t @@ -14,14 +14,14 @@ "doc": null } { - "name": "Int64.of_string_opt", - "type": "string -> int64 option", + "name": "Int32.of_string_opt", + "type": "string -> int32 option", "cost": 2, "doc": null } { - "name": "Int32.of_string_opt", - "type": "string -> int32 option", + "name": "Int64.of_string_opt", + "type": "string -> int64 option", "cost": 2, "doc": null } @@ -109,20 +109,20 @@ "doc": null } { - "name": "List.filter_map", - "type": "('a -> 'b option) -> 'a list -> 'b list", + "name": "List.concat_map", + "type": "('a -> 'b list) -> 'a list -> 'b list", "cost": 10, "doc": null } { - "name": "List.concat_map", - "type": "('a -> 'b list) -> 'a list -> 'b list", + "name": "List.filter_map", + "type": "('a -> 'b option) -> 'a list -> 'b list", "cost": 10, "doc": null } { - "name": "ListLabels.filter_map", - "type": "f:('a -> 'b option) -> 'a list -> 'b list", + "name": "ListLabels.concat_map", + "type": "f:('a -> 'b list) -> 'a list -> 'b list", "cost": 10, "doc": null } @@ -234,34 +234,34 @@ { "file": "moreLabels.mli", "start": { - "line": 168, + "line": 318, "col": 2 }, "end": { - "line": 168, - "col": 55 + "line": 318, + "col": 52 }, - "name": "MoreLabels.Hashtbl.replace", - "type": "('a, 'b) Stdlib__MoreLabels.Hashtbl.t -> key:'a -> data:'b -> unit", + "name": "MoreLabels.Hashtbl.add_seq", + "type": "('a, 'b) Stdlib__MoreLabels.Hashtbl.t -> ('a * 'b) Seq.t -> unit", "cost": 48, "doc": null, - "constructible": "MoreLabels.Hashtbl.replace _ ~key:_ ~data:_" + "constructible": "MoreLabels.Hashtbl.add_seq _ _" }, { "file": "moreLabels.mli", "start": { - "line": 318, + "line": 168, "col": 2 }, "end": { - "line": 318, - "col": 52 + "line": 168, + "col": 55 }, - "name": "MoreLabels.Hashtbl.add_seq", - "type": "('a, 'b) Stdlib__MoreLabels.Hashtbl.t -> ('a * 'b) Seq.t -> unit", + "name": "MoreLabels.Hashtbl.replace", + "type": "('a, 'b) Stdlib__MoreLabels.Hashtbl.t -> key:'a -> data:'b -> unit", "cost": 48, "doc": null, - "constructible": "MoreLabels.Hashtbl.add_seq _ _" + "constructible": "MoreLabels.Hashtbl.replace _ ~key:_ ~data:_" }, { "file": "moreLabels.mli", @@ -316,14 +316,14 @@ "doc": "Convert the given string to an integer. The string is read in decimal (by default, or if the string begins with [0u]), in hexadecimal (if it begins with [0x] or [0X]), in octal (if it begins with [0o] or [0O]), or in binary (if it begins with [0b] or [0B]). The [0u] prefix reads the input as an unsigned integer in the range [[0, 2*max_int+1]]. If the input exceeds {!max_int} it is converted to the signed integer [min_int + input - max_int - 1]. The [_] (underscore) character can appear anywhere in the string and is ignored. Return [None] if the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in type [int]. @since 4.05" } { - "name": "Int64.of_string_opt", - "type": "string -> int64 option", + "name": "Int32.of_string_opt", + "type": "string -> int32 option", "cost": 2, "doc": "Same as [of_string], but return [None] instead of raising. @since 4.05" } { - "name": "Int32.of_string_opt", - "type": "string -> int32 option", + "name": "Int64.of_string_opt", + "type": "string -> int64 option", "cost": 2, "doc": "Same as [of_string], but return [None] instead of raising. @since 4.05" }