ClojureScript

Clojurescript compiler cannot be AOT compiled

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

With Clojurescript 0.0-1859:

user=> (binding [*compile-files* true] (require 'cljs.analyzer 'cljs.compiler))
nil
user=> (cljs.compiler/with-core-cljs)
AssertionError Assert failed: set! target must be a field or a symbol naming a var
targetexpr  cljs.analyzer/fn--1668 (analyzer.clj:593)

Activity

Hide
David Nolen added a comment -

Is there any more information about what exactly is required or expected? Or hints about what needs to be done to resolve this issue? Thanks!

Show
David Nolen added a comment - Is there any more information about what exactly is required or expected? Or hints about what needs to be done to resolve this issue? Thanks!
Hide
Ambrose Bonnaire-Sergeant added a comment -

The root of this issue seems to be the call to `import-macros` at the top of cljs.core.

Under AOT compilation, the macros are imported as regular functions. This seems to be due to a weird property under AOT where attaching metadata to a var def must be done with alter-meta!, rather than by attaching metadata to the second argument of `def`.

This is a telling symptom:

user=> (binding [*compile-files* true] (require 'cljs.core))
nil
user=> (-> #'cljs.core/when meta :macro)
nil

The patch adds a redundant call to `alter-meta!`.

Behaviour before patch (https://github.com/clojure/clojurescript/commit/070b677a2192912d4f9e933f34c19055b571d101):

user=> (binding [*compile-files* true] (require 'cljs.core))
nil
user=> (require '[cljs [analyzer :as ana] [compiler :as comp] [env :as env]] :verbose)
...
nil
user=> (do (env/ensure (comp/with-core-cljs)) nil)
ExceptionInfo Can't recur here at line 158 file:/home/ambrose/.m2/repository/org/clojure/clojurescript/0.0-SNAPSHOT/clojurescript-0.0-SNAPSHOT.jar!/cljs/core.cljs  clojure.core/ex-info (core.clj:4327)

After patch:

user=> (binding [*compile-files* true] (require 'cljs.core))
nil
user=> (require '[cljs [analyzer :as ana] [compiler :as comp] [env :as env]] :verbose)
(clojure.core/in-ns 'user)
(clojure.core/alias 'ana 'cljs.analyzer)
(clojure.core/in-ns 'user)
(clojure.core/alias 'comp 'cljs.compiler)
(clojure.core/in-ns 'user)
(clojure.core/alias 'env 'cljs.env)
nil
user=> (do (env/ensure (comp/with-core-cljs)) nil)
nil
Show
Ambrose Bonnaire-Sergeant added a comment - The root of this issue seems to be the call to `import-macros` at the top of cljs.core. Under AOT compilation, the macros are imported as regular functions. This seems to be due to a weird property under AOT where attaching metadata to a var def must be done with alter-meta!, rather than by attaching metadata to the second argument of `def`. This is a telling symptom:
user=> (binding [*compile-files* true] (require 'cljs.core))
nil
user=> (-> #'cljs.core/when meta :macro)
nil
The patch adds a redundant call to `alter-meta!`. Behaviour before patch (https://github.com/clojure/clojurescript/commit/070b677a2192912d4f9e933f34c19055b571d101):
user=> (binding [*compile-files* true] (require 'cljs.core))
nil
user=> (require '[cljs [analyzer :as ana] [compiler :as comp] [env :as env]] :verbose)
...
nil
user=> (do (env/ensure (comp/with-core-cljs)) nil)
ExceptionInfo Can't recur here at line 158 file:/home/ambrose/.m2/repository/org/clojure/clojurescript/0.0-SNAPSHOT/clojurescript-0.0-SNAPSHOT.jar!/cljs/core.cljs  clojure.core/ex-info (core.clj:4327)
After patch:
user=> (binding [*compile-files* true] (require 'cljs.core))
nil
user=> (require '[cljs [analyzer :as ana] [compiler :as comp] [env :as env]] :verbose)
(clojure.core/in-ns 'user)
(clojure.core/alias 'ana 'cljs.analyzer)
(clojure.core/in-ns 'user)
(clojure.core/alias 'comp 'cljs.compiler)
(clojure.core/in-ns 'user)
(clojure.core/alias 'env 'cljs.env)
nil
user=> (do (env/ensure (comp/with-core-cljs)) nil)
nil

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: