-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Clarification questions about pointers and struct immutability #40
Comments
Yes
This is a mistake in the docs. Fixed. Thanks :) |
OK, so V must prevent pointers to stack allocated structs from escaping when passed to a function. Is there an attribute e.g. struct S1 { s2 S2*}
fn (mut S1 s1) set_field(s2 @escape S2*) {s1.s2 = s2} |
No
… On 22 Mar 2019, at 12:23, Nick Treleaven ***@***.***> wrote:
Yes
OK, so V must prevent pointers to stack allocated structs from escaping when passed to a function. Is there an attribute e.g. @escape for marking function parameters as escapable (i.e. assigned to a receiver)?
struct S1 { s2 S2*}
fn (mut S1 s1) set_field(s2 @escape S2*) {s1.s2 = s2}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#40 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAp_fF6K7i_Ujt-jEVNB5BctscQJLzmGks5vZL0-gaJpZM4cCnD9>.
|
@medvednikov I presume you mean you don't want an |
No meaning there’s no such feature.
And I don’t have a solution to this problem atm.
… On 22 Mar 2019, at 12:33, Nick Treleaven ***@***.***> wrote:
@medvednikov <https://github.com/medvednikov> I presume you mean you don't want an @escape attribute, and all function parameters can't escape. This seems to work against the nice feature of immutable data that it can be referenced in multiple places (and even across threads) because it doesn't change. But I suppose that requires garbage collection or reference counting for heap allocated immutable data.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#40 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAp_fO7CEpuDZqYcLEPaOK0R8z8S84yPks5vZL9ugaJpZM4cCnD9>.
|
I think V should prevent escapes for now, then later the restriction could be relaxed in certain cases if necessary. Otherwise it will be hard to go the other way and allow escaping now, then break code by imposing a restriction later. I guess the workaround for forcing escapes (that the programmer knows are memory safe) would be to drop into C |
Closing because the original questions were answered. Escaping structs were discussed in another issue. Basically they will behave like in Go. |
Firstly, I think that v looks very promising and succinct!
I have 2 clarification questions, one about pointers and the other about struct immutability.
Structs
subsection:For instance, is it possible to do the following?
mut
keyword can be passed into a receiver which will modify the fields of that struct? For instance, theuser
struct here isn't declared withmut
, and yet its fields get modified by theregister()
method. So then, how would one guarantee that the fields ofuser
do not get modified by any methods? In other words, how is it possible for structs to be "immutable by default:?" Or, am I misunderstanding something about "deep immutability" versus "shallow immutability" here?Thanks for reading!
The text was updated successfully, but these errors were encountered: