core-typed

Typed Clojure, an optional type system for Clojure
2020-06-04T01:34:45.017800Z

for anyone interested in reusing some of Typed Clojure's infrastructure for their own type system, https://www.patreon.com/posts/example-type-37870230 shows how to use its analyzer.

2020-06-04T08:02:39.018Z

@borkdude No idea if this could be useful to the type checking in clj-kondo or not, but in case you don't monitor this channel, and it might be useful.

borkdude 2020-06-04T12:55:50.018300Z

thanks!

2020-06-05T01:20:56.022300Z

@borkdude if you ever find yourself wanting to partially expand something, it'll probably be useful. I think you use rewrite-clj right? my analyzer is intended for the use-case where you use tools.analyzer, but you need to check intermediate steps.

borkdude 2020-06-05T10:14:53.024700Z

tools.analyzer is not suited for clj-kondo, it doesn't work with GraalVM unfortunately

2020-06-05T14:12:42.024900Z

oh interesting. my analyzer is a distinct entity from tools.analyzer (w/ no transitive dependency on it), do you know what the issues are? I might be able to fix them.

borkdude 2020-06-05T14:24:16.025100Z

I think one issue was that tools.analyzer did macroexpansion which effectively uses eval and eval uses dynamic classloading which is not supported by GraalVM

2020-06-05T14:42:39.025400Z

welp

2020-06-05T14:43:25.025600Z

well, that's bad news 😞

borkdude 2020-06-05T14:43:40.025800Z

It's basically why I wrote a clojure interpreter 😉

borkdude 2020-06-05T14:44:42.026Z

I'm working on a new macroexpand feature in clj-kondo that will be using this interpreter, so it can all still run in the native binary: https://clojureverse.org/t/feedback-wanted-on-new-clj-kondo-macroexpansion-feature/6043 feedback on that is most welcome

2020-06-05T14:49:12.026300Z

nice. I've thought a lot about this kind of thing. in typed clojure, the analyzer can return an ::unanalyzed AST node, and then custom rules can be registered about how to type check a particular macro.

2020-06-05T14:50:37.027100Z

I haven't figured out how to properly handle macros that bind variables, but I would go in the direction of extending a type environment and passing that down, rather than your sketch of expanding to a let (FWIW).

borkdude 2020-06-05T14:51:57.027300Z

the clj-kondo approach is not only about validating a macro. it's foremost about expanding since it can't do that without eval. but since the user provides the code that macroexpands, it can do all kinds of checking on it as well and throw an exception. I'll probably let the user return an :findings vector too.

borkdude 2020-06-05T14:52:45.027500Z

potentially the expand function could get access to locals, etc too. that's why the function signature is a map to a map, to allow for more stuff in the future

2020-06-05T14:53:31.027700Z

yea cool that sounds right to me

2020-06-05T14:54:12.027900Z

I like this direction. does your interpreter expose a macroexpand-1 function?

borkdude 2020-06-05T14:55:39.028100Z

it does:

$ bb "(defmacro foo [x] (list 'do x x)) (macroexpand-1 '(foo 1))"
(do 1 1)

borkdude 2020-06-05T14:55:51.028300Z

(bb = babashka which uses the same interpreter)

2020-06-05T14:56:53.028500Z

ah interesting. can you rebind tools.analyzer's macroexpand-1 with that?

borkdude 2020-06-05T14:59:08.028700Z

you mean, like, alter-var-root?

2020-06-05T15:00:05.029300Z

it has its own macroexpand-1

2020-06-05T15:00:40.029500Z

that's the direction I was thinking, I'm sure there's a ton of other details

2020-06-05T15:01:54.029700Z

(for graalvm + tools.analyzer compat)

borkdude 2020-06-05T15:02:10.029900Z

I think this boils down to the reason why clj-kondo doesn't just run the code from a user's source file: because it has to be pure clojure, no references to other namespaces or particular Java classes, protocols, etc

2020-06-05T15:02:51.030100Z

yea ok

2020-06-05T15:05:57.030300Z

appreciate your time and insight!

borkdude 2020-06-05T15:17:57.030500Z

likewise!