Skip to content
Permalink
Browse files

add allow-top-level-non-IFn flag for generating specs

  • Loading branch information...
frenchy64 committed Jun 18, 2019
1 parent 55c054f commit 2213641a3afeea0fde4b2565973428c3f59f9867
@@ -744,7 +744,7 @@
(assoc done-sdefs a e))))))))


(defn envs-to-specs [env {:keys [spec-macros] :as config}]
(defn envs-to-specs [env {:keys [spec-macros allow-top-level-non-IFn] :as config}]
;(prn "envs-to-specs" (keys (alias-env env)))
(let [should-spec-macros? (boolean spec-macros)
trim-type-env #?(:clj
@@ -762,10 +762,15 @@
;; top level def's are functions, which breaks spec instrumentation.
;; We work around this behaviour by simply
;; omitting non-function specs.
(not (#{:IFn} (:op v))))))
(if allow-top-level-non-IFn
false
(not (#{:IFn} (:op v)))))))
%)
:cljs identity)
;_ (prn "pre env" env)
env (update-type-env env trim-type-env)
;_ (prn "allow-top-level-non-IFn" allow-top-level-non-IFn)
;_ (prn "env" env)
env (implicit-aliases-for-env env config)
aliases-generated (atom #{})]
(binding [*envs* (atom env)]
@@ -2648,7 +2648,8 @@
(symbol (name k))
;; imports
k)
(unparse-type (assoc v :top-level-def k)))]
(unparse-type
(assoc v :top-level-def k)))]
(when polymorphic?
(prn "polymorphic?" polymorphic? k)
(let [call-ids (get call-flows k)]
@@ -19,17 +19,20 @@
var-path
key-path
fn-rng-path
fn-dom-path]]
[clojure.core.typed.annotator.track :refer [track-var]]
fn-dom-path]
:as rep]
[clojure.core.typed.annotator.track :refer [track-var] :as track]
[clojure.core.typed.annotator.join :refer [make-Union
join*
join-HMaps
join]]
[clojure.core.typed.annotator.env :as env]
[clojure.core.typed.annotator.frontend.spec :refer [unparse-spec'
envs-to-specs]]
[clojure.core.typed.annotator.insert :refer [delete-generated-annotations-in-str
generate-ann-start
generate-ann-end]]
generate-ann-end]
:as insert]
[clojure.core.typed.annotator.util :refer [*ann-for-ns*
spec-ns
current-ns
@@ -1075,6 +1078,43 @@
(with-out-str (instrument-top-level-form '(do (def a "a") (println a))))
"a\n")))

(defn code-to-gen-spec [root-ns root-key samples {:keys [spec?] :as config}]
(binding [*ns* *ns*]
(in-ns root-ns)
(binding [*ns* (the-ns root-ns)
*ann-for-ns* #(the-ns root-ns)
unparse-type (if spec?
unparse-spec'
unparse-type')]
(let [results-atom (atom (env/initial-results))
;instrument and track
_ (run!
(fn [e]
(track/track
(track/gen-track-config)
results-atom
e
#{[(rep/var-path root-ns root-key)]}
#{}))
(concat (map eval (:eval samples))
(:edn samples)))
_ (prn @results-atom)
infer-out
(infer/infer-anns root-ns
{:spec? spec?
:allow-top-level-non-IFn true
:results-atom results-atom})
_ (prn "infer out" infer-out)
spec-out
(apply insert/prepare-ann
((juxt :requires :top-level :local-fns) infer-out))]
spec-out))))


(deftest manual-track-test
(is (code-to-gen-spec 'user 'user/foo-bar {:eval '[(inc 1)] :edn '[a]}
{:spec? true})))

(declare *-from-infer-results)

;TODO remove # suffixes

0 comments on commit 2213641

Please sign in to comment.
You can’t perform that action at this time.