v icon indicating copy to clipboard operation
v copied to clipboard

v: remove the automatic passing of structs with more than 8 fields by reference (too complex/unpredictable, with little benefit)

Open spytheman opened this issue 2 years ago • 8 comments

Fix #17077 .

spytheman avatar Jan 29 '23 19:01 spytheman

@spytheman, thank you for your willingness to change complex and old features. Let's make less unpredictable behavior.

walkingdevel avatar Jan 29 '23 19:01 walkingdevel

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?

MatejMagat305 avatar Feb 02 '23 20:02 MatejMagat305

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.

JalonSolov avatar Feb 02 '23 21:02 JalonSolov

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 &.

JalonSolov avatar Feb 02 '23 21:02 JalonSolov

Any thoughts on finishing this one?

JalonSolov avatar Sep 08 '23 02:09 JalonSolov

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?

yuyi98 avatar Sep 08 '23 07:09 yuyi98

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.

JalonSolov avatar Sep 08 '23 09:09 JalonSolov

Any thoughts on finishing this one?

Yes, I am working on it.

spytheman avatar Sep 08 '23 20:09 spytheman