-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Borrowing for var T
and lent T
to improve Nim's memory safety
#7373
Comments
First param only sounds a bit unfinished. Also I feel like I'm also talking a lot about FP but: iterator mzip(container1: var seq[C1], container2: var seq[C2]): (var C1, var C2) =
... also |
I'm not sure what type
SeqHolder = object
data: seq[int]
proc foo(x: SeqHolder): var int =
return x.data[0] My initial thoughts are that the sequence slots can be indeed treated as part of the Otherwise, I don't see how limiting the borrow checker to a single param makes things easier. Looks like the job will be only slightly harder when more locations are involved. |
It's not about ease of implementation. It's about how to make the existing |
Since globals live forever, taking their address is always safe. So |
This proposal finally solves issue #124 by a simple borrow checking rule: A return type of
var T
is assumed and enforced to be a view into the location reachable by the first parameter of the proc.Every known usage of
var T
in the standard library is derived from the first parameter. Other code likewill fail to compile. Furthermore the analysis needs to forbit mutating operations on the collection for as long as the
var T
views are "borrowed". Sincelet x = returnsVarT(collection)
conceptually turns the pointer view into a copy, this borrow check should be rather easy to enforce. I hope.Let us see how this outlined borrowing rule solves #124:
Future directions
Later versions can be more precise with a syntax like
The text was updated successfully, but these errors were encountered: