The following is just kinda thinking out loud, do not pay much attention.
Ok, we have 4 variants for parameter passing:
- I):
fn f(arg: const T), copy value and do not allow to change the copy.
This is what Zig is currently doing, but… with some peculiarities:
constmodifier is implicit, not good- compiler may decide to pass by reference anyway, also not good, despite the semantic is preserved
_
- II)
fn f(arg: T), copy value and allow to change the copy
Are there any cases at all when changing the copy can be a footgun?.. It (the copy) does not exist after returning from a function, what can go wrong?..
- III)
fn f(arg: *T), pass a reference and allow to mutate the pointee. - IV)
fn f(arg: *const T), pass a reference and do not allow to mutate the pointee.
Variants III and IV are absolutely clear. Variants I/II (with implicit const or even *const) are not, 'arg: T' may sometimes mean 'arg: const T' and sometimes 'arg: *const T'.