Skip to content
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

Wrong expansion of inlined forms inside other inlined forms #33

Open
camsaul opened this issue Aug 19, 2020 · 1 comment · May be fixed by #34
Open

Wrong expansion of inlined forms inside other inlined forms #33

camsaul opened this issue Aug 19, 2020 · 1 comment · May be fixed by #34

Comments

@camsaul
Copy link

camsaul commented Aug 19, 2020

I ran into this issue:

(riddley.walk/macroexpand-all `(= (count [1 2]) (count [3 4])))
;; -> 
(.
 clojure.lang.Util
 clojure.core/equiv
 (. clojure.lang.RT (clojure.core/count [1 2]))
 (clojure.core/count [3 4]))

Note the the = form and the first count form are expanded correctly, but the second count form is not expanded.

Macroexpanding the form generated by the inlined call to = seems to work:

(riddley.walk/macroexpand-all ((-> #'= meta :inline) '(count [1 2]) '(count [3 4])))

(.
 clojure.lang.Util
 clojure.core/equiv
 (. clojure.lang.RT (clojure.core/count [1 2]))
 (. clojure.lang.RT (clojure.core/count [3 4])))

It also seems to work correctly if I replace the calls to count with calls to macros that simply expand to calls to count:

(defmacro my-count [& args]
  `(count ~@args))

(rw/macroexpand-all `(= (my-count [1 2]) (my-count [3 4])))
;; ->
(.
 clojure.lang.Util
 clojure.core/equiv
 (. clojure.lang.RT (clojure.core/count [1 2]))
 (. clojure.lang.RT (clojure.core/count [3 4])))

This doesn't seem to affect every inlined function:

(riddley.walk/macroexpand-all '(+ (count [1]) (count [2])))
;; -> 
(.
 clojure.lang.Numbers
 (add (. clojure.lang.RT (clojure.core/count [1])) (. clojure.lang.RT (clojure.core/count [2]))))
@camsaul
Copy link
Author

camsaul commented Aug 19, 2020

I think this has something to do with Riddley marking the second call to count as :transformed:

(binding [*print-meta* true]
  (pr (riddley.walk/macroexpand-all '(= (count [1 2]) (count [3 4])))))
->
;; (line/col metadata removed for clarity)
(. 
 clojure.lang.Util
 clojure.core/equiv
 (. clojure.lang.RT (clojure.core/count [1 2]))
 ^{:riddley.walk/transformed true} (count [3 4]))

camsaul added a commit to camsaul/riddley that referenced this issue Aug 19, 2020
camsaul added a commit to camsaul/riddley that referenced this issue Aug 19, 2020
@camsaul camsaul linked a pull request Aug 19, 2020 that will close this issue
camsaul added a commit to camsaul/riddley that referenced this issue Aug 19, 2020
camsaul added a commit to camsaul/riddley that referenced this issue Aug 19, 2020
camsaul added a commit to camsaul/riddley that referenced this issue Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant