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

Implement =move and =sink operators (destructors) #150

Closed
mratsim opened this issue Nov 8, 2017 · 2 comments
Closed

Implement =move and =sink operators (destructors) #150

mratsim opened this issue Nov 8, 2017 · 2 comments

Comments

@mratsim
Copy link
Owner

mratsim commented Nov 8, 2017

Move operator =move (for a and b being var T) and =sink (for a being var T and b being T) were introduced in master and are described in Araq's pointer-free programming blog post.

Using those should allow value semantics i.e. let a = b; a[1] = 0 does not change the value of b[1] with the efficiency of reference semantics i.e. every slice, =, reshape is a view of the same data.

  • Value semantics is safe but makes it easy to trigger useless memory allocation.
  • Reference semantics is fast but makes it easy to shoot yourself in the foot.
  • =move and =sink promise the best of both world with the compiler autodetecting when it's safe to move (reference semantics) or copy (value semantics).

This also would have the tremendous benefits of making "unsafe" proc much less mandatory for general users. (They would still be used inside Arraymancer to mutate slices for example).

Related issues memory allocation: #46, #141, #23, #19, #104, #89, #121

Edit, support is opt-in via the new compilation flag --newruntime

@mratsim mratsim changed the title Use =move and =sink operator for no-copy value semantics (destructors) Implement =move and =sink operators (destructors) Nov 26, 2017
@mratsim mratsim added easy and removed key feature labels Nov 26, 2017
@mratsim
Copy link
Owner Author

mratsim commented Nov 26, 2017

With #160 data is not copied anymore, metadata is on the stack and cheap to copy so not a key feature anymore.

@mratsim
Copy link
Owner Author

mratsim commented Mar 14, 2018

Latest developments on destructors in Nim are documented here.

There is a new lent type that will probably be useful to implement immutable views. (inverse of Rust borrows).

Removing the easy tag because I don't think it's easy anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant