ClojureScript

User supplied type hints stopped working on js/goog.DEBUG which means DCE can fail

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: 1.9.655
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

Description

Somewhere between version 1.9.293 and 1.9.456 the type hint "^boolean" stopped working for "js/goog.DEBUG" and, as a result, this expression silently stopped being a functioning DCE guard in ":advanced" compilations.

So this code example no longer "works" (in the sense that DCE doesn't happen anymore):

(when ^boolean js/goog.DEBUG 
   ... some dev-time code in here which we want to Dead Code Eliminate at prod-time)

Note: if the guard condition is changed to use "^boolean goog.DEBUG" (no leading "js/") then it does work. So the leading "js/" is a problem.

thheller speculates that this bug arose during the introduction of :infer-externs
https://github.com/clojure/clojurescript/commit/0560106fe8576fd7029d86e61be09cd1f246bfe0

Some discussion in slack:
https://clojurians-log.clojureverse.org/cljs-dev/2017-05-04.html

I have created a minimal repo which demonstrates the problem:
https://github.com/mike-thompson-day8/CLJS-issue-2023

Activity

Hide
Thomas Heller added a comment -

This can be reproduced by running cljs.analyzer.api/analyze on (with-meta 'js/goog.DEBUG {:tag 'boolean}).

{:form ^boolean js/goog.DEBUG,
 :op :var,
 :info
 {:name ^boolean js/goog.DEBUG,
  :ns js,
  :tag ^{:prefix [goog DEBUG]} js},
 :tag ^{:prefix [goog DEBUG]} js}

Running a quick git bisect the :tag changed from boolean to js in this commit:
https://github.com/clojure/clojurescript/commit/0560106fe8576fd7029d86e61be09cd1f246bfe0

Show
Thomas Heller added a comment - This can be reproduced by running cljs.analyzer.api/analyze on (with-meta 'js/goog.DEBUG {:tag 'boolean}).
{:form ^boolean js/goog.DEBUG,
 :op :var,
 :info
 {:name ^boolean js/goog.DEBUG,
  :ns js,
  :tag ^{:prefix [goog DEBUG]} js},
 :tag ^{:prefix [goog DEBUG]} js}
Running a quick git bisect the :tag changed from boolean to js in this commit: https://github.com/clojure/clojurescript/commit/0560106fe8576fd7029d86e61be09cd1f246bfe0
Hide
António Nuno Monteiro added a comment -

Attached patch with fix and test.

Show
António Nuno Monteiro added a comment - Attached patch with fix and test.

People

Vote (2)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: