Fork me on GitHub
#cljs-dev
<
2019-10-25
>
andy.fingerhut06:10:35

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

thheller08:10:47

@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

thheller08:10:53

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

andy.fingerhut08:10:32

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

thheller08:10:45

yes. .bar will be compiled before .foo

thheller08:10:07

circular stuff isn't allowed

andy.fingerhut08:10:37

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

thheller08:10:28

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

andy.fingerhut08:10:54

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.

thheller08:10:13

yes vars are checked at compile time

thheller08:10:39

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

andy.fingerhut08:10:39

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

thheller08:10:44

not throw like clojure would

thheller08:10:16

the JS compiler will generated ouroboros.foo.Transient

andy.fingerhut08:10:39

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

thheller08:10:56

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

andy.fingerhut08:10:46

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

thheller08:10:18

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

andy.fingerhut08:10:22

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

thheller08:10:15

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

thheller08:10:28

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

andy.fingerhut08:10:26

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.

dnolen13:10:53

just doesn't seem very important

dnolen13:10:15

one way or the other

Filipe Silva14:10:47

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

👍 12