The main ticket I think needs to be at least assessed is https://clojure.atlassian.net/projects/CLJS/issues/CLJS-3170
ah right ok - I think the others, esp. externs inference we'll leave for a follow up
Inference regression related to Closure Library analysis: https://clojure.atlassian.net/browse/CLJS-3189
thanks
Thanks for the fix!
yep
unless anything else comes up I think that's it - let's shoot for Monday release
I've unleashed Canary on master
Release notes updated for a Monday release https://github.com/clojure/clojurescript-site/pull/332
have a couple questions re: type inference.
1. what’s the best way to infer the type of a form when writing a macro? e.g. if I’m walking a form and come across (foo :bar)
, what’s the best way to ask the analyzer the potential return type? Docs would be helpful!
2. What’s the best way to annotate my functions or macros in order to get better type inference? Are there any docs on what’s supported / best practices?
Canary's green âś…
@lilactown you shouldn't have to do anything
and in fact I would discourage being interested in the details unless you're going to work on making it better 🙂
I would like to help with making it better as well
most of these changes are about faster code w/ zero work
no user level code changes at all
but there are parts of some library code I’m writing that would benefit from leveraging type inference to generate faster code
@lilactown Kevin Lynagh has explored this space
oh right, I forgot about that. he did that with hiccup parsing
(This stuff https://kevinlynagh.com/notes/fast-cljs-react-templates/)
I am happy to give an overview of how canary->release works here https://clojurescript.org/community/dev once I understand it (maybe under https://clojurescript.org/community/patches). Would be a good place to set expectations (remind contributors this is oss and folks have day jobs) for how patches might (or might not) get to production.
unless it is already described somewhere? I might have a blind spot!
cljs.analyzer/infer-tag
(got it from reading his hicada fork’s source code) was what I was looking for. thanks!
Yeah, his stuff ended up using private API (an experiment, really)
is there any public API for it yet?
No... ilk
also uses similar private API FWIW
i’ll use ilk for now in the hopes that when a public API gets released it will get updated :<
FWIW the kinds of optimizations I want to do:
(let [props (merge {:foo "bar"} {:baz 42})]
(dom/div props "foo"))
and the dom/div
macro can infer that props
is a map
another optimization, with React hooks:
(let [click-handler (fn [e] (js/alert "hi"))]
if a macro could infer that the right-hand side (fn ...)
is a function type, and rewrite it to wrap in a useCallback
:
(let [click-handler (react/useCallback (fn [e] (js/alert "hi")) #js [])]
which would preserve identity of the function across renders, allowing for other optimizationsI’m not sure if all cases can be inferred right now that I’m interested in, but I’d like to help get there if I can