Closed jjcnn closed 6 years ago
@jjcnn This is not true. Scilla maps are immutable because the implementation of builtin
s for Scilla Map
s ensure that when they are modified, a copy is made. See the comment(s) (* Scilla semantics is not in-place modification. *)
in Builtins.ml
. So if you are seeing a behaviour where it is modified in place, that's a bug and can be fixed by creating a copy as in these places.
share a map between two fields
What is sharing a map between two fields? Can you post an example where you're seeing unintended behaviour?
@vaivaswatha is right. Maps are in fact immutable at the moment because a put
operation makes a copy of the hashtable.
However, this means that the put
operation is linear in the size of the map, and the only way to get around that is to make bindings with maps (let
and bind
) be linear instead.
Based on offline discussion, replace Caml.Hashtbl
implementation with Caml.Map
for Scilla `Map.
Based on offline discussion, here is what should be done:
Hashtbl
to represent Scilla Map
s. Map
s in expressions will continue, i.e., as immutable values.Map
values directly and updating them: v <- m[k]
for reading a field directly and m[k] := v
for updating a field.m[k1][k2] := v
will be valid.Implemented with #290. Closing.
Since OCaml hashtables are mutable, Scilla maps have become mutable since we changed their implementation to use hashtables.
This change comes with a number of problems, chief among them being that this was never the intended behaviour. Also, should one choose to share a map between two fields, that sharing is lost when the transition is over, and the state of the contract is output to a json file.
From a slack conversation between Ilya and myself: