Function arity dispatch returns arity

Description

JS code generated from cljs.js/eval-str* and cljs.js/compile-str* functions are out of order(see the attachment).

Used the below compilation option to generate js code.
{ :load-macros true
:analyze-deps true
:static-fns false
:def-emits-var true
:context :expr }

Environment

None

Activity

Show:
Mike Fikes
June 3, 2016, 2:20 AM

Attaching CLJS-1611.patch which fixes the multi-arity as well as the variadic case.

Variadic and multi-arity defn forms expand to code that perform the
needed def, followed by some side-effecting code. Instead of returning
the value of the last side-effecting form, capture and return the
value of the def so that the expanded defn returns the value of the
def, thus causeing :def-emits-vars to operate properly in REPLs.

Mike Fikes
June 3, 2016, 4:11 AM

While CLJS-1611.patch appears to fix the issue when looking at its behavior in the REPL, it causes different JavaScript to be emitted which leads me to suspect the patch may not be suitable.

For a concrete example of what is produced, consider this namespace

This would normally transpile to this:

With the patch, this is emitted:

I haven't yet grokked the consequences of this. On the other hand, I have empirically seen a failure of Planck to be able to walk the namespace object trees in code generated with this patch.

Mike Fikes
June 3, 2016, 1:27 PM

With a little more care with respect to what is emitted in the transpiled JavaScript, the revised CLJS-1611-1.patch meets our desire of returning the var in the REPL, but otherwise not affecting transpiled JavaScript. I've put this through some paces, evaluating forms in script/noderepljs, requiring code and looking at what gets put in .cljs_node_repl, and using it downstream with Planck and it appears to be doing what we want. I'd recommend others giving a spin as well.

Commit comment:

Variadic and multi-arity defn forms expand to code that perform the
needed def, followed by some side-effecting code. Instead of returning
the value of the last side-effecting form, conditionally return a var
for the name if :def-emits-vars is true, otherwise nil (which gets
elided from compiled JavaScript.)

Mike Fikes
June 3, 2016, 2:40 PM

Rohit Aggarwal indicated "LGTM."

Assignee

David Nolen

Reporter

import

Labels

Approval

None

Patch

Code

Priority

Minor
Configure