v
v copied to clipboard
v: remove the automatic passing of structs with more than 8 fields by reference (too complex/unpredictable, with little benefit)
Fix #17077 .
@spytheman, thank you for your willingness to change complex and old features. Let's make less unpredictable behavior.
I"m only asking: this cause that in the compiler of vlang have to be rewrite all place where is (mut some_complicate_struct) fn_n(...) to reference versions?
Well, no, it will just pass those complicated structs on the stack. You only need to change the code if you want them to be passed as references, instead of it "magically" being done for you.
Or, in other words, it will always be "pass by value" now, instead of sometimes pass by value, and sometimes pass by reference. If you want pass by reference, you have to manually add the &
.
Any thoughts on finishing this one?
Can the receiver of the method have only two modes, fn (mut f Foo) and fn (f Foo), and the second can only be passing by reference mode, canceling passing by value mode?
fn (f Foo)
would be pass by value, since it wouldn't be modifiable. fn (mut f Foo)
or fn (&f foo)
would be pass by reference.
Any thoughts on finishing this one?
Yes, I am working on it.