Recur around try boxes primitives
Description
Environment
Activity
Kevin Downey July 28, 2014 at 11:22 PM
if you want the fixes for try out of the return context to be part of CLJ-701 then yes it is a dupe, if you are unsure or would prefer 701 to stay more focused (my patch may not be acceptable, or may be too large and doing too much) then no it wouldn't be a dupe. I sort of took it on myself to solve both in the patch on CLJ-701 because I came to CLJ-701 via Nicola's comment here, and the same compiler machinery can be used for both.
I think the status is pending on the status of CLJ-701.
Alex Miller July 28, 2014 at 7:56 PM
Should I dupe this to CLJ-701?
Kevin Downey July 23, 2014 at 3:27 AM
http://dev.clojure.org/jira/browse/CLJ-701 has a patch that I think solves this
Kevin Downey July 22, 2014 at 12:59 AM
try/catch in the compiler only implements Expr, not MaybePrimitiveExpr, looking at extending TryExpr with MaybePrimitiveExpr it seems simple enough, but it turns out recur analyzes it's arguments in the statement context, which causes (try ...) to essentially wrap itself in a function like ((fn [] (try ...))), at which point it is an invokeexpr which is much harder to add maybeprimitiveexpr too and it reduces to the same case as CLJ-701
Primitive function and recur variables can't pass through a (try) cleanly; they're boxed to Object instead. This causes reflection warnings for fns or loops that use primitive types.
user=> (set! *warn-on-reflection* true) true user=> (fn [] (loop [t 0] (recur t))) #<user$eval676$fn__677 user$eval676$fn__677@3d80023a> user=> (fn [] (loop [t 0] (recur (try t)))) NO_SOURCE_FILE:1 recur arg for primitive local: t is not matching primitive, had: Object, needed: long Auto-boxing loop arg: t #<user$eval680$fn__681 user$eval680$fn__681@5419323a> user=> (fn [^long x] (recur (try x))) NO_SOURCE_FILE:1 recur arg for primitive local: x is not matching primitive, had: Object, needed: long CompilerException java.lang.IllegalArgumentException: recur arg for primitive local: x is not matching primitive, had: Object, needed: long, compiling:(NO_SOURCE_PATH:1:1)