Uploaded image for project: 'Clojure'
  1. CLJ-322

Enhance AOT compilation process to emit classfiles only for explicitly-specified namespaces


    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Declined
    • Affects versions: None
    • Fix versions: None
    • Labels:
    • Patch:
      Code and Test


      Why This Was Declined

      The current behavior of transitive compilation is a valuable semantic. It is arguably essential to e.g. AOT protocols ahead of their call sites.

      On the other hand, you should not ship AOT compiled classes for which your project is not the source. As worded in the original ticket:
      "Having the option of shipping either all AOT-compiled classfiles or mixed source/AOT depending upon one's distribution requirements would make that phase of work with a clojure codebase significantly easier and less error-prone."

      This latter goal can be accomplished by keeping "what you compile" and "what you ship" cleanly separate. The compiler does not know or care about the latter, and tools can automate this with e.g. boot's sift.

      Historical Context

      This was originally/erroneously reported by Howard Lewis Ship in the clojure-contrib assembla:

      My build file specifies the namespaces to AOT compile but if I include another namespace
      (even from a JAR dependency) that is not AOT compiled, the other namespace will be compiled as well.
      In my case, I was using clojure-contrib's clojure.contrib.str-utils2 namespace, and I got a bunch of
      clojure/contrib/str_utils2 classes in my output directory.
      I think that the AOT compiler should NOT precompile any namespaces that are transitively reached,
      only namespaces in the set specified by the command line are appropriate.
      As currently coded, you will frequently find unwanted third-party dependencies in your output JARs;
      further, if multiple parties depend on the same JARs, this could cause bloating and duplication in the
      eventual runtime classpath.

      The only question in my mind is what the default should be. We're all used to the current behaviour, but I'd guess that any nontrivial project where the form of the distributable matters (i.e. the source/AOT mix), providing as much control as possible by default makes the most sense. Given the tooling that most people are using, it's trivial (and common practice, IIUC) to provide a comprehensive list of namespaces one wishes to compile, so making that the default shouldn't be a hurdle to anyone. If an escape hatch is desired, a --transitive switch to clojure.lang.Compile could be added.




            • Assignee:
              cemerick Chas Emerick
            • Votes:
              18 Vote for this issue
              16 Start watching this issue


              • Created: