Skip to content

0.5.3

Compare
Choose a tag to compare
@darwin darwin released this 25 Mar 16:11
· 608 commits to master since this release

Dead code elimination

Originally I didn't anticipate including cljs-devtools into advanced builds because currently custom formatters do not work under advanced optimizations. Until now, my approach in projects including cljs-devtools was to require cljs-devtools only into development builds and completely skip it in advanced builds using modified :source-paths set.

Recently @domkm raised a valid expectation that cljs-devtools should play well with advanced builds:

Advanced compilation is not eliding dead code as I would expect it to. With goog.DEBUG as false, (when ^boolean goog/DEBUG (devtools/install!)) causes cljs-devtools to be included in the advanced build even though that is the only use of cljs-devtools in the project. Any ideas why it's not being elided?

When you:

It could look something like this. Please note that ^boolean hint is important for closure advanced optimizer to clearly understand that the conditional will always evaluate to false:

(if ^boolean goog/DEBUG (devtools/install!))

Alternative method could be to write a simple macro which would emit (devtools/install!) call only if under advanced build (for example there is an environmental property set signalling that).

I'm happy to announce that the above techniques work as expected since v0.5.3. Also I have added tests to ensure this won't break in the future and advanced builds will do full elide in those cases.

Notable commits:

  • e5fad13 fix CLJS-1545
  • 4a93a95 include dead code elimination check as part of standard testing
  • 27503b4 sanity-hints: play well with dead code elimination in :advanced builds
  • 8fd78f9 defonce prevents dead code elimination in :advanced builds
  • cb212d6 dirac: remove exported api