Skip to content
This repository has been archived by the owner on Feb 20, 2020. It is now read-only.

Commit

Permalink
WIP turn off rewrite on fn arities checked >1 times
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Aug 1, 2015
1 parent 66bf163 commit bd4c70c
Showing 1 changed file with 24 additions and 13 deletions.
Expand Up @@ -5,6 +5,7 @@
[clojure.core.typed.contract-utils :as con]
[clojure.core.typed.ast-utils :as ast-u]
[clojure.core.typed.type-ctors :as c]
[clojure.core.typed.utils :as u]
[clojure.core.typed.check.utils :as cu]
[clojure.core.typed.errors :as err]
[clojure.core.typed.parse-unparse :as prs]
Expand Down Expand Up @@ -81,13 +82,11 @@
[mthods {:keys [dom rest drest kws] :as f} opt]
{:pre [((every-pred methods? seq) mthods)
(r/Function? f)]
:post [(methods? %)]}
:post [(every? methods? %)]}
;(prn "check-Function" f)
(let [ndom (count dom)
ms (->> mthods
(map #(maybe-check f % opt))
(filter identity)
vec)]
(let [ms (into []
(keep #(maybe-check f % opt))
mthods)]
;(prn "checked ms" (count ms))
(when (empty? ms)
(binding [vs/*current-expr* (impl/impl-case
Expand All @@ -100,13 +99,13 @@
ms))


(defn check-fni [exp mthods
(defn check-fni [exp mthod
{:keys [recur-target-fn
validate-expected-fn
self-name]
:as opt}]
{:pre [(function-type? exp)
(methods? mthods)
(method? mthod)
(opt-map? opt)]
:post [(methods? %)]}
;(prn "check-fni" exp)
Expand Down Expand Up @@ -134,9 +133,9 @@
(mapcat (fn [f]
{:pre [(r/Function? f)]
;returns a collection of fn-method's
:post [(methods? %)]}
:post [(every? methods? %)]}
(check-Function
mthods
mthod
f
{:recur-target-fn recur-target-fn}))
(:types fin))))))]
Expand Down Expand Up @@ -171,6 +170,18 @@
(prs/with-unparse-ns (cu/expr-ns (first mthods))
(err/tc-delayed-error (str (prs/unparse-type expected) " is not a function type")
:return []))
(vec
(mapcat (fn [t] (check-fni t mthods opt))
ts)))))
;; Need to know:
;; 1) Each intersection arity is covered by at least one fn arity
;; 2) If a fn arity is checked more than once, then disable rewriting
;; for that arity.
(u/rewrite-when (== 1 (count ts))
(mapv
(fn [t]
(mapv (fn [m]
(check-fni t m opt))
mthods))
ts)

(vec
(mapcat (fn [t] (check-fni t mthods opt))
ts))))))

0 comments on commit bd4c70c

Please sign in to comment.