rewrite-clj

https://github.com/clj-commons/rewrite-clj
lread 2021-03-09T19:17:10.031500Z

Welcome @holyjak šŸ‘‹ !

ā¤ļø 1
Jakub HolĆ½ 2021-03-09T19:19:03.034200Z

Thank you! After @borkdude's praise I could not not check out #rewrite-clj :)

lread 2021-03-09T19:19:20.034500Z

Itā€™s a pretty cool library for sure!

lread 2021-03-09T19:22:44.036700Z

I think I am pretty much ready to merge the clj-commons/rewrite-clj v1 branch to main. After that, Iā€™ll work toward getting a release up on clojars. Before I do the merge anybody want to review the https://github.com/clj-commons/rewrite-clj/blob/v1/CHANGELOG.adoc#rewrite-clj-v1? Iā€™m looking for anything that makes you think, ā€œuh oh, that will be a problemā€.

ā¤ļø 2
Jakub HolĆ½ 2021-03-09T19:23:09.037300Z

Do I understand correctly you are rewriting #rewrite-clj? šŸ˜¹

lread 2021-03-09T19:25:05.039100Z

Oh ha! Thatā€™s very meta! I do use rewrite-clj to generate rewrite-cljā€™s public APIs. Which is fun.

šŸ”„ 1
vemv 2021-03-09T19:33:56.039700Z

I could try these changes, maybe on the weekend? An alpha would help. I have a rewrite-clj program that used/hacked things for getting namespaced keyword support. It could be a useful report, verifying if I was able to update rewrite-clj->rewrite-cljc with only moderate pain (I do expect at least some little surprise due to my hacking)

borkdude 2021-03-09T19:45:16.040100Z

@lee PR welcome to try it on carve

borkdude 2021-03-09T19:45:42.040500Z

clj-kondo has a fork of rewrite-clj so that won't really work for testing

borkdude 2021-03-09T19:47:31.040900Z

PR to rewrite-edn also welcome

borkdude 2021-03-09T19:48:25.041500Z

I know I want to upgrade those libs to the clj-commons one anyway, so might as well get it over with now. Been using your playground so far

lread 2021-03-09T19:59:36.042600Z

Yeah, rewrite-clj v1 branch, is pretty much equivalent to my rewrite-cljc-playground with more fixes and some minor changes to namespaced elements.

lread 2021-03-09T20:00:19.043300Z

Once I get the alpha out on clojars, Iā€™ll happily do PRs for carve and rewrite-edn.

lread 2021-03-09T20:02:07.043500Z

Cool, yeah, thanks, I think the real feedback can only come when people actually try out the first alpha.

borkdude 2021-03-09T20:03:00.044600Z

cool, then I can also have a clojars release of rewrite-edn. which I already did but I forgot I have a git dep :P

lread 2021-03-09T20:03:36.045200Z

BTW, I am already running carve and rewrite-edn tests against rewrite-clj v1 via its libs tests.

borkdude 2021-03-09T20:04:09.046300Z

Awesome. I also saw (not read entirely) the conversations with zprint. I assume you also test clj-format?

lread 2021-03-09T20:04:13.046400Z

Yeah, Iā€™m not exactly sure how antq manages a clojars release when it is using a git dep to rewrite-cljc-playground.

lread 2021-03-09T20:04:26.046700Z

Yep, cljfmt works.

borkdude 2021-03-09T20:04:39.047Z

Maybe he just copies your sources into the target dir before jar building? :P

borkdude 2021-03-09T20:06:50.048600Z

Maybe @slipset knows what happens when you deps-deploy a library with a gitlib to clojars?

lread 2021-03-09T20:07:31.049100Z

Yeah, I dunno, I figured the dep would have to be in pom?

lread 2021-03-09T20:08:10.049700Z

Iā€™m not sure how long it has been since you had a peek at v1 namespaced elements changes @borkdude, itā€™s similar to what we discussed ages ago, but if you have a time for a https://github.com/clj-commons/rewrite-clj/blob/v1/CHANGELOG.adoc#rewrite-clj-v1 thatā€™d be great.

borkdude 2021-03-09T20:09:15.050Z

@lee It seems he does package your code along with his jar ...

