Clojurians
#cljs-dev
<
2016-02-19
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

richiardiandrea01:02:38

Hello guys, is there an obvious reason why in bootstrapped clojurescript :simple :

cljs.user=> (ns a.ns)
nil
a.ns=> (def a 3)
ERROR - Cannot set property 'a' of undefined <- here undefined is a.ns

richiardiandrea01:02:04

I understand namespaces are not reified but:

as.ns=> (ns ap.ns)
nil
ap.ns=> (def a 3)
#'ap.ns/a
ap.ns=> (ns c.ns)
nil
c.ns=> (def a 3)
ERROR - Cannot set property 'a' of undefined <- here undefined is c.ns

richiardiandrea01:02:09

smells like a bug

richiardiandrea01:02:20

but I wanted your opinion first

jaredly05:02:07

@richiardiandrea: does in-ns work?

richiardiandrea06:02:38

@jaredly will check tomorrow. Have you had similar issues?

jaredly06:02:19

yeah.. can’t remember what fixed it though

dnolen12:02:36

@richiardiandrea: whether that does or doesn’t work is really dependent on REPL code

dnolen12:02:55

and bootstrapped doesn’t provide any of that

richiardiandrea16:02:53

thanks @dnolen smelled like a bug but very likely on my side :smile: @jaredly if you happen to remember let me know ok? thank you both!

jaredly16:02:48

@richiardiandrea: umm so testing in http://jaredforsyth.com/reepl/ a.ns or [single-char].ns doesn’t work, but (ns some.ns) or (ns one.two) works :smile: might point you in the right direction

richiardiandrea16:02:50

yes same here, and it happens with :simple only so I might be losing js symbol somewhere

richiardiandrea16:02:22

it is weird because in the console I see the object a.dt but my JavaScript-fu is weak and it looks like this object is not visible inside the expression above

richiardiandrea16:02:31

ok so in the scope of execution of the big Javascript function above there is no symbol a.ns defined, but if I execute in the console it works! Digging...

richiardiandrea16:02:11

so now the question is, what is the difference between console and js/eval?

jaredly17:02:40

@richiardiandrea: check for window.a.ns in the scope of that function

jaredly17:02:10

it’s possible that there’s a local variable a that’s shadowing the global window.a

richiardiandrea17:02:39

yes I think is like you say and b (b.nh) in that closure is:

[:lang :clj]
1[:name "(def a 3)"]
2[:path "(def a 3)"]
3[:source 
"(function (){↵b.nh.a … test:null)])));})()↵"
]
4[:cache nil]

richiardiandrea17:02:49

cljs-devtools output

jaredly17:02:56

yup, gclosure makes most vbls single letter

jaredly17:02:06

wonder how hard it would be to get namespace references prefixed with window (or global in node, self in webworker)

richiardiandrea17:02:55

@jaredly: so basically it is referring to local vars instead of window and because of the optimizations the name clashes?

richiardiandrea17:02:28

I will open an issue

jaredly17:02:04

a fix could be to pass an option to the compile step that prefixes everything w/ window.

richiardiandrea17:02:35

maybe there is a reason not to do it and David will tell us :wink:

jaredly17:02:54

well it doesn’t make sense to do it in generally b/c closure has global knowledge

jaredly17:02:09

but in bootstrapped, you’re running stuff after closure’s done it’s magic and w/o it’s knowledge

richiardiandrea17:02:59

that's why he was saying that it is basically my implementation

richiardiandrea17:02:10

but the generated code here under not my control

richiardiandrea17:02:34

it is generated in cljs.js/eval

richiardiandrea18:02:22

in any case :simple in both node and browser is hard to achieve (atm does not work for node for instance)

richiardiandrea18:02:11

by the way @jaredly is js/global renamed in nodejs when :simple?

dnolen18:02:18

@richiardiandrea: I do not understand what’s under discussion here really

dnolen18:02:30

so far I haven’t heard anything that seems like a bug

jaredly18:02:46

@dnolen: compiled cljs assumes that namespaces are in the global scope, but if you’re in a function compiled by google closure, where single-letter variable names are locally shadowed, you won’t be able to access anything on single-letter namespaces, e.g. a.ns.

richiardiandrea18:02:36

I am not sure @dnolen, that's why I haven't open any issue yet, don't want to say it is a bug until I understood, probably it has to be that way

