That is very handwavy. Falling back to copying implies either relying on compile-time escape analysis (which is often pessimistic and fails across boundaries) or introducing unexpected pointer comparisons at runtime. Neither of those are desirable or expected in systems code.
Also an additional problem that, as far as I’ve seen, wasn’t talked about at all in this thread is multithreaded code. It’s not unreasonable to assume that code exists that operates on things as values where concurrent threads are updating the “original”. With a normal mutex operation this will likely rarely happen, but this is Zig and you can (and should be able to) do anything you please. And other synchronization methods where this would lead to issues are easily possible to create and also widely used. I haven’t looked into it but intuitively lock free stuff and also something like a seqlock could suffer from this.
Other problems I can think of are (1) the then missing consistency of generics, where you might need to explicitely handle cases for types larger than some processor dependent threshold, for which the reason is entirely hidden and can easily be forgotten because, at least I, wouldn’t think about how this thing I’m programming could be used in all possible ways while writing some code. And (2) the already non-stable ABI which Zig has is then even more brittle and making it even harder to allow things like this. (3) The ability for any code to write assembly, which is largely a black box to the compiler and with that especially to some part of the frontend, and expect something to be passed by value. (4) Being able to patch the code that is running at runtime - I don’t need to say more about this one I think.
It also violates the key thing that for me Zig stands for is that the amount of implicit things is reduced to the necessary minimum[1].
$ zig zen | sed -n '2p;4p;10p'
* Communicate intent precisely.
* Favor reading code over writing code.
* Reduce the amount one must remember.
I believe something like this just doesn’t belong at all into a close to the hardware language that allows complete control over the executed code.
But not the absolute minimum as this would be very awkward. ↩︎