lread 2021-03-09T20:09:37.050300Z

Ah ok, your initial guess was right!

borkdude 2021-03-09T20:13:50.050600Z

@lee what is: > Potentially breaking: clojure.tools.reader.edn

lread 2021-03-09T20:14:01.050800Z

I switched to it.

borkdude 2021-03-09T20:14:17.051Z

from?

lread 2021-03-09T20:14:41.051400Z

in some places I think clojure.edn? Would have to look it up.

lread 2021-03-09T20:15:11.052Z

Oh I seeā€¦ maybe more of a bug fix than something to be listed under breaking changesā€¦

lread 2021-03-09T20:15:21.052200Z

if thatā€™s what you are getting at.

borkdude 2021-03-09T20:16:14.052900Z

I mean: you switched to Y. Yes, ok, but from what X? Where did you switch from? It raises more questions than answers to me ;)

lread 2021-03-09T20:16:29.053100Z

Oh gotchaā€¦

borkdude 2021-03-09T20:16:47.053800Z

I'll have a more serious read later, kind of in the middle of something

lread 2021-03-09T20:17:06.054Z

Thanks, Iā€™ll get more elaborate. Might be a false old note, will double check.

lread 2021-03-09T20:17:56.054600Z

Thanks @borkdude, looking foward to more feedback.

lread 2021-03-09T20:30:26.056600Z

I thought rewrite-clj v0 used read-string from other namespaces - other than from tests, this is not the case, Iā€™ll delete the note.

borkdude 2021-03-09T20:31:46.056800Z

This is why it surprised me

borkdude 2021-03-09T20:31:49.057Z

thanks

borkdude 2021-03-09T20:32:14.057600Z

Luckily rewrite-clj didn't because I would not have been able to use it with GraalVM at the time and clj-kondo wouldn't have happened and then babashka probably neither

borkdude 2021-03-09T20:32:41.058400Z

Reading for the second time: Typo: > redundent

šŸ‘ 1
lread 2021-03-09T20:33:21.059300Z

Ya, I think I actually temporarily introduced a bad read-string due to a booboo in transcribing prefixed requires.

borkdude 2021-03-09T20:33:51.060Z

The thing that I wonder most about after reading it is this one: > Namespace map prefix, is now stored in a namespaced map qualifier node. Prior to v1, was stored as a keyword. You give a lot of examples of any combination of things, but you call sexpr on everything, while I was wondering what the difference for this map prefix was

borkdude 2021-03-09T20:34:42.060400Z

Maybe you could show it using an example

borkdude 2021-03-09T20:35:08.061Z

And the other thing: does this affect how you call :children on a namespaced map node, what you get back and how you should process it?

lread 2021-03-09T20:36:42.061400Z

Good feedback, thanks.

lread 2021-03-09T20:43:01.065100Z

Thinking out loud here: Iā€™m still a bit confused as to what is and is not the public API. For example node record fields were not documented in v0. This indicates they are an implementation detail. This will change if we support serialization of nodes, but for now they are considered internal. So I think Iā€™ll express differences between the old an new namespaced map prefix from the perspective of the public node API.

lread 2021-03-09T20:43:57.065600Z

Eg. tag string ā€¦

lread 2021-03-09T20:44:04.066Z

Already did sexpr

borkdude 2021-03-09T20:44:17.066300Z

In clj-kondo I do rely on this, but I'm using my own fork anyway. so is clojure-lsp I think

lread 2021-03-09T20:45:01.067200Z

I actually run clojure-lspā€™s tests against rewrite-clj v1, they pass.

borkdude 2021-03-09T20:45:23.067600Z

That's good. Maybe this is because they are not doing analysis with rewrite-clj anymore, but only rewriting

borkdude 2021-03-09T20:45:30.067900Z

analysis is now done by clj-kondo

borkdude 2021-03-09T20:45:46.068200Z

Have you tested older versions that didn't use clj-kondo yet?

borkdude 2021-03-09T20:45:56.068400Z

Might be interesting

lread 2021-03-09T20:46:20.069Z

Nope just a current release.

borkdude 2021-03-09T20:46:36.069600Z

What is the reason you changed this field from a keyword to a map?

lread 2021-03-09T20:46:47.069700Z

