From 17c419a15f69b6bf40f4e7f9ad09f00918741a1b Mon Sep 17 00:00:00 2001 From: Sventimir Date: Wed, 30 Mar 2022 18:04:41 +0200 Subject: [PATCH 1/2] Proto/Interpreter: Move kstep function to internals. This function unfortunately must be exported, because it's used by benchmarks. However, not it's exported from Script_interpreter.Internals module, which highlights its internal character --- .../interpreter_workload.ml | 2 +- .../lib_protocol/script_interpreter.ml | 2 ++ .../lib_protocol/script_interpreter.mli | 32 +++++++++---------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml index 43380b2d0c12..638ae6d952a9 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml @@ -1483,7 +1483,7 @@ let extract_deps (type bef_top bef aft_top aft) ctxt step_constants try let res = Lwt_main.run - (Script_interpreter.kstep + (Script_interpreter.Internals.kstep (Some logger) ctxt step_constants diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index a47fa7de1b54..62801877d816 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1885,4 +1885,6 @@ module Internals = struct let step (ctxt, step_constants) gas ks accu stack = internal_step ctxt step_constants gas ks accu stack + + let kstep = kstep end diff --git a/src/proto_alpha/lib_protocol/script_interpreter.mli b/src/proto_alpha/lib_protocol/script_interpreter.mli index c57869e469d0..3f1778cfc4e1 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.mli +++ b/src/proto_alpha/lib_protocol/script_interpreter.mli @@ -132,22 +132,6 @@ val execute_with_typed_parameter : internal:bool -> (execution_result * context) tzresult Lwt.t -(** [kstep logger ctxt step_constants kinstr accu stack] interprets the - script represented by [kinstr] under the context [ctxt]. This will - turn a stack whose topmost element is [accu] and remaining elements - [stack] into a new accumulator and a new stack. This function also - returns an updated context. If [logger] is given, [kstep] calls back - its functions at specific points of the execution. The execution is - parameterized by some [step_constants]. *) -val kstep : - logger option -> - context -> - step_constants -> - ('a, 's, 'r, 'f) Script_typed_ir.kinstr -> - 'a -> - 's -> - ('r * 'f * context) tzresult Lwt.t - (** Internal interpretation loop ============================ @@ -193,4 +177,20 @@ module Internals : sig * Local_gas_counter.local_gas_counter) tzresult Lwt.t + + (** [kstep logger ctxt step_constants kinstr accu stack] interprets the + script represented by [kinstr] under the context [ctxt]. This will + turn a stack whose topmost element is [accu] and remaining elements + [stack] into a new accumulator and a new stack. This function also + returns an updated context. If [logger] is given, [kstep] calls back + its functions at specific points of the execution. The execution is + parameterized by some [step_constants]. *) + val kstep : + logger option -> + context -> + step_constants -> + ('a, 's, 'r, 'f) Script_typed_ir.kinstr -> + 'a -> + 's -> + ('r * 'f * context) tzresult Lwt.t end -- GitLab From 9076e2d29c5bb9f64e103a2c6450d9d9710e3d15 Mon Sep 17 00:00:00 2001 From: Sventimir Date: Thu, 31 Mar 2022 12:14:10 +0200 Subject: [PATCH 2/2] Proto/Interpreter: Move step function to Internals submodule. Rename previously existing step function to avoid name clash. --- .../lib_protocol/script_interpreter.ml | 11 ++++------- .../lib_protocol/script_interpreter.mli | 18 +++++++++--------- .../michelson/test_interpretation.ml | 4 ++-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 62801877d816..276c6a66cc21 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1682,12 +1682,6 @@ let kstep logger ctxt step_constants kinstr accu stack = >>=? fun (accu, stack, ctxt, gas) -> return (accu, stack, update_context gas ctxt) -let internal_step ctxt step_constants gas kinstr accu stack = - step (ctxt, step_constants) gas kinstr KNil accu stack - -let step logger ctxt step_constants descr stack = - step_descr ~log_now:false logger (ctxt, step_constants) descr stack - (* High-level functions @@ -1884,7 +1878,10 @@ module Internals = struct next g gas ks accu stack let step (ctxt, step_constants) gas ks accu stack = - internal_step ctxt step_constants gas ks accu stack + step (ctxt, step_constants) gas ks KNil accu stack + + let step_descr logger ctxt step_constants descr stack = + step_descr ~log_now:false logger (ctxt, step_constants) descr stack let kstep = kstep end diff --git a/src/proto_alpha/lib_protocol/script_interpreter.mli b/src/proto_alpha/lib_protocol/script_interpreter.mli index 3f1778cfc4e1..bd1ddafad9da 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.mli +++ b/src/proto_alpha/lib_protocol/script_interpreter.mli @@ -70,15 +70,6 @@ type step_constants = Script_typed_ir.step_constants = { level : Script_int.n Script_int.num; } -val step : - logger option -> - context -> - Script_typed_ir.step_constants -> - ('a, 's, 'r, 'f) Script_typed_ir.kdescr -> - 'a -> - 's -> - ('r * 'f * context) tzresult Lwt.t - (** [execute ?logger ctxt ~cached_script mode step_constant ~script ~entrypoint ~parameter ~internal] interprets the [script]'s [entrypoint] for a given [parameter]. @@ -178,6 +169,15 @@ module Internals : sig tzresult Lwt.t + val step_descr : + logger option -> + context -> + Script_typed_ir.step_constants -> + ('a, 's, 'r, 'f) Script_typed_ir.kdescr -> + 'a -> + 's -> + ('r * 'f * context) tzresult Lwt.t + (** [kstep logger ctxt step_constants kinstr accu stack] interprets the script represented by [kinstr] under the context [ctxt]. This will turn a stack whose topmost element is [accu] and remaining elements diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml index 2736fa2f42ac..e0a111a7e440 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml @@ -56,9 +56,9 @@ let logger = let run_step ctxt code accu stack = let open Script_interpreter in let open Contract_helpers in - step None ctxt default_step_constants code accu stack + Internals.step_descr None ctxt default_step_constants code accu stack >>=? fun ((_, _, ctxt') as r) -> - step (Some logger) ctxt default_step_constants code accu stack + Internals.step_descr (Some logger) ctxt default_step_constants code accu stack >>=? fun (_, _, ctxt'') -> if Gas.(remaining_operation_gas ctxt' <> remaining_operation_gas ctxt'') then Alcotest.failf "Logging should not have an impact on gas consumption." ; -- GitLab