redplanetlabs / specter

Clojure(Script)'s missing piece
Apache License 2.0
2.53k stars 105 forks source link

Warnings #97

Closed galdolber closed 8 years ago

galdolber commented 8 years ago

I'm getting the following warnings:

WARNING: Use of undeclared Var cljs.js/eval-fn at line 52 resources/public/_/com/rpl/specter/impl.cljs WARNING: cljs.js/_eval-fn* not declared ^:dynamic at line 52 resources/public/_/com/rpl/specter/impl.cljs WARNING: Use of undeclared Var cljs.js/eval-fn* at line 52 resources/public/**/com/rpl/specter/impl.cljs WARNING: Use of undeclared Var cljs.js/eval-fn* at line 52 resources/public/**/com/rpl/specter/impl.cljs WARNING: Use of undeclared Var cljs.js/js-eval at line 52 resources/public/_/com/rpl/specter/impl.cljs WARNING: Use of undeclared Var cljs.js/eval-fn at line 52 resources/public//com/rpl/specter/impl.cljs WARNING: Use of undeclared Var cljs.js/eval at line 53 resources/public//com/rpl/specter/impl.cljs WARNING: Use of undeclared Var cljs.js/empty-state at line 53 resources/public//com/rpl/specter/impl.cljs WARNING: Use of undeclared Var cljs.js/empty-state at line 53 resources/public/**/com/rpl/specter/impl.cljs

Dependencies: [org.clojure/clojure "1.9.0-alpha4"] [org.clojure/clojurescript "1.9.14"] [com.rpl/specter "0.11.0"]

nathanmarz commented 8 years ago

These were due to some code inserted specially to enable Specter to work in bootstrap. I was able to get rid of most of the warnings with this commit: https://github.com/nathanmarz/specter/commit/c1d9dff75e63d3a6e7f20854e88aab21f0894f53

However, one warning still persists:

WARNING: cljs.js/*eval-fn* not declared ^:dynamic at line 51 target/classes/com/rpl/specter/impl.cljs

@mfikes Any ideas on how to get rid of that warning? I tried changing the metadata on that symbol to ^{:dynamic true :cljs.analyzer/no-resolve true} to no avail.

mfikes commented 8 years ago

@nathanmarz It's not immediately obvious how to eliminate that warning. Scratching my head trying to think through this one...

nathanmarz commented 8 years ago

@mfikes: What if that code used push-thread-bindings/pop-thread-bindings manually? Is that even possible in bootstrap? What about a couple calls to alter-var-root?

mfikes commented 8 years ago

@nathanmarz Interesting. Actually, set! appears to do the trick.

(defn macroexpand'
  [form]
  (let [orig-eval-fn ^:cljs.analyzer/no-resolve cljs.js/*eval-fn*]
    (try
      (set! ^:cljs.analyzer/no-resolve cljs.js/*eval-fn* ^:cljs.analyzer/no-resolve cljs.js/js-eval)
      (^:cljs.analyzer/no-resolve cljs.js/eval (^:cljs.analyzer/no-resolve cljs.js/empty-state)
        `(macroexpand (quote ~form))
        identity)
      (finally
        (set! ^:cljs.analyzer/no-resolve cljs.js/*eval-fn* orig-eval-fn)))))

The above doesn't appear to cause any warnings to be emitted when evaluated in a regular ClojureScript REPL. If you call the function, it will work if cljs.js has been required. Additionally, I tried it within Planck and it works.

In short, I think set! is conceptually close to what you were suggesting with push-thread-bindings / pop-thread-bindings and alter-var-root.

nathanmarz commented 8 years ago

@mfikes: Thanks for looking into this – this is now committed to master.