I’m wanting to learn how to work on Clojure itself. I’ve got IntelliJ (without Cursive) set up to work with the java codebase but now I want to know how people work on the Compiler itself. I’m interested to hear experiences and resources about
- general overview of how the compiler works
- how to set up workflow to create artifacts and test them
- how to get a repl running in the Clojure codebase so you can quickly interact
- how to profile the results of changes
I’m reading lots of tickets in Jira and git commits but its still quite a lot. Just wondering what people here have done to get involved. Thanks.
Unfortunately, there are few resources about how the compiler works. I wish it were otherwise (but wishing does not create time to change that). There are a few good intro conference talks about it (https://www.youtube.com/watch?v=8NUI07y1SlQ, https://www.youtube.com/watch?v=2SGFeegEt9E come to mind) and I think some of the tools.analyzer talks and resources are good intros too (https://www.youtube.com/watch?v=KhRQmT22SSg). The Clojure compiler is, however, intentionally not very complicated.
Re workflow, there are instructions for build and test in several ways in the readme: https://github.com/clojure/clojure/blob/master/readme.txt (shocking I know :). Just mvn clean install is enough to build a deploy a snapshot version with your local changes that you can use from other projects.
You can use that jar in a repl with just clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.0-master-SNAPSHOT"}}}'. (Note that right now snapshot deps are only retrieved from Maven daily, so you’ll need to remove from ~/.m2/repository/org/clojure/clojure/… then add -Sforce to force a re-load (this is something I expect to fix in clj soon).)
Another option is to set up a deps.edn right in the clojure project itself (I do this for some stuff) that looks like this:
{:deps
{org.clojure/clojure {:mvn/version "1.10.0-alpha7"}
org.clojure/test.check {:mvn/version "0.9.0"}
criterium {:mvn/version "0.4.4"}}
:aliases
{:dbg {:classpath-overrides {org.clojure/clojure "target/classes"}}}}
Then use clj -A:dbg to run a Clojure repl.
And then another another way to do it is to connect a Clojure repl via an IDE (I do this via Cursive). That’s useful because you can actually walk across both Java and Clojure code.
I typically use Criterium to profile changes with the bench or quick-bench functions.