cljs-dev

p-himik 2025-02-08T13:37:21.795039Z

Originally reported in https://clojurians.slack.com/archives/C03S1L9DN/p1738952860782529. This simple code produces the unreachable code warning when compiling a release build with advanced optimizations and that warning turned on:

(defn my-go []
  (go
    (with-out-str)))

;; results in
WARNING: [...]/out/repro/main.js:134:0: WARNING - [JSC_UNREACHABLE_CODE] unreachable code
  134| return cljs.core.cst$kw$recur;
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Approximately at the reported location, this can be found:
throw ex4057;
return cljs.core.cst$kw$recur;
I have no idea how to properly debug core.async, but this part in cljs.core.async.impl.ioc-macros seems suspicious, specifically the last two lines where :recur ends up being in the code even though the previous line could end up being (throw ~ex):
(defrecord CatchHandler [catches]
  IInstruction
  (reads-from [this] [])
  (writes-to [this] [])
  (block-references [this] (map first catches))
  ITerminator
  (terminate-block [this state-sym _]
    (let [ex (gensym 'ex)]
      `(let [~ex (aget ~state-sym ~VALUE-IDX)]
         (aset-all! ~state-sym ~CURRENT-EXCEPTION ~ex)
         (cond
          ~@(for [[handler-idx type] catches
                  i [(if (= type :default)
                       `true
                       `(instance? ~type ~ex)) ` (aset-all! ~state-sym
                                                           ~STATE-IDX ~handler-idx
                                                           ~CURRENT-EXCEPTION nil)]]
              i)
          :else (throw ~ex))
         :recur))))

dnolen 2025-02-11T02:24:12.177909Z

Hrm I definitely feel like I've seen this one before though it is quite rare. I think I've probably just ignored it since it's doesn't have any real effect and I'm assuming DCE will get rid of it.