Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

spytheman
Copy link
Member

@spytheman spytheman commented Jan 29, 2023

Fix #17077 .

@spytheman spytheman marked this pull request as draft January 29, 2023 19:09
@ghost
Copy link

ghost commented Jan 29, 2023

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

@MatejMagat305
Copy link
Contributor

MatejMagat305 commented Feb 2, 2023

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?

@JalonSolov
Copy link
Contributor

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
Copy link
Contributor

JalonSolov commented Feb 2, 2023

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

@yuyi98 yuyi98 closed this Feb 20, 2023
@yuyi98 yuyi98 reopened this Feb 20, 2023
@spytheman spytheman added the Needs Rebase The code of the PR must be rebased over current master before it can be approved. label Mar 6, 2023
@spytheman spytheman force-pushed the remove_auto_ref_passing_on_structs_bigger_than_8_fields branch from 54c263c to 151c1df Compare March 11, 2023 09:09
… reference (too complex/unpredictable, with little benefit)
@spytheman spytheman force-pushed the remove_auto_ref_passing_on_structs_bigger_than_8_fields branch from 151c1df to 687fe2b Compare June 21, 2023 09:54
@spytheman spytheman added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). and removed Needs Rebase The code of the PR must be rebased over current master before it can be approved. labels Jun 21, 2023
@spytheman spytheman added the Needs Rebase The code of the PR must be rebased over current master before it can be approved. label Aug 21, 2023
@JalonSolov
Copy link
Contributor

Any thoughts on finishing this one?

@yuyi98
Copy link
Member

yuyi98 commented Sep 8, 2023

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?

@JalonSolov
Copy link
Contributor

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.

@spytheman
Copy link
Member Author

Any thoughts on finishing this one?

Yes, I am working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Rebase The code of the PR must be rebased over current master before it can be approved. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rule that all structures with more than 8 fields are always passed as reference in methods should be removed
7 participants