richiardiandrea18:02:48

but yes the problem is the above ^

jaredly18:02:08

a bootstrapped repl needs to be able to prefix all javascript references w/ window. in order to guard against this shadowing. this would be a change to core

dnolen18:02:08

@jaredly: ok that isn’t a bug

dnolen18:02:18

@richiardiandrea: this is your answer ^

dnolen18:02:35

shadowing is shadowing, absolutely uninterested in doing anything about it

jaredly18:02:58

it’s only an issue that would come up in the context of bootstrapped cljs

dnolen18:02:13

@jaredly: that isn’t true

dnolen18:02:20

the compiler has stuff for shadowing

dnolen18:02:26

it affects all ClojureScript

dnolen18:02:04

look at at JIRA for several tickets around this problem

jaredly18:02:09

right but the issue is two different compilations that aren’t aware of each other

dnolen18:02:57

and they should not be

dnolen18:02:06

also if this boils down to single character namespaces … we just don’t care

richiardiandrea18:02:28

well yes I agree, it is such an unlikely scenario

dnolen18:02:38

it’s not that it’s unlikely

dnolen18:02:43

it’s that it’s not important at all

richiardiandrea18:02:00

bootstrapped + single letter ns -> just came up in my tests

jaredly18:02:31

would you be open to a patch that adds an option js-ns-prefix or something to compile-string?

dnolen18:02:41

sure but if it doesn’t matter for normal usages of bootstrapped, this isn’t something worth spending time on

dnolen18:02:43

@jaredly: no

dnolen18:02:37

probably the only thing I would consider is a warning about single letter namespaces

richiardiandrea18:02:39

I agree with @dnolen too here, I already spent some "precious" time to debug it

dnolen18:02:39

nobody should be doing that

jaredly18:02:16

it would also allow (something that I’ve wanted) for bootstrapped cljs to eval in a separate namespace-context from the bootstrapping code. e.g. deffing a vbl in the repl that doesn’t step on the code of the repl itself

richiardiandrea18:02:25

perfection does not exists I guess, on the bright side TIL

richiardiandrea18:02:26

@jaredly: that is interesting, dunno if doable, again my JS-fu is weak

jaredly18:02:36

w/ a js-ns-prefix it would totally work

richiardiandrea18:02:06

no I was thinking of a solution in replumb but I don't see it working

dnolen18:02:26

@jaredly: not interested in such a thing at this time

dnolen19:02:42

far as I can tell the corrupted analysis cache bug should be fixed - https://github.com/clojure/clojurescript/commit/68524a89eea8a8ae6cb69d1329acb3e3025c0fb6

dnolen19:02:53

if somebody wants to test master that would be great

richiardiandrea19:02:49

oh I read about it, I will check

dnolen19:02:23

@richiardiandrea: you know it’s working if your project can still build even if you truncate an analysis cache file

richiardiandrea19:02:49

ok thanks because there was no test case in the issue

dnolen19:02:30

@richiardiandrea: a test case would be welcome for this of course

mhuebert19:02:10

ha. so I’ve still been using cljs master from working on that patch, and today I had a super weird ui bug. just could not figure it out. then I look at the map holding the relevant data - duplicate keys! (not= (count (keys m)) (count (set (keys m)))). one key had the correct value, the other an old one. happening about every 10 minutes and haven’t been able to figure out exactly when/how it starts.

richiardiandrea19:02:56

@dnolen: so I see all my cache.edn then I just delete some part of them and launch the build again?

dnolen19:02:12

@richiardiandrea: yes

dnolen20:02:30

might affect bootstrapped usage

dnolen20:02:40

also if you’re using :parallel-build of course

richiardiandrea20:02:24

@dnolen: sorry for the noob question but cljs.build.api/build does not allow multiple source dirs at the moment?

dnolen20:02:57

@richiardiandrea: it does use inputs

richiardiandrea20:02:29

checking the source..

richiardiandrea20:02:54

clever @mfikes, I am using your tricks :smile: CLJSC_CP=... otherwise it is a pain :wink:

richiardiandrea20:02:20

Ok for now I will take a break, I have: Exception in thread "main" java.lang.IllegalAccessError: tried to access class com.google.javascript.jscomp.ES6ModuleLoader from class cljs.closure__init

richiardiandrea20:02:25

Will try maybe later