From c3bbd22666d34b19a1655d5ce582ae6c7bfbe6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Wed, 3 Aug 2022 14:03:50 +0200 Subject: [PATCH] Protocol/SCORU: infix syntax cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François Thiré Co-authored-by: Raphaël Proust --- .../lib_protocol/sc_rollup_inbox_repr.ml | 20 +++++++++---------- .../lib_protocol/skip_list_repr.ml | 13 ++++-------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml index fd87602c7fa3..9029244ee8b3 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_repr.ml @@ -1150,17 +1150,15 @@ struct let history = remember cell_ptr inbox history in let deref ptr = Hash.Map.find_opt ptr history.events in let compare hash = - (* TODO: #3321 replace with Lwt_option_syntax when that's in the - environment V6 *) - let ( let* ) x f = - Lwt.(x >>= function None -> return None | Some y -> f y) - in - let result = - let* tree = P.lookup_tree ctxt hash in - let* level = find_level tree in - Lwt.return (Some (Raw_level_repr.compare level l)) - in - Lwt.map (fun x -> Option.value x ~default:(-1)) result + let*! tree = P.lookup_tree ctxt hash in + match tree with + | None -> Lwt.return (-1) + | Some tree -> ( + let open Lwt_syntax in + let+ level = find_level tree in + match level with + | None -> -1 + | Some level -> Raw_level_repr.compare level l) in let* path = option_to_result diff --git a/src/proto_alpha/lib_protocol/skip_list_repr.ml b/src/proto_alpha/lib_protocol/skip_list_repr.ml index ce132734571b..3c333669ac04 100644 --- a/src/proto_alpha/lib_protocol/skip_list_repr.ml +++ b/src/proto_alpha/lib_protocol/skip_list_repr.ml @@ -320,12 +320,7 @@ end) : S = struct equal_ptr first_cell_ptr cell_ptr && valid_path cell_index cell_ptr path let search ~deref ~compare ~cell_ptr = - (* TODO: #3321 replace with Lwt_option_syntax when that's in the - environment V6 *) - let ( let*? ) x f = - match x with None -> Lwt.return None | Some y -> f y - in - let ( let*! ) = Lwt.bind in + let open Lwt_option_syntax in let rec aux path ptr ix = let*? cell = deref ptr in let*? candidate_ptr = back_pointer cell ix in @@ -333,12 +328,12 @@ end) : S = struct let*! comparison = compare candidate_cell.content in if Compare.Int.(comparison = 0) then (* In this case, we have reached our target cell. *) - Option.some_s (List.rev (candidate_ptr :: ptr :: path)) + return (List.rev (candidate_ptr :: ptr :: path)) else if Compare.Int.(comparison < 0) then if Compare.Int.(ix = 0) then (* If the first back pointer is 'too far' ([comparison < 0]), that means we won't find a valid target cell. *) - Option.none_s + fail else (* If a back pointer other than the first is 'too far' we can then backtrack to the previous back pointer. *) @@ -357,6 +352,6 @@ end) : S = struct let*! comparison = compare cell.content in (* We must check that we aren't already at the target cell before starting the recursion. *) - if Compare.Int.(comparison = 0) then Option.some_s [cell_ptr] + if Compare.Int.(comparison = 0) then return [cell_ptr] else aux [] cell_ptr 0 end -- GitLab