Fork me on GitHub
#cljs-dev
<
2019-04-25
>
Roman Liutikov12:04:19

Is it expected that compiler’s env doesn’t include an anonymous function in :fn-scope? Here :fn-scope is only going to have fn-1

(defn fn-1 []
  (fn [a]
    a))

dnolen13:04:33

:fn-scope is about shadowing

dnolen13:04:40

shadowing isn't a problem with anonymous fns

dnolen13:04:46

@roman01la concrete example (fn console [] ...)

dnolen13:04:00

w/o :fn-scope this will create a local named fn with the exact JS name console

dnolen13:04:28

which breaks expectations

dnolen13:04:10

fwiw it's sometimes useful to use the git history to see what test was associated w/ a change - the test hopefully makes it clear what was broken

dnolen13:04:21

definitely true in this case

dnolen13:04:19

to clarify further, we use each entry in :fn-scope to produce a qualified name that can be used for recursion

dnolen13:04:34

something like fn_1$console

Roman Liutikov13:04:16

I’m trying to detect if a local var is an argument of the top most function, not sure what’s the general algorithm here?

dnolen13:04:36

we could of course generate random names - but the above has the added benefit of aligning w/ something you see in Clojure as well as helping w/ debugging

dnolen13:04:45

@roman01la I wouldn't mess w/ any of this

dnolen13:04:57

or attempt to re-use anything in ClojureScript

dnolen13:04:16

beyond calling analyze, just walk the AST yourself and sort it out

Roman Liutikov13:04:32

yes, that’s what I’m doing

dnolen13:04:41

then I don't see why you care about :fn-scope

dnolen13:04:36

should just be able to look at bindings and args

Roman Liutikov13:04:34

Ok, perhaps I missed something, I have to look more into it. I’ll get back if I need more help. Thanks!

dnolen13:04:20

as you walk down the AST w/ the original fns args, just check to see if you got shadowed via a new binding or fn arg

mhuebert14:04:20

is it normal to get errors when using ^boolean type hints in cljc code? eg

Error in phase :compile-syntax-check
IllegalArgumentException: Unable to resolve classname: clojure.core$boolean@6fc1e52d

mhuebert15:04:07

I don’t get an error if I type something like (defn ^boolean x []) in a clojure repl

thheller15:04:14

@mhuebert the return value tag is placed incorrectly. so likely it just isn't interpreted? this fails

(defn x ^boolean [])
CompilerException java.lang.IllegalArgumentException: Only long and double primitives are supported, 

dpsutton15:04:29

an example. i thought the typehint went on the var

thheller15:04:10

pretty sure for defn the hint goes on the args vector (for :ret-tag)

dnolen15:04:54

@mhuebert pretty sure ^boolean won't work in Clojure

dnolen15:04:07

so you need to conditionalize

dnolen15:04:57

also I'm sure you're doing something very performance sensitive to bother here at all

mhuebert15:04:20

yeah it’s in a tight loop where the ^boolean in cljs makes a big difference

dnolen15:04:55

k, for some history ^boolean was introduced when we started to doing persistent datastructures

dnolen15:04:00

wasn't really important for anything else

mfikes15:04:20

@mhuebert It is also possible in many cases for the compiler to infer that a function returns a Boolean value. This depends on the body of the function.

mfikes15:04:58

This raises an interesting question on inference / hinting around goog-define values

dnolen15:04:06

I think I considered a flag for :warn-on-cljs-truth but I think that was before file-scoped dynamic vars

dnolen15:04:31

was too noisy, could revisit for people doing perf work

mfikes15:04:33

(Sorry about the goog-define noise in my previous comment; thought that was the code in question.)

mhuebert15:04:52

could it infer from the last fn passed to comp?

dnolen15:04:24

there is no higher order inference

mhuebert15:04:12

ok. After using the analyzer to do a bit of digging, hints were propagating up from function bodies more than I realized

dnolen18:04:43

right a lot code users write isn't higher-order (this isn't Haskell afterall), so the surface area that our simple inference covers is surprisingly effective

dnolen18:04:05

and lazy seq ops return seq or nil, so even that's covered

dnolen18:04:08

but we can't do too much about partial, comp, apply etc. right now - but I think not really a big deal, and those things would require a lot more effort

lread22:04:47

Hello cljs-dev! I am interested in seeing this one addressed: https://dev.clojure.org/jira/browse/CLJS-3074 - do you think it would be a good first issue for me to tackle?

dnolen22:04:39

@lee absolutely!

dnolen22:04:56

doesn't require getting too deep into compiler know-how - but enough to get familiar with the process

lread22:04:21

I am perusing it now, thanks! Have already submitted my Contributor Agreement.