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
yes
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
Thanks! That’s good to know.
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.
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.
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?
no difference in how instrumentation is implemented
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.
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.
To use spec.alpha2, do I need to clone the repo? I don't see it in maven-central
it has not yet been released
there are instructions in the readme on how to use it as a git dep
it is still a wip, actively changing, and buggy. you have been warned. :)
understood, thanks!
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
Sounds like a good idea