proteus
proteus copied to clipboard
Bump to latest riddley (0.1.7)
This is a fix for #3 - potentially the wrong one, but bumping riddley can't hurt, right?
The actual issue: letfn
isn't having its locals registered as part of the letfn*
transformation, so its bindings aren't visible to the analyzer inside nested let
expressions. So swallowing analysis errors as riddley 0.1.7 gets this use case working, but I'm assuming the right fix is to register locals for letfn
.
In digging into a potential locals-registering solution, my quicky & easy (but dirty, poking at internals) idea:
diff --git a/src/proteus.clj b/src/proteus.clj
index 7eadb2e..d73b710 100644
--- a/src/proteus.clj
+++ b/src/proteus.clj
@@ -50,7 +50,9 @@
vs' (map #(gensym (name %)) vs)]
`(let [~@(interleave vs' vs)
~@(interleave vs (map read-form vs))]
- (~'letfn* ~bindings
+ (~'letfn* ~(#'riddley.walk/let-bindings
+ transform-let-mutable-form
+ bindings)
(let [~@(interleave vs vs')]
~(transform-let-mutable-form `(do ~@body))))))
didn't work, got a java.lang.UnsupportedOperationException: Can't type hint a primitive local
.
Surprisingly (to me), inlining the implementation of let-bindings
seemed to do the trick:
diff --git a/src/proteus.clj b/src/proteus.clj
index 7eadb2e..39b1c98 100644
--- a/src/proteus.clj
+++ b/src/proteus.clj
@@ -50,7 +50,14 @@
vs' (map #(gensym (name %)) vs)]
`(let [~@(interleave vs' vs)
~@(interleave vs (map read-form vs))]
- (~'letfn* ~bindings
+ (~'letfn* ~(->> bindings
+ (partition-all 2)
+ (mapcat
+ (fn [[k v]]
+ (let [[k v] [k (transform-let-mutable-form v)]]
+ (riddley.compiler/register-local k v))
+ [k v]))
+ vec)
(let [~@(interleave vs vs')]
~(transform-let-mutable-form `(do ~@body))))))
But that seemed pretty awful, and might not even be necessary - I don't have a full mental model of the consequences of analysis errors in this context.