cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
dnolen 2020-09-03T00:00:22.028Z

but did you not observe that?

cfleming 2020-09-03T00:00:25.028100Z

That is what I expected.

cfleming 2020-09-03T00:00:25.028400Z

No

cfleming 2020-09-03T00:00:53.029Z

Here’s what comes out:

{:name stub-test,
 :publics ({:name normal-def, :type :var}
           {:name normal-defn, :arglists ([]), :type :var}
           {:name hidden-defmacro2, :arglists ([]), :doc "Doc", :type :macro}
           {:name gen-clj-stuff, :arglists ([]), :type :macro}
           {:name NormalProtocol, :type :protocol, :members ({:name normal-method, :arglists ([this]), :type :var})}
           {:name hidden-defmacro5, :arglists ([foo__2589__auto__]), :type :macro}
           {:name gen-stuff, :arglists ([]), :type :macro}
           {:name hidden-defmacro6, :arglists ([foo__2589__auto__] [foo__2589__auto__ bar__2590__auto__]), :type :macro}
           {:name normal-multimethod, :type :multimethod}
           {:name hidden-defmacro4, :arglists ([]), :doc "Moar doc", :type :macro}
           {:name normal-method, :arglists ([this]), :type :var}
           {:name hidden-defmacro3, :arglists ([]), :type :macro}
           {:name hidden-defmacro, :arglists ([]), :type :macro}
           {:name normal-macro, :arglists ([]), :type :macro})}

cfleming 2020-09-03T00:01:07.029400Z

normal-macro does appear there.

dnolen 2020-09-03T00:01:37.030100Z

ok so let me try to reproduce that with really basic analysis - and leave the other parts for later

dnolen 2020-09-03T00:01:49.030500Z

I'm not going to use the specific stuff you have, just standard analyze-file

cfleming 2020-09-03T00:02:00.030900Z

Sounds good.

cfleming 2020-09-03T00:02:34.031400Z

The repro contains a bunch of fiddling required to make helix.dom analyse, related to npm deps.

dnolen 2020-09-03T00:16:58.031800Z

(normal-def normal-defn normal-multimethod NormalProtocol normal-method)

dnolen 2020-09-03T00:16:59.031900Z

this is the result of analyze-file of the first 8 lines

dnolen 2020-09-03T00:17:02.032Z

the keys of the :defs for that namespace

dnolen 2020-09-03T00:17:19.032300Z

I don't see normal-macro in there

dnolen 2020-09-03T00:17:33.032600Z

which would have been very surprising because it's behind a reader conditional

cfleming 2020-09-03T00:17:43.032900Z

That’s why I was very surprised 🙂

cfleming 2020-09-03T00:18:02.033700Z

Let me try just analyze-file on that.

dnolen 2020-09-03T00:19:24.034400Z

to be clear this was cljs.analyzer/analyze-file, let me try the api one - which is the right one to use

dnolen 2020-09-03T00:20:17.034600Z

same result for api one

cfleming 2020-09-03T00:21:45.035Z

Here’s what I’m using:

