Skip to content

Commit

Permalink
Remove ::transformed stuff, not needed; fix ztellman#33
Browse files Browse the repository at this point in the history
  • Loading branch information
camsaul committed Aug 19, 2020
1 parent b0533ee commit 3268bce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
14 changes: 3 additions & 11 deletions src/riddley/walk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
(inline-fn '(+ 1 2)) ; -> #function[clojure.core/nary-inline/fn--5541]
(inline-fn '(+ 1 2)) ; -> nil"
[form]
(when (and (seq? form)
(not (::transformed (meta form))))
(when (seq? form)
(let [[fn-symbol & args] form]
(when (symbol? fn-symbol)
;; a function is inlineable if it has an `:inline` function in its metadata, and, if it has an
Expand All @@ -50,16 +49,9 @@

([form special-form?]
(let [inline-fn (or (inline-fn form)
(throw (ex-info "Form is not an inlineable function call." {:form form})))
expanded (with-meta (apply inline-fn (rest form)) (meta form))]
(throw (ex-info "Form is not an inlineable function call." {:form form})))]
(macroexpand
;; unfortunately, static function calls can look a lot like what we just
;; expanded, so prevent infinite expansion
(if (head= expanded '.)
(with-meta
(concat (butlast expanded) [(merge-meta (last expanded) {::transformed true})])
(meta expanded))
expanded)
(with-meta (apply inline-fn (rest form)) (meta form))
special-form?))))

(defn- expand-list-like
Expand Down
18 changes: 12 additions & 6 deletions test/riddley/walk_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
`(int 1) true
`(n 1) nil
`+ nil
`n nil}
;; any form with `::transformed` in its metadata should always come back as nil
[form expected] [[form expected]
[(with-meta form {:riddley.walk/transformed true}) nil]]]
`n nil}]
(testing (binding [*print-meta* true] (pr-str (list 'inline-fn? form)))
(if expected
(is (fn? (r/inline-fn form)))
Expand All @@ -70,12 +67,12 @@

(deftest expand-inline-fn-test
(is (= '(. clojure.lang.Numbers (and 2 1))
(r/expand-inline-fn '(bit-and 2 1) nil)))
(r/expand-inline-fn '(bit-and 2 1))))
(testing "Should throw an Exception if the form is not inlineable"
(is (thrown-with-msg?
clojure.lang.ExceptionInfo
#"Form is not an inlineable function call"
(r/expand-inline-fn '(+ 1) nil)))))
(r/expand-inline-fn '(+ 1))))))

(deftest test-walk-exprs
;; the first and third numbers get incremented, but not the second
Expand Down Expand Up @@ -223,3 +220,12 @@
(deftest meta-data-on-inline-function-macro-expasion
(is (= {:foo :bar}
(meta (r/macroexpand (with-meta '(+ 1 1) {:foo :bar}))))))

(deftest expand-nested-inline-fn-calls-test
(testing "Nested inlined function calls should get expanded correctly (#33)"
(is (= '(.
clojure.lang.Util
clojure.core/equiv
(. clojure.lang.RT (clojure.core/count [1 2]))
(. clojure.lang.RT (clojure.core/count [3 4])))
(r/macroexpand-all `(= (count [1 2]) (count [3 4])))))))

0 comments on commit 3268bce

Please sign in to comment.