This is suggestion for a small feature useful for ad-hoc troubleshooting.
Sometimes it would be useful to be sure that certain variable does not change in certain part of the code and only there. Using const/let/noSideEffect is not handy for this.
proc foo() =
var a = 1
var b = 2
... # a may be modified here
...
block:
# This will ensure that no code until the end of current block
# will modify value of 'a', even through functions called from here
{.untouched:a.}
a = 10 # compiler error
b = 20 # OK, not protected
proc_modifying_a() # compiler error
...
a = 100 # OK, outside of guarded block
Statis check by the compiler won't be be 100% failsafe (aliased pointers, multi-threaded access) but may catch most cases of misuse. In debug mode compiler may also insert a runtime check at the end of guarded block, to catch problems not caught at compile time.
Syntax possibilities:
# None of the 3 variables may be changed from now
{.untouched:[a, b, c].}
# None of global or local variables defined before may be changed from now
{.untouched:*.}
# guard single item through a pointer
{.untouched:ptr_to_obj.item.}
# guard whole object through pointer
{.untouched:ptr_to_obj.*.}
Main use would be ad-hoc troubleshooting. You see (or suspect) that some data gets changed under your nose: you make it "immutable" in critical part of the code and the compiler will hopefully tell where's exactly the problem. Or you can use them as "commnents verified by compiler", as hints for code reviewer or to reduce obsessive NULL checking all over.