(let [state (cljs.env/default-compiler-env)
      resource (io/resource "stub_test.cljc")]
  (comp/with-core-cljs state nil #(ana/analyze-file state resource nil))
  (mapv :name (vals (ana/ns-publics state 'stub-test))))

cfleming 2020-09-03T00:22:00.035300Z

With that, I get:

[stub-test/normal-def
 stub-test/normal-defn
 stub-test/hidden-defmacro2
 stub-test/gen-clj-stuff
 stub-test/NormalProtocol
 stub-test/hidden-defmacro5
 stub-test/gen-stuff
 stub-test/hidden-defmacro6
 stub-test/normal-multimethod
 stub-test/hidden-defmacro4
 stub-test/normal-method
 stub-test/hidden-defmacro3
 stub-test/hidden-defmacro
 stub-test/normal-macro]

cfleming 2020-09-03T00:22:10.035800Z

Am I using the API wrong?

dnolen 2020-09-03T00:22:32.036400Z

ns-publics is probably what's sending you down the wrong path - let me read over that

dnolen 2020-09-03T00:22:52.036700Z

yes I would read over ns-publics 🙂

dnolen 2020-09-03T00:24:24.037800Z

so the reasoning behind this behavior is that really for self-referencing files, the defs and the macros are the ns-publics of that file

dnolen 2020-09-03T00:24:27.038Z

just like Clojure

dnolen 2020-09-03T00:24:50.038600Z

because for end users, you're going to want to know about defs and macros because these can all be :refered

dnolen 2020-09-03T00:25:24.039300Z

so doing it this way is more like Clojure, and it would let an autodoc tool get everything at once instead of doing something special to get at the macros provided by a library

dnolen 2020-09-03T00:28:20.040900Z

if you want the true :defs I would say get those yourself and skip ns-publics

dnolen 2020-09-03T00:29:05.042200Z

as to whether or not we should have a public api for just that - I'm a bit skeptical and honestly I don't see the compiler state representation changing - not worth the hassle

cfleming 2020-09-03T00:29:05.042300Z

Ok, so I think I understand why the macro problem occurs. I still don’t understand why the elements generated by gen-stuff are not. Is that because analysis doesn’t actually execute top-level forms?

cfleming 2020-09-03T00:29:26.042700Z

Yeah, I think that is reasonable (re; the public API).

dnolen 2020-09-03T00:29:49.043100Z

ok so we've sorted out the first half of your problem - on to the next half

dnolen 2020-09-03T00:32:08.043300Z

so first question

dnolen 2020-09-03T00:32:23.043500Z

I do not understand the last line

dnolen 2020-09-03T00:32:46.044Z

you're using a macro that's only defined in Clojure but you didn't put it behind a reader conditional

cfleming 2020-09-03T00:34:23.045Z

This may be my superficial knowledge of CLJS macros showing. My understanding was that macros were defined in CLJ but used in CLJS. Is that not correct?

dnolen 2020-09-03T00:34:40.045400Z

but you didn't refer the macro

cfleming 2020-09-03T00:34:49.045800Z

Argh

dnolen 2020-09-03T00:34:53.045900Z

you cannot just use it because you self-referenced via :require-macros - you need to refer

dnolen 2020-09-03T00:35:16.046300Z

or use an aliased reference

cfleming 2020-09-03T00:35:44.046900Z

Indeed, (stub-test/gen-stuff) works!

dnolen 2020-09-03T00:35:51.047300Z

BOOM!

cfleming 2020-09-03T00:35:58.047500Z

Great, thank you - that was very enlightening 🙂

dnolen 2020-09-03T00:36:03.047700Z

no problem

dominicm 2020-09-03T21:27:31.048800Z

How does data readers work on clojurescript? They seem to be executed in java, which means that objects won't be converted to clojurescript. Should they return a code form?

lilactown 2020-09-03T21:55:47.049Z

yeah they’re similar to macros

dominicm 2020-09-03T21:56:19.049100Z

How can I create a reader which works in clojure and cljs? I should have mentioned my actual question :)

dominicm 2020-09-03T21:56:25.049200Z

In Clojure, I return the object.

dominicm 2020-09-03T21:56:50.049300Z

Just peeking at what #uuid does, it seems it creates a java.util.UUID, and then defines https://github.com/clojure/clojurescript/blob/b68f0a0de19384f736ab10912001519249737e56/src/main/clojure/cljs/compiler.cljc#L423-L425 Not sure if that's something user-space should do.

lilactown 2020-09-03T23:09:30.050400Z

I think this is more illustrative of how to write a tag handler for cljs: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/tagged_literals.cljc#L21

lilactown 2020-09-03T23:10:14.051Z

takes in the form after the tag, returns another form for the compiler