parameterize navigators immediately if all params are constant (rather than factor)

This commit is contained in:
Nathan Marz 2016-08-06 00:44:40 -04:00
parent 56da47aca5
commit b9cd024c38

View file

@ -677,6 +677,18 @@
([] (must-cache-paths! true)) ([] (must-cache-paths! true))
([v] (set-cell! MUST-CACHE-PATHS v))) ([v] (set-cell! MUST-CACHE-PATHS v)))
(defn constant-node? [node]
(cond (record? node) false
(number? node) true
(keyword? node) true
(string? node) true
(vector? node) (every? constant-node? node)
(set? node) (every? constant-node? node)
(map? node) (and (every? constant-node? (vals node))
(every? constant-node? (keys node)))
:else false
))
(defn- extract-original-code [p] (defn- extract-original-code [p]
(cond (cond
(instance? LocalSym p) (:sym p) (instance? LocalSym p) (:sym p)
@ -881,14 +893,12 @@
(magic-fail! "Var " (:sym op) " is dynamic") (magic-fail! "Var " (:sym op) " is dynamic")
(cond (cond
(or (root-params-nav? vv) (instance? ParamsNeededPath vv)) (or (root-params-nav? vv) (instance? ParamsNeededPath vv))
;;TODO: if all params are constants, then just bind the path right here (if (every? constant-node? ps)
;;otherwise, add the params (apply vv ps)
;; - could extend this to see if it contains nested function calls which (do
;; are only on constants (swap! params-atom #(vec (concat % ps)))
(do (coerce-path vv)
(swap! params-atom #(vec (concat % ps))) ))
(coerce-path vv)
)
(and (fn? vv) (-> v meta :pathedfn)) (and (fn? vv) (-> v meta :pathedfn))
;;TODO: update this to ignore args that aren't symbols or have :nopath ;;TODO: update this to ignore args that aren't symbols or have :nopath
@ -927,13 +937,14 @@
)) ))
(and (fn? vv) (-> vv meta :layerednav)) (and (fn? vv) (-> vv meta :layerednav))
(do (if (every? constant-node? ps)
;;TODO: if all args are constant then invoke it right here (apply vv ps)
(swap! params-atom conj (:code p)) (do
(if (= (-> vv meta :layerednav) :lean) (swap! params-atom conj (:code p))
lean-compiled-path-proxy (if (= (-> vv meta :layerednav) :lean)
rich-compiled-path-proxy lean-compiled-path-proxy
)) rich-compiled-path-proxy
)))
:else :else
(magic-fail! "Var " (:sym op) " must be either a parameterized " (magic-fail! "Var " (:sym op) " must be either a parameterized "