Or maybe I did with rewrite-cljc ages agoā€¦

lread 2021-03-09T20:48:19.071100Z

For clarity and to support current-ns auto-resolve :: , ex. #::{:a 1} which rewrite-clj v0 did not support at all.

borkdude 2021-03-09T20:48:44.071500Z

so basically: to support more than one bit of info

borkdude 2021-03-09T20:48:54.071700Z

which a map is a good choice for

borkdude 2021-03-09T20:49:29.072200Z

Does the number of children change for namespaced maps?

lread 2021-03-09T20:49:37.072400Z

Nope

borkdude 2021-03-09T20:49:58.072900Z

And what happens when you call (sexpr (first (:children namespaced-map))) ?

borkdude 2021-03-09T20:50:06.073200Z

assuming that it returns the prefix?

lread 2021-03-09T20:50:39.073800Z

Yeah, there are examples in the change log.

borkdude 2021-03-09T20:50:42.074Z

or does it return only the k/vs?

lread 2021-03-09T20:51:05.074400Z

Oh right from a node API perspectiveā€¦

lread 2021-03-09T20:51:24.074700Z

Youā€™ll get the prefix

lread 2021-03-09T20:51:29.075Z

Like in v0

borkdude 2021-03-09T20:51:40.075300Z

Yes, I manipulate a lot of the nodes just by hand, by iterating over the :children, etc

borkdude 2021-03-09T20:51:44.075500Z

without zippers

borkdude 2021-03-09T20:53:24.077500Z

I guess I can just try this myself in the REPL

lread 2021-03-09T20:53:29.077700Z

Yeah, it is a bit awkward when you want to treat a map as a map whether it be a namespaced-map-node or a map-node.

lread 2021-03-09T20:55:26.078600Z

But v1 node traversal matches v0, and I like that. I have an https://github.com/clj-commons/rewrite-clj/issues/131.

borkdude 2021-03-09T20:55:50.078900Z

user=> (rewrite-clj.node/sexpr (first (:children (p/parse-string "#::{:a 1}"))))
?_current-ns_?

borkdude 2021-03-09T20:56:08.079300Z

cool, it does something :)

lread 2021-03-09T20:56:12.079400Z

yep, uses the default auto-resolve function which the user can choose to override.

borkdude 2021-03-09T20:58:51.080Z

user=> (rewrite-clj.node/sexpr (first (:children (p/parse-string "#::{:a 1}"))) {:auto-resolve {':current 'foo}})
foo
yes, excellent

lread 2021-03-09T20:59:05.080400Z

an idea I got from some clever fellow, canā€™t remember his name. :simple_smile:

šŸ˜† 1
borkdude 2021-03-09T20:59:55.081100Z

Last question: can you tell more about cljs perf things you removed to improve compatibility between both?

borkdude 2021-03-09T21:00:33.082400Z

And lastly: lots of respect for your thorough work. This is an important piece of software for the clj ecosystem and you stepped up, a lot of thanks.

lread 2021-03-09T21:02:20.083300Z

Yeahā€¦ I should actually provide a link to cljs perf because I have one somewhereā€¦ rundis made some efforts to optimize rewrite-cljs and wrote up a blog post. I dropped most of them in favour of a unified single code base for rewrite-cljs and rewrite-clj. Ah here it is: http://rundis.github.io/blog/2015/clojurescript_performance_tuning.html

lread 2021-03-09T21:03:14.084300Z

Well, you and others have certainly been supportive, thanks for the continued feedback over the journey.

lread 2021-03-09T21:03:52.084900Z

So rewrite-cljs users might notice a slowdown. Iā€™ve not done any perf testing at all.

borkdude 2021-03-09T21:04:08.085200Z

@lee I have done this in clj-kondo: > First quickwin - Moving away from multimethods Guess that perf improvement I saw in general usage? I can't say that I noticed.

borkdude 2021-03-09T21:04:19.085600Z

But it might help more in CLJS, who knows

lread 2021-03-09T21:04:46.086200Z

And this was against ClojureScript circa 2015, soā€¦ dunno what perf changes have happened since then.

borkdude 2021-03-09T21:04:52.086500Z

I did find it a little bit weird to use multi-methods for a private namespace.

