IMO, this one is very important and should be in our list of work for
foreseeable future. I am happy both with write effect and explicit args types
approaches. Can't really say which one is better. There is still intersection
with sideeffects though. Changes to ref content is a side effect,.
IMO, this how the above example types should look like, notice a lent keyword
is used:
proc select(a, b: Node): lent Node =
result = if oracle(): a else: b
proc construct(a, b: Node): Node =
result = Node(data: "new", le: a, ri: b)
proc harmless(a, b: Node) =
var x = construct(a, b)
x.data = "mutated"
proc harmful(a, b: Node) =
var x = select(a, b)
x.data = "mutated" # doesn't compile, x is lent
proc construct2(a: Node): Node =
result = a # doesn't compile, a is not mutable. Either change return type
to `lent Node` or make argument `a` mutable
Run
P.S. If the proposed notations where good enough for backend to rely on them to
determine what can alias and what can't this would really great and improve
performance as well.