clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
bbrinck 2020-04-30T02:24:08.300800Z

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

alexmiller 2020-04-30T03:52:19.301Z

yes

alexmiller 2020-04-30T03:54:09.301700Z

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

bbrinck 2020-04-30T15:16:15.302500Z

Thanks! That’s good to know.

bbrinck 2020-04-30T15:20:57.305700Z

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.

bbrinck 2020-04-30T15:22:09.307300Z

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.

bbrinck 2020-04-30T15:23:38.309200Z

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?

alexmiller 2020-04-30T15:23:54.309500Z

no difference in how instrumentation is implemented

bbrinck 2020-04-30T15:33:26.311400Z

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.

alexmiller 2020-04-30T15:39:28.312200Z

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.

1👀
ballpark 2020-04-30T16:18:38.313500Z

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

alexmiller 2020-04-30T16:20:23.313700Z

it has not yet been released

alexmiller 2020-04-30T16:20:42.314200Z

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

1👍
alexmiller 2020-04-30T16:21:25.315100Z

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

ballpark 2020-04-30T16:21:52.315400Z

understood, thanks!

bbrinck 2020-04-30T17:58:55.317100Z

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

alexmiller 2020-04-30T18:16:17.317500Z

Sounds like a good idea