Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed May 31, 2024
1 parent bef1660 commit 35bd938
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
{:added "1.0"}
[& body]
`(io.github.frenchy64.fully_satisfies.safe_locals_clearing.Delay.
;; FIXME I think this defeats locals clearing. maybe a linter is needed instead
;; since we just need to disallow recur
(^{:once true} fn* [] (let* [res# (do ~@body)] res#))))

;;TODO unit test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@
(testing "recur target is exposed"
(let [f identity
d (cc/delay (f 1) (recur))]
(is (thrown? NullPointerException @d)))))
(is (thrown? NullPointerException @d)))
;;
(let [f identity
self (promise)
d (clojure.lang.Delay. (^:once fn* [] (let* [res (do (f 1))] @self)))]
(deliver self d)
(is @d))))

(deftest safe-test
(is (cc/delay? (safe/delay)))
Expand All @@ -68,45 +74,42 @@
d (safe/delay (f) @@p)]
(deliver p d)
(is (thrown-with-msg? Exception #"Recursive delay dereference" @d))))
(testing "doesn't seem to clear local here, maybe because n is a long"
(binding [*atom* (atom [])]
(let [n 1
self (promise)
d (safe/delay
(swap! *atom* conj n)
(when-not *recursive*
(binding [*recursive* true]
@@self))
n)]
(deliver self d)
(is (thrown-with-msg? Exception #"Recursive delay dereference" @d))
(is (= [1] @*atom*)))))
(testing "doesn't seem to clear local here, maybe because n is a long"
(binding [*atom* (atom [])]
(let [n identity
self (promise)
d (safe/delay
(swap! *atom* conj n)
(when-not *recursive*
(binding [*recursive* true]
@@self))
n)]
(deliver self d)
(is (thrown-with-msg? Exception #"Recursive delay dereference" @d))
(is (= [n] @*atom*)))))
(testing "clears f, seemingly because we invoked it"
(binding [*atom* (atom [])]
(let [f #(do nil)
self (promise)
d (safe/delay
(swap! *atom* conj f)
(f)
(when-not *recursive*
(binding [*recursive* true]
@@self)))]
(deliver self d)
(is (thrown-with-msg? Exception #"Recursive delay dereference" @d))
(is (= [f] @*atom*)))))
(binding [*atom* (atom [])]
(let [n 1
self (promise)
d (safe/delay
(swap! *atom* conj n)
(when-not *recursive*
(binding [*recursive* true]
@@self))
n)]
(deliver self d)
(is (thrown-with-msg? Exception #"Recursive delay dereference" @d))
(is (= [1] @*atom*))))
(binding [*atom* (atom [])]
(let [n identity
self (promise)
d (safe/delay
(swap! *atom* conj n)
(when-not *recursive*
(binding [*recursive* true]
@@self))
n)]
(deliver self d)
(is (thrown-with-msg? Exception #"Recursive delay dereference" @d))
(is (= [n] @*atom*))))
(binding [*atom* (atom [])]
(let [f #(do nil)
self (promise)
d (safe/delay
(swap! *atom* conj f)
(f)
(when-not *recursive*
(binding [*recursive* true]
@@self)))]
(deliver self d)
(is (thrown-with-msg? Exception #"Recursive delay dereference" @d))
(is (= [f] @*atom*))))
(testing "recur target is hidden"
(is (thrown? clojure.lang.Compiler$CompilerException
(eval `(safe/delay (recur)))))))

0 comments on commit 35bd938

Please sign in to comment.