Fork me on GitHub
#clojure-spec
<
2020-04-30
>
bbrinck02:04:08

I noticed that instrumentation doesn’t work for certain core functions. Is this related to the inline metadata?

(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as st])
(s/fdef clojure.core/count :args (s/cat :coll coll?))
(s/fdef clojure.core/reverse :args (s/cat :coll coll?))
(st/instrument ['clojure.core/count 'clojure.core/reverse])
    
(reverse 1) ; gives spec error
(count 1) ; gives non-spec error

Alex Miller (Clojure team)03:04:09

you will also find that adding specs to core functions will not be checked in calls from one core function to another as core is compiled with direct linking

bbrinck15:04:15

Thanks! That’s good to know.

bbrinck15:04:57

The reason why the “inline” limitation comes up is I’m thinking about ways to use instrumentation to help provide some different error messages when using core functions, but this means that some functions cannot be instrumented.

bbrinck15:04:09

I wonder if there’s a way around this. I can also see how many functions are actually inlined. Maybe it’s not a huge amount in practice.

bbrinck15:04:38

I may be misremembering, but I seem to remember some mention of spec2 instrumentation changing things. Do you have any idea if this inline limitation will remain in the new instrumentation?

Alex Miller (Clojure team)15:04:54

no difference in how instrumentation is implemented

bbrinck15:04:26

OK, thanks. A quick search in clojure.core indications about 85 cases of :inline. Maybe it’s not a huge deal to just skip those functions or maybe there’s a non-instrumentation-based way to help with errors. I’ll think more.

Alex Miller (Clojure team)15:04:28

the biggest thing to be concerned about is probably performance. Some of the tests they did with https://github.com/borkdude/speculative made instrumented core pretty much unusable.

👀 4
bbrinck17:04:55

Agreed. I tried instrumentation on my test suite and it was way too slow. I have an idea about a different way to instrument that might be better wrt performance (basically by only doing spec checking if there is an error) but the inline limitation will require some additional thinking

Alex Miller (Clojure team)18:04:17

Sounds like a good idea

Frank Henard16:04:38

To use spec.alpha2, do I need to clone the repo? I don't see it in maven-central

Alex Miller (Clojure team)16:04:23

it has not yet been released

Alex Miller (Clojure team)16:04:42

there are instructions in the readme on how to use it as a git dep

👍 4
Alex Miller (Clojure team)16:04:25

it is still a wip, actively changing, and buggy. you have been warned. :)

Frank Henard16:04:52

understood, thanks!