borkdude 2021-03-09T21:05:15.086900Z

They do incur some perf overhead so switching to a closed set of cases does make sense

borkdude 2021-03-09T21:05:45.087500Z

This is what I did in edamame, the parser which is largely inspired by the rewrite-clj parser

lread 2021-03-09T21:06:57.088600Z

The nice thing is that is that we can improve performance if there are issues without breaking things.

borkdude 2021-03-09T21:07:11.088800Z

yep, very nice

lread 2021-03-09T21:08:20.089600Z

I put that under potentially breaking, because it might make rewrite-clj v1 cljs unusable if perf is really poor.

borkdude 2021-03-09T21:11:02.090Z

I guess if that is the case, the JVM can also benefit from some optimizations at the same time

lread 2021-03-09T21:11:17.090300Z

Sure, yep.

lread 2021-03-09T21:14:24.092900Z

I was also thinking about a prior conversation we had about version schemes and using commit count. Perhaps subjective, but Iā€™m thinking a benefit of using commit count really makes the version seems less precious and makes cutting a release less precious (which to me is good).

borkdude 2021-03-09T21:15:33.093200Z

What do you mean with the word precious here?

lread 2021-03-09T21:16:04.093700Z

Less of an important event. If need to release for any reason, I release.

borkdude 2021-03-09T21:16:42.094300Z

What does that have to do with the version number? Both can be scripted (I certainly use a script for this)

borkdude 2021-03-09T21:16:57.094600Z

I mean, bumping the version is a script in my projects

lread 2021-03-09T21:18:25.096500Z

I was thinking of more along the lines of psychological than technical.

borkdude 2021-03-09T21:18:32.096700Z

If you really want to make your versions meaningless, use dates. clj-kondo uses http://yyyy.mm.dd

lread 2021-03-09T21:18:46.096900Z

I did consider it.

borkdude 2021-03-09T21:19:20.097600Z

I can explain why I did this for clj-kondo: this project will never be finished, so always just use the newest

lread 2021-03-09T21:19:37.098300Z

Itā€™s all quite subjective thoughā€¦

borkdude 2021-03-09T21:19:55.098800Z

For babashka I do want to indicate something along the lines of API breaking or important new functionality, so I use 0.2.13 now. When spec goes in it will certainly be 0.3.0 or so

lread 2021-03-09T21:20:33.099300Z

Yeah I think thatā€™s what rewrite-clj v0 was doing.

borkdude 2021-03-09T21:20:36.099500Z

It is subjective yes. So it really doesn't matter much

lread 2021-03-09T21:20:59.100Z

Yes very true.

lread 2021-03-09T21:22:12.100900Z

Ok, Iā€™m going to go and incorporate your very helpful feedback into the change log and tomorrow will merge to main! Thanks as always!

lread 2021-03-09T21:38:28.101700Z

Funny thing about rewrite-cljc and rewrite-clj v1ā€¦ all I really wanted to do was fix a little bug in cljfmtā€¦ huh!

šŸ˜‚ 1
borkdude 2021-03-09T21:40:10.102Z

Improving the world one bugfix... eh library at a time

borkdude 2021-03-09T21:40:50.102400Z

So what was the bug?

lread 2021-03-09T21:40:53.102700Z

An open source journey begins with but one bug

borkdude 2021-03-09T21:40:56.102800Z

And is it fixed?

lread 2021-03-09T21:45:22.105100Z

No, not yet. There were a few actually, I think https://github.com/weavejester/cljfmt/pull/77#issuecomment-470721499, but it was missing namespaced map support in rewrite-clj v0 and lotsa missing stuff in rewrite-cljs that really lit the flame.

borkdude 2021-03-09T21:46:14.105400Z

so cljfmt is using cljs?

lread 2021-03-09T21:46:28.105800Z

Yeah it supports both clj and cljs.

borkdude 2021-03-09T21:46:29.105900Z

ah, .cljc ok

lread 2021-03-09T21:46:51.106400Z

It references both rewrite-cljs and rewrite-clj v0.

borkdude 2021-03-09T21:49:47.106900Z

So once migrating it to v1 you may finally get to it? ;)

lread 2021-03-09T21:58:23.107200Z

Yes!