meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
Lucy Wang 2020-09-30T02:36:31.190400Z

Both CLJ & CLJS tests of GH-141 branch passes on my dev machine.

šŸ‘ 1
noprompt 2020-09-30T03:55:05.191700Z

Thanks Lucy. Iā€™m going to add one more test and then I will merge the branch once it passes CI.

noprompt 2020-09-30T03:55:56.192800Z

Tim, I havenā€™t had a chance to run this against the case you have an open ticket for. Iā€™m hoping Iā€™ll have a chance tonight.

noprompt 2020-09-30T04:05:24.192900Z

I missed this earlier. Yeah, if you can pick that fruit thatā€™d be great.

noprompt 2020-09-30T06:03:39.193200Z

https://clojars.org/meander/epsilon/versions/0.0.502

šŸ‘ 1
noprompt 2020-09-30T06:04:46.194Z

ā˜ļø Fixes the SO from GH-141

noprompt 2020-09-30T06:04:59.194400Z

I donā€™t think this fixes the other SO ticket but I havenā€™t checked yet.

noprompt 2020-09-30T06:06:45.194700Z

Looks like, no, it doesnā€™t.

noprompt 2020-09-30T06:07:04.195100Z

Iā€™ll start investigating it tomorrow.

jimmy 2020-09-30T16:42:44.196600Z

Just pushed the tail recursive non-recur and now the other one doesn't stack overflow with a stack of 512k.

clj -J-Xss512k -Sdeps '{:deps {meander/epsilon {:local/root "."}}}' -e "(require '[meander.epsilon :as m])  (defn z [] (m/rewrite {} (loop* [?seq (clojure.core/seq ?xs) ?chunk nil ?chunkn 0 ?i 0] (if (clojure.lang.Numbers/lt ?i ?chunkn) (let* [(m/and ?sym (m/app always-meta {:tag  ?tag :type ?type})) (.nth ?chunk ?i)] (do ?body (recur ?seq ?chunk ?chunkn (clojure.lang.Numbers/unchecked_inc ?i)))) (let* [?as (clojure.core/seq ?seq)] (if ?as (let* [?bs ?as] (if (clojure.core/chunked-seq? ?bs) (let* [?cs (clojure.core/chunk-first ?bs)] (recur (clojure.core/chunk-rest ?bs) ?cs (clojure.lang.RT/intCast (clojure.lang.RT/count ?cs)) (clojure.lang.RT/intCast 0))) (let* [?sym (clojure.core/first ?bs)] (do ?body (recur (clojure.core/next ?bs) nil 0 0))))))))) (foreach ~(or ?type ?tag) ?sym ?xs (m/app inner-form ?body))))"
If you have lastest meander locally you can run this from its root. I actually tested and with this change 511k is the smallest you can go and still compile it. Any lower it stack overflows.

jimmy 2020-09-30T16:43:39.196800Z

I was hoping something like kondo would give a warning about this. But it doesn't. If anyone knows a tool that can lint non-recur tail recursion, that would be great to find.

jimmy 2020-09-30T17:00:39.197Z

We could probably trampoline walk/prewalk/postwalk and get our stack size much smaller. Obviously with a macroexpansion performance hit.

jimmy 2020-09-30T17:30:05.197200Z

As I'm looking at things, walk seems to be the thing that grows our stack most often. So if we want to reduce it, making some walk that didn't grow the stack would definitely be the approach we should take. Just fyi, default stack of 32bit is 320k default for 64bit is 1024k.

noprompt 2020-09-30T18:19:48.197400Z

Thanks for looking at this!

noprompt 2020-09-30T18:24:17.197600Z

We could trade stack for heap and use a zipper approach but that implies filling in blanks for the usual zipper stuff.

noprompt 2020-09-30T18:26:22.197800Z

I think ref substitution is where we end up eating the most stack.