[go: up one dir, main page]

Env: Array module

Context

On top of !6040 (merged), only review last commit.

Arrays are used in the protocol (in the Plonk code). In V6 (and in V7 prior to this MR) it uses a submodule that includes just enough Array to get along.

This MR introduces an Array module in the environment. It includes only a few functions. For the truly dangerous functions (e.g., set which does side-effects 😱) it has a value `Some_error_message_here. If the function is used in the protocol, it leads to a somewhat readable error message. E.g.,

File "src/proto_alpha/lib_protocol/sampler.ml", line 163, characters 11-32:
163 |   let () = [| "foo" |].(3) <- ""
                 ^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type
         [ `You_cannot_modify_array_content_in_the_protocol ]
       This is not a function; it cannot be applied.
  • Should we keep those error-message values? Or should we just omit the values altogether?
    • Note that the syntax .()<- cannot be removed, but it is desugared to Array.set by the compiler which can be removed. Maybe we should keep the error-message value just for set so that the syntax doesn't lead to Unbound value Array.set?
  • Suggestions on the error messages welcome too

Manually testing the MR

Use unsafe array expressions in the environment. Check that you get an error during compilation.

Merge request reports

Loading