On Tue, Jan 15, 2019 at 10:43 PM Didier <didi...@gmail.com> wrote: > Okay, I found my issue, mostly. > > It seems that Clojure 1.9 and 1.10 both now have a > clojure.core.specs.alpha.clj file. > > This file seems to be the only file that is not AOT compiled by the maven > compile script for Clojure. Thus the Jar for Clojure only has it as source, > and is missing the .classes for it. > > We have custom Ant tasks to compile Clojure, where we call compile-ns > ourselves on our source namespaces. > > I was using Clojure 1.9 in our Ant tasks, which meant that as part of > running compile-ns on our namespace, because they depend on Clojure core as > well, clojure.core.specs.alpha.clj from the Clojure 1.9 jar was also being > compiled. > > Thus, our project jar now contained the 1.9 classes for core specs. > > Now, we would use Clojure 1.10 to run our project, but the Clojure 1.9 > core specs fail to validate amp-impl of Clojure 1.10. I'm guessing it was > changed along with its spec inside core specs. > > So we were getting a weird syntax error at runtime for every namespace > that depend on clojure.core. > > I have a few questions based on this: > > 1) Why is clojure.core.specs.alpha.clj the only thing not AOT compiled in > the Clojure jar? >
clojure.core.specs.alpha is actually not part of Clojure proper, it's in the dependencies. We don't compile the specs as we would then be bound to a particular version of the spec.alpha dependency. We wanted it to be possible to bump those versions but not have to be binary-compatible. (And this is exactly the issue you're seeing - binary incompatibility of compiled specs between versions.) There are actually a few other namespaces in Clojure itself that are not AOT compiled because they are conditionally included, or for other reasons. Some of these special cases went away in Clojure 1.10 due to the bump in minimum JDK which removed a lot of the special cases. > > 2) I realized that I probably shouldn't compile Clojure 1.10 code with > Clojure 1.9, and I bumbed our Ant code to use Clojure 1.10, and that fixed > it. So what are the compiler compatibility? Can newer Clojure versions > compile older Clojure code? Is it only two version back? Is this tested? Or > should I always use equal versions to compile? Is forward compatibility a > thing? Etc. > I'm not sure you've accurately described the scenario here. In general, we don't guarantee binary compatibility between versions of Clojure, however, we do make every effort to maintain stability of the interfaces that compiled Clojure classes rely on inside the language (all the Java core like RT, etc). However, I don't think the problem here is with Clojure itself, it's with spec. What you're seeing are specs compiled with one version of spec.alpha, then being run with a different version of spec.alpha. We have not been trying to maintain binary compatibility for compiled specs (and have not been compiling the core.specs to avoid this being an issue). Protocols tend to be particularly problematic in this area (the spec interface is a protocol), so that's a complicating factor here. > 3) Is compile-ns transitive? I was surprised to see that it also compiles > clojure.core.specs.alpha. > Yes. When compilation is on, it transitively compiles every namespace loaded. 4) Isn't it a bit strange that if I AOT compile my code, my Jar gets .class > files from Clojure core as well? Even though I don't get the error anymore, > I still have clojure.core.specs.alpha classes from my jar on the classpath, > and the source from Clojure on it as well. > Yes, it's one of the downsides of AOT. This has been discussed for a long time (see https://dev.clojure.org/jira/browse/CLJ-322 for example). Having both source and classes is totally fine - Clojure prefers the class file, but there are issues (particularly with protocols) in having classes that depend on source files. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.