cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
2019-10-25T06:29:35.036100Z

I sent a message to #clojurescript channel about this, but since the ClojureScript compiler behavior I am seeing might have some subtle explanation, I thought I would send it here, too. The README of this tiny sample project should explain everything: https://github.com/jafingerhut/ouroboros

thheller 2019-10-25T08:30:47.039100Z

@andy.fingerhut since .bar does not have a require for .foo the compiler can not ensure that .foo is actually compiled before .bar. the default compiler logic when then just process your "inputs" (eg. files in the :source-paths) in an undefined order which ends up compiling .bar before .foo and thus complaining about a var it can't find. problem would get even worse with :parallel-build since with multiple threads it may even sometimes happen to reach (deftype Transient ...) before its use in .bar so the error will only appear occasionally

thheller 2019-10-25T08:31:53.039700Z

in general it is not safe to access other namespaces without having an explicit :require for them

2019-10-25T08:33:32.040500Z

So there is an explicit require in namespace foo of bar. Shouldn't that mean that bar must be compiled first always, deterministically?

thheller 2019-10-25T08:34:45.041100Z

yes. .bar will be compiled before .foo

thheller 2019-10-25T08:35:07.041300Z

circular stuff isn't allowed

2019-10-25T08:35:37.041900Z

How is what you said different than the order I asked about?

thheller 2019-10-25T08:36:28.042700Z

sorry, read that wrong. I didn't look at the ns of .foo before 😛

2019-10-25T08:36:54.043300Z

It seems that there is a kind of circularity being allowed here, and warned about, but the compiler goes ahead and generates what appears to be working code, despite that.

thheller 2019-10-25T08:37:13.043800Z

yes vars are checked at compile time

thheller 2019-10-25T08:37:39.044800Z

but the JS runtime is fine with this at runtime since the "default" behavior is to just warn about missing warns

2019-10-25T08:37:39.044900Z

I haven't examined the JavaScript generated by ClojureScript compiler here, partly since I'm new to JavaScript.

thheller 2019-10-25T08:37:44.045100Z

not throw like clojure would

thheller 2019-10-25T08:38:16.045600Z

the JS compiler will generated ouroboros.foo.Transient

2019-10-25T08:38:39.046Z

and JS warns about, but allows, such 'forward references'?

thheller 2019-10-25T08:38:56.046300Z

JS doesn't warn no, it is totally fine with that

2019-10-25T08:39:46.046900Z

So I'm guessing that this should not be held up as a good recommended way to write ClojureScript code.

thheller 2019-10-25T08:40:18.047500Z

yes. IMHO this should even be a hard error like in Clojure. Not sure why it was made a warning.

2019-10-25T08:41:22.048400Z

Understood. Yeah, hopefully you can understand my confusion at how this was possibly working.

thheller 2019-10-25T08:43:15.049Z

yeah, this works since JS is much more dynamic than the JVM and everything is loaded into the same global scope anyways

thheller 2019-10-25T08:43:28.049500Z

so as long as it is loaded into the runtime before it is actually accessed JS will be fine

2019-10-25T08:44:26.050100Z

OK, thanks for the help understanding what is going on. Sounds like a question for #cljs-dev folks for why this is a warning rather than an error.

dnolen 2019-10-25T13:11:53.050300Z

just doesn't seem very important

dnolen 2019-10-25T13:12:15.050700Z

one way or the other

Filipe Silva 2019-10-25T14:18:47.051300Z

heya, would you accept me adding a shadow-cljs section and project template to https://clojurescript.org/guides/project-templates?

👍 3
Filipe Silva 2019-10-25T14:19:14.051700Z

I see I can add it as a PR in https://github.com/clojure/clojurescript-site/blob/master/content/guides/project-templates.adoc, but I am not sure if it's welcome to do

Filipe Silva 2019-10-25T18:41:07.052200Z

added a PR https://github.com/clojure/clojurescript-site/pull/328