Skip to end of metadata
Go to start of metadata

Problem

The Clojure and ClojureScript readers do not currently track the column number when reading forms, only line numbers.

((juxt :line :column) (meta #'identity)) => [1351 nil]

Several components could be improved by tracking column information:

  • Compiler error messages
  • Tooling, such as SLIME or IDEs (consider jump-to-definition)

However, the key motivator is Source Maps for ClojureScript. The development tools in modern browsers have growing support for graphical debugging of machine generated code. This is relevant for minified JavaScript, but it's also intended for use with multi-stage transformations, such as CoffeeScript/GWT/ClojureScript -> Unoptimized Javascript -> Google Closure Compiler -> Final JavaScript

Solution

Patches Clojure's LispReader and other components of the compiler: http://dev.clojure.org/jira/browse/CLJ-960

ClojureScript's reader will need a similar patch, but that's not required to enable SourceMaps.

Labels:
  1. Aug 29, 2012

    I'm curious if you've done any profiling to see how this affects compilation time (particularly AOT) of larger Clojure projects.

    1. Aug 29, 2012

      I haven't measured it, but I doubt the impact is noticeable. I don't have a large Clojure project with AOT to test against. Does the compiler have an existing performance test suite of any kind?

      Skim the patch, you'll see that it's a pretty straight forward transformation of gets/sets to line fields and the LINE Var to include parallel column fields and COLUMN Var.

      Alternatively, I could have made a Position object representing a Line/Column pair, but avoided that because it 1) Would requiring changing more code 2) Would incur an allocation cost (unlikely to be an issue). My concern here is that, given the pace of Clojure tickets, the patch would grow stale. Any parallel patches that read LINE would be breaking, unless we maintained those vars for compatibility. If I can get commitment to getting a column patch in, I'd be willing to do the cleaner Position thing. However, my preference would be to expend that effort towards moving more parts of the compiler to being self-hosted Clojure.