Replies: 14 comments
-
Thanks @krolaw So you suggest only having channels to modify data concurrently. My initial idea was to have a Also the plan is to translate Go code in the future, so this feature may be necessary. |
Beta Was this translation helpful? Give feedback.
-
@medvednikov I saw lock, but it relies on the dev getting it right. Also locks would probably need labels, for sections of different code accessing the same mutable data, and that's getting more complicated. My suggestion hopefully means you can't have a race (like rust). |
Beta Was this translation helpful? Give feedback.
-
Just updating proposal with point 4, which essentially deals with rust's borrowing of mutable data in a way that I think is much simpler. |
Beta Was this translation helpful? Give feedback.
-
@krolaw I like a lot of these concepts but I'm a little fuzzy on number 4. So for the last example the system is doing something along the lines of
If that is the case I don't believe it would generate a compile time error in many cases. But would generate a runtime error. Given the nature of concurrency using any system I don't know we can guarantee the timing. Unless the channel receiver is above the assignment in the same block and the channel is also blocking by default. Which could potentially lead to deadlock under the right circumstances, no? I do not have extensive experience with concurrent programming but these are my initial thoughts. Are channels blocking by default in V? The docs are pretty sparse on concurrency and no mention of channels I could find. |
Beta Was this translation helpful? Give feedback.
-
By the way for # 4 the syntax should be
|
Beta Was this translation helpful? Give feedback.
-
@runimp @medvednikov I've made things a bit more flexible (easier to code) and updated the gist. mut b := 7 |
Beta Was this translation helpful? Give feedback.
-
You don't. For data to be shared you do need pointers. However if b never changes or is read again the compiler can get away with a copy.
mut is an indicator to the compiler. A simple implementation could replace mut with &.
Sorry don't know.
I disagree. I believe the mut keyword is all you need. x := b // x is an immutable copy of b, if b is immutable or never changes after the allocation the compiler could get away with x := &b if it improves performance. Otherwise x := b. So effectively mut is an indicator of sharing intent. Depending what is actually done, the compiler can decide whether pointers should be used. Hope that helps. |
Beta Was this translation helpful? Give feedback.
-
Hi all, It had been bothering me that in order to ensure concurrent safety and flexibility the compiler would have to traverse the entire code tree to assess how a mut variable would be used when passing it into a channel/coroutine. Turns out it is unnecessary as the compiler rejects any mut variables that do not have a path that causes the value to change This simplifies things drastically, as a mut receiver must have a path that changes its value - no need to traverse. Thus the only concurrent rule required is: Any mut variable after being passed to a channel or coroutine's mut receiver, must no longer be accessed (read or write). I'll update the proposal soon. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Discussed with @medvednikov various aspects of mutability. I have updated the gist based on those discussions.
|
Beta Was this translation helpful? Give feedback.
-
I've been reworking channels to support selects, and I think refs may be a mistake. They make sense when used implicity with functions/methods for mutability, but having two (or more) ptrs to the same memory location is going to make "having no undefined behaviour" extremely difficult (in terms of usage rules and compiler implementation) when it comes to coroutines. I'm wondering (beyond implicit function ptrs), if refs are actually that useful anyway and can they simply be done away with? I'm not saying ptrs wouldn't be used by the compiler (for speed), they would, but automatically, especially when "copying" large immutable objects. Or "copying" large mutable objects to immutable objects under certain conditions. How is: Structures with refs and arrays of refs may cost us "no undefined behaviour" or some massive complexity rules or both. So I'm just trying to get a handle on how important they are. Maybe refs can only exist in "unsafe" V code, allowing for importing of C etc, but "safe" v code doesn't allow them? |
Beta Was this translation helpful? Give feedback.
-
@krolaw Regards, |
Beta Was this translation helpful? Give feedback.
-
Pony and V's proposal are essentially the same.
|
Beta Was this translation helpful? Give feedback.
-
@krolaw |
Beta Was this translation helpful? Give feedback.
-
@cristian-ilies-vasile it certainly does not. An immutable variable never becomes mutable. You can take a mutable copy, but that's it. |
Beta Was this translation helpful? Give feedback.
-
I've created a gist drafting how I perceive V could be completely safe using coroutines and without rust complexity, and I've dropped ptrs.
https://gist.github.com/krolaw/000a8bfb72483880a691dcbd00ae4919
Looking for feedback.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions