Clojure

Report boxed math warning on function that boxes primitive return value

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.7
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code

Description

With the new :warn-on-boxed (CLJ-1325), these examples do not report a boxed math warning although they each do boxing:

user=> (defn f1 [^long x] (inc x))
f1
user=> (defn f2 [x] (aget (long-array [1 2]) 0))
f2
user=> (defn f3 [x] (aget (int-array [1 2]) 0))
f3
user=> (defn f4 [^String s] (.indexOf s "a"))

Cause: emitBoxReturn has a hard-coded call to box a prim return value.

Solution: If *unchecked-math* is set to :warn-on-boxed, emit a warning on boxing of primitive numeric return types.

Patch:

Activity

Alex Miller made changes -
Field Original Value New Value
Fix Version/s Release 1.7 [ 10250 ]
Approval Vetted [ 10003 ]
Alex Miller made changes -
Description Lifting Nicola's comment on CLJ-

With the new :warn-on-boxed, this code reports a warning:

{code}
user=> (defn f [x] (inc x))
Boxed math warning, NO_SOURCE_PATH:2:13 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_in
{code}

but this does not:

{code}
user=> (defn f1 [^long x] (inc x))
{code}

*Cause:* Number Numbers.num(long) (and similar) are not currently reported as boxed math warnings.

*Solution:* Add the boxed math warning annotation for these methods:
- Number Numbers.num(long)
- Number Numbers.num(double)
- Number Numbers.num(float)

Lifting Nicola's comment on CLJ-1325... With the new :warn-on-boxed, this code reports a warning:

{code}
user=> (defn f [x] (inc x))
Boxed math warning, NO_SOURCE_PATH:2:13 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_in
{code}

but this does not:

{code}
user=> (defn f1 [^long x] (inc x))
{code}

*Cause:* Number Numbers.num(long) (and similar) are not currently reported as boxed math warnings.

*Solution:* Add the boxed math warning annotation for these methods:
- Number Numbers.num(long)
- Number Numbers.num(double)
- Number Numbers.num(float)

Alex Miller made changes -
Description Lifting Nicola's comment on CLJ-1325... With the new :warn-on-boxed, this code reports a warning:

{code}
user=> (defn f [x] (inc x))
Boxed math warning, NO_SOURCE_PATH:2:13 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_in
{code}

but this does not:

{code}
user=> (defn f1 [^long x] (inc x))
{code}

*Cause:* Number Numbers.num(long) (and similar) are not currently reported as boxed math warnings.

*Solution:* Add the boxed math warning annotation for these methods:
- Number Numbers.num(long)
- Number Numbers.num(double)
- Number Numbers.num(float)

Lifting Nicola's comment on CLJ-1325... With the new :warn-on-boxed, this code reports a warning:

{code}
user=> (defn f [x] (inc x))
Boxed math warning, NO_SOURCE_PATH:2:13 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_in
{code}

but this does not:

{code}
user=> (defn f1 [^long x] (inc x))
{code}

*Cause:* Number Numbers.num(long) is not currently reported as boxed math warnings in the generated code above.

*Solution:*

Alex Miller made changes -
Summary Report boxed math warning on Numbers.num() that return Number Report boxed math warning on function that boxes primitive return value
Fix Version/s Release 1.7 [ 10250 ]
Approval Vetted [ 10003 ] Triaged [ 10120 ]
Alex Miller made changes -
Description Lifting Nicola's comment on CLJ-1325... With the new :warn-on-boxed, this code reports a warning:

{code}
user=> (defn f [x] (inc x))
Boxed math warning, NO_SOURCE_PATH:2:13 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_in
{code}

but this does not:

{code}
user=> (defn f1 [^long x] (inc x))
{code}

*Cause:* Number Numbers.num(long) is not currently reported as boxed math warnings in the generated code above.

*Solution:*

Lifting Nicola's comment on CLJ-1325... With the new :warn-on-boxed, this code reports a warning:

{code}
user=> (defn f [x] (inc x))
Boxed math warning, NO_SOURCE_PATH:2:13 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_in
{code}

but this does not (even though it will do the inc as a primitive op, then box the return value into an Object:

{code}
user=> (defn f1 [^long x] (inc x))
{code}

*Cause:*

*Solution:*

Alex Miller made changes -
Description Lifting Nicola's comment on CLJ-1325... With the new :warn-on-boxed, this code reports a warning:

{code}
user=> (defn f [x] (inc x))
Boxed math warning, NO_SOURCE_PATH:2:13 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_in
{code}

but this does not (even though it will do the inc as a primitive op, then box the return value into an Object:

{code}
user=> (defn f1 [^long x] (inc x))
{code}

*Cause:*

*Solution:*

With the new :warn-on-boxed (CLJ-1325), these examples do not report a boxed math warning although they each do boxing:

{code}
user=> (defn f1 [^long x] (inc x))
f1
user=> (defn f2 [x] (aget (long-array [1 2]) 0))
f2
user=> (defn f3 [x] (aget (int-array [1 2]) 0))
f3
{code}

*Cause:* emitBoxReturn has a hard-coded call to box a prim return value.

*Solution:* If \*unchecked-math* is set to :warn-on-boxed, emit a warning on boxing of primitive numeric return types.

*Patch:*
Alex Miller made changes -
Description With the new :warn-on-boxed (CLJ-1325), these examples do not report a boxed math warning although they each do boxing:

{code}
user=> (defn f1 [^long x] (inc x))
f1
user=> (defn f2 [x] (aget (long-array [1 2]) 0))
f2
user=> (defn f3 [x] (aget (int-array [1 2]) 0))
f3
{code}

*Cause:* emitBoxReturn has a hard-coded call to box a prim return value.

*Solution:* If \*unchecked-math* is set to :warn-on-boxed, emit a warning on boxing of primitive numeric return types.

*Patch:*
With the new :warn-on-boxed (CLJ-1325), these examples do not report a boxed math warning although they each do boxing:

{code}
user=> (defn f1 [^long x] (inc x))
f1
user=> (defn f2 [x] (aget (long-array [1 2]) 0))
f2
user=> (defn f3 [x] (aget (int-array [1 2]) 0))
f3
user=> (defn f4 [^String s] (.indexOf s "a"))
{code}

*Cause:* emitBoxReturn has a hard-coded call to box a prim return value.

*Solution:* If \*unchecked-math* is set to :warn-on-boxed, emit a warning on boxing of primitive numeric return types.

*Patch:*
Alex Miller made changes -
Attachment clj-1585.patch [ 13496 ]
Patch Code [ 10001 ]
Alex Miller made changes -
Priority Major [ 3 ] Minor [ 4 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated: