You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When lambdas close over some external environment variable, if that
variable is a linear value, their environment becomes the owner of the
captured value and the value will be freed with the environment. If the
lambda moves this variable out of its own scope, however, e.g. by
returning it in its body, both the caller and the lambda environment
will wind up owning the value, resulting in double frees.
For now, we prevent this scenario by simply disallowing functions to
leak variables captured from another scope. Doing so is now an error. Of
course, one can still copy these values without issue.
We achieve this through set operations. If the memory state loses the
fake deleters for the set of a lambdas captured bindings after its body
is evaluated, we've encountered an ownership leak, and report an error.
```clojure
(defn example []
(let [capture @""
lambda (fn [] capture)])) ;; this is now an error
(defn example []
(let [capture @""
lambda (fn [] @&capture)])) ;; this is still OK
```
fixescarp-lang#1040
0 commit comments