Skip to content

Commit

Permalink
fix validate-loop-locals for instance-call, minor performance improve…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
Bronsa committed Dec 9, 2013
1 parent 5dd024a commit 5301a03
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

(defn fix-case-test
"If the node is a :case-test, annotates in the atom shared
by the binding and the local node :case-test"
by the binding and the local node with :case-test"
[ast]
(when (:case-test ast)
(swap! (:atom ast) assoc :case-test true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@
(validate-call class method args tag ast :static)))

(defmethod -validate :instance-call
[{:keys [class validated? method tag args] :as ast}]
(if (and class (not validated?))
(validate-call class method args tag ast :instance)
ast))
[{:keys [class validated? method tag args instance] :as ast}]
(let [class (or class (u/maybe-class (:tag instance)))]
(if (and class (not validated?))
(validate-call class method args tag (assoc ast :class class) :instance)
ast)))

(defmethod -validate :import
[{:keys [class validated? env] :as ast}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(ns clojure.tools.analyzer.passes.jvm.validate-loop-locals
(:require [clojure.tools.analyzer.passes :refer [prewalk postwalk]]
[clojure.tools.analyzer.utils :refer [update!]]
[clojure.tools.analyzer.jvm.utils :refer [wider-tag]]))
[clojure.tools.analyzer.jvm.utils :refer [wider-tag maybe-class]]))

(def ^:dynamic ^:private validating? false)
(def ^:dynamic ^:private mismatch? #{})
Expand Down Expand Up @@ -40,14 +40,16 @@
bindings mismatch?)
binds (zipmap bindings (mapv (comp :tag meta) bindings))]
(binding [validating? true]
(postwalk (prewalk (assoc ast key
(mapv (fn [bind f]
(assoc bind :form f))
(key ast) bindings))
(fn [ast]
(assoc-in (dissoc ast :tag :validated? :ret-tag :bind-tag)
[:env :loop-locals-casts] binds)))
analyze)))
(analyze (prewalk (assoc ast key
(mapv (fn [bind f]
(assoc bind :form f))
(key ast) bindings))
(fn [{:keys [op] :as ast}]
(let [ast (assoc-in (dissoc ast :tag :validated? :ret-tag :bind-tag)
[:env :loop-locals-casts] binds)]
(if (= :instance-call op)
(dissoc ast :class)
ast)))))))
ast)))))

(defmethod -validate-loop-locals :loop
Expand Down

0 comments on commit 5301a03

Please sign in to comment.