-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Make copy / reference semantics more explicit #2435
Comments
Would a unitary symbol against the variable be better to indicate assignment by reference rather than introduce a new assignment symbol?
|
I think something like The |
This is also a question when passing variables of differing location as function arguments (as this came up on yesterday's weekly call). Instead of considering C++'s
|
I would like to open the discussion on this again. As mentioned earlier, an different assignment symbol is not sufficient, because we also need to consider passing data along function calls. My proposal would be that reference types are always assigned and passed by reference by default. If this is not possible (because it is an assignment to storage or from storage to memory or across function calls), an rvalue can be turned into an rvalue of "copyable type" by using This will result in rather verbose syntax for external function calls. An alternative would be to use a symbol instead of an actual function call (i.e. Another alternative would be to perform copies by default and make references explicit. I think this is not as good because it could result in too many unnecessary (and unnoticed) copy operations. |
I think always passing by reference by default and requiring a In theory the verbosity could be decreased by just having |
I agree with @ekpyron |
What about value types? They are copied all the time, so I would assume that a copy operator is not required. We might also think about using a copy operator instead of a function: |
Note that with this, the expression |
These days I'm most in favour of using an operator called |
Open question: Do we also require |
@axic was suggesting If we use the operator without parentheses, the precedence has to be determined. Next step would be to take a look at some contracts and see how they would look like. |
Implicit copy operations from storage to memory, from calldata to memory, from memory to external function arguments, etc is not possible anymore except for value types.
To make an ordinary value copyable, use the
copyof
operator:x
cannot be copied, butcopyof x
can be copied. Usingcopyof
twice is invalid. Storing a copyable type somewhere erases the copyable property again, i.e.uint[] memory x = copyof y; c.f(x);
is invalid.The text was updated successfully, but these errors were encountered: