From 5a78dfcd0d99be1ad9ab1b8c67d1e8d6e6485c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Kr=C3=BCger?= Date: Tue, 25 Oct 2022 13:28:10 +0100 Subject: [PATCH] SCORU: WASM: Clean up Internal_for_benchmark functions --- src/lib_scoru_wasm/bench/exec.ml | 10 ++--- src/lib_scoru_wasm/bench/pvm_instance.ml | 9 +++++ src/lib_scoru_wasm/bench/pvm_instance.mli | 4 ++ src/lib_scoru_wasm/bench/scenario.ml | 7 +--- src/lib_scoru_wasm/wasm_pvm.ml | 12 ------ src/lib_scoru_wasm/wasm_pvm.mli | 3 ++ src/lib_scoru_wasm/wasm_pvm_sig.ml | 46 ----------------------- src/lib_scoru_wasm/wasm_vm.mli | 12 ++++++ 8 files changed, 33 insertions(+), 70 deletions(-) diff --git a/src/lib_scoru_wasm/bench/exec.ml b/src/lib_scoru_wasm/bench/exec.ml index bbe8e6544244..81317742264f 100644 --- a/src/lib_scoru_wasm/bench/exec.ml +++ b/src/lib_scoru_wasm/bench/exec.ml @@ -26,7 +26,6 @@ open Test_scoru_wasm_test_helpers open Tezos_scoru_wasm open Wasm_pvm_state.Internal_state -open Pvm_instance type phase = Decoding | Initialising | Linking | Evaluating | Padding [@@deriving show {with_path = false}] @@ -44,8 +43,7 @@ let should_continue phase (pvm_state : pvm_state) = | Initialising, Init _ -> true | Linking, Link _ -> true | Decoding, Decode _ -> true - | Evaluating, Eval _ - when Wasm.Internal_for_benchmark.eval_has_finished pvm_state.tick_state -> + | Evaluating, Eval _ when Wasm_vm.eval_has_finished pvm_state.tick_state -> false | Evaluating, Eval _ -> true | Padding, Eval _ -> true @@ -54,12 +52,10 @@ let should_continue phase (pvm_state : pvm_state) = Lwt.return continue let finish_top_level_call_on_state pvm_state = - Wasm.Internal_for_benchmark.compute_step_many_pvm_state - ~max_steps:Int64.max_int - pvm_state + Wasm_vm.compute_step_many ~max_steps:Int64.max_int pvm_state let execute_on_state phase state = - Wasm.Internal_for_benchmark.compute_step_many_until_pvm_state + Wasm_vm.compute_step_many_until ~max_steps:Int64.max_int (should_continue phase) state diff --git a/src/lib_scoru_wasm/bench/pvm_instance.ml b/src/lib_scoru_wasm/bench/pvm_instance.ml index c41398f36b88..f60e0c818423 100644 --- a/src/lib_scoru_wasm/bench/pvm_instance.ml +++ b/src/lib_scoru_wasm/bench/pvm_instance.ml @@ -30,6 +30,15 @@ module Tree = Test_encodings_util.Tree module Tree_encoding_runner = Test_encodings_util.Tree_encoding_runner module Wasm = Wasm_utils.Wasm +let encode_pvm_state state tree = + Tree_encoding_runner.encode + Tezos_scoru_wasm.Wasm_pvm.pvm_state_encoding + state + tree + +let decode_pvm_state tree = + Tree_encoding_runner.decode Tezos_scoru_wasm.Wasm_pvm.pvm_state_encoding tree + let get_tick_from_tree tree = let open Lwt_syntax in let* info = Wasm.get_info tree in diff --git a/src/lib_scoru_wasm/bench/pvm_instance.mli b/src/lib_scoru_wasm/bench/pvm_instance.mli index d2ad67730f2c..23174a799576 100644 --- a/src/lib_scoru_wasm/bench/pvm_instance.mli +++ b/src/lib_scoru_wasm/bench/pvm_instance.mli @@ -31,6 +31,10 @@ module Wasm : Tezos_scoru_wasm.Wasm_pvm_sig.S with type tree = Context.tree open Tezos_scoru_wasm open Wasm_pvm_state +val encode_pvm_state : Internal_state.pvm_state -> Wasm.tree -> Wasm.tree Lwt.t + +val decode_pvm_state : Wasm.tree -> Internal_state.pvm_state Lwt.t + val get_tick_from_tree : Wasm.tree -> Z.t Lwt.t val get_tick_from_pvm_state : Internal_state.pvm_state -> Z.t Lwt.t diff --git a/src/lib_scoru_wasm/bench/scenario.ml b/src/lib_scoru_wasm/bench/scenario.ml index 74a5703c7ebc..5da4108557e6 100644 --- a/src/lib_scoru_wasm/bench/scenario.ml +++ b/src/lib_scoru_wasm/bench/scenario.ml @@ -133,17 +133,14 @@ let exec_phase run_state phase = let exec_loop tree_run_state = let open Lwt_syntax in let* pvm_run_state = - switch_state_type - Wasm.Internal_for_benchmark.decode - "Decode tree" - tree_run_state + switch_state_type decode_pvm_state "Decode tree" tree_run_state in let* pvm_run_state = Exec.run_loop exec_phase pvm_run_state in let* tree_run_state = switch_state_type (fun state -> (* the encode function takes the _previous_ tree encoding as argument *) - Wasm.Internal_for_benchmark.encode state tree_run_state.state) + encode_pvm_state state tree_run_state.state) "Encode tree" pvm_run_state in diff --git a/src/lib_scoru_wasm/wasm_pvm.ml b/src/lib_scoru_wasm/wasm_pvm.ml index 47a270e0e546..5833e22aa2d0 100644 --- a/src/lib_scoru_wasm/wasm_pvm.ml +++ b/src/lib_scoru_wasm/wasm_pvm.ml @@ -251,18 +251,6 @@ module Make (T : Tezos_tree_encoding.TREE) : let* pvm_state = Wasm_vm.reveal_step payload pvm_state in encode pvm_state tree - module Internal_for_benchmark = struct - let decode = decode - - let encode = encode - - let compute_step_many_until_pvm_state = Wasm_vm.compute_step_many_until - - let compute_step_many_pvm_state = Wasm_vm.compute_step_many - - let eval_has_finished = Wasm_vm.eval_has_finished - end - module Internal_for_tests = struct let get_tick_state tree = let open Lwt_syntax in diff --git a/src/lib_scoru_wasm/wasm_pvm.mli b/src/lib_scoru_wasm/wasm_pvm.mli index 9f481fbfaa2c..5cf75212f13b 100644 --- a/src/lib_scoru_wasm/wasm_pvm.mli +++ b/src/lib_scoru_wasm/wasm_pvm.mli @@ -24,6 +24,9 @@ (* *) (*****************************************************************************) +val pvm_state_encoding : + Wasm_pvm_state.Internal_state.pvm_state Tezos_tree_encoding.t + val durable_buffers_encoding : Tezos_webassembly_interpreter.Eval.buffers Tezos_tree_encoding.t diff --git a/src/lib_scoru_wasm/wasm_pvm_sig.ml b/src/lib_scoru_wasm/wasm_pvm_sig.ml index ff1d565ef399..f0b9fa78d70f 100644 --- a/src/lib_scoru_wasm/wasm_pvm_sig.ml +++ b/src/lib_scoru_wasm/wasm_pvm_sig.ml @@ -25,50 +25,6 @@ (*****************************************************************************) open Wasm_pvm_state -(** This module type expose internals necessary for benchmarking. - - /!\ Not intended for unit tests: the functions could be used to redefine the - main execution loop, at the risk of departing from what is defined in the - PVM definition. [Internal_for_benchmark.compute_step_many_until] can use - custom stopping condition and therefore should not be used in unit test: - the test could hide regression if the condition change in the code, but not - in the test. *) -module type Internal_for_benchmark = sig - open Internal_state - - type tree - - val decode : tree -> pvm_state Lwt.t - - val encode : pvm_state -> tree -> tree Lwt.t - - (** [compute_step_many_until_pvm_state max_step should_continue pvm_state] - advance forwards the VM in the same manners as [compute_step_many] - as long as [should_continue] returns true. - - Returns the new state and number of the executed ticks. - - IS applied on [pvm_state] rather than a tree. - - /!\ as it allows to redefine the stop condition, this function should - not be used in unit test: the test could hide regression if the - condition change in the code, but not in the test. - *) - val compute_step_many_until_pvm_state : - ?max_steps:int64 -> - (pvm_state -> bool Lwt.t) -> - pvm_state -> - (pvm_state * int64) Lwt.t - - (** [compute_step_many_pvm_state max_step pvm_state] - advance forwards the VM in the same manners as [compute_step_many] - *) - val compute_step_many_pvm_state : - max_steps:int64 -> pvm_state -> (pvm_state * int64) Lwt.t - - val eval_has_finished : tick_state -> bool -end - module type Internal_for_tests = sig open Internal_state @@ -111,8 +67,6 @@ module type S = sig function may raise an exception. *) val get_output : output_info -> tree -> string option Lwt.t - module Internal_for_benchmark : Internal_for_benchmark with type tree := tree - module Internal_for_tests : Internal_for_tests with type tree := tree end diff --git a/src/lib_scoru_wasm/wasm_vm.mli b/src/lib_scoru_wasm/wasm_vm.mli index e396075705a3..f2335c29e289 100644 --- a/src/lib_scoru_wasm/wasm_vm.mli +++ b/src/lib_scoru_wasm/wasm_vm.mli @@ -27,6 +27,18 @@ open Wasm_pvm_state.Internal_state include Wasm_vm_sig.S +(** [compute_step_many_until max_step should_continue pvm_state] + advance forwards the VM in the same manners as [compute_step_many] + as long as [should_continue] returns true. + + Returns the new state and number of the executed ticks. + + IS applied on [pvm_state] rather than a tree. + + /!\ as it allows to redefine the stop condition, this function should + not be used in unit test: the test could hide regression if the + condition change in the code, but not in the test. + *) val compute_step_many_until : ?max_steps:int64 -> (pvm_state -> bool Lwt.t) -> -- GitLab