Fork me on GitHub
#clojure-dev
<
2020-12-11
>
borkdude19:12:22

I guess it's expected that the non-inlined version of alength uses reflection, right?

Alex Miller (Clojure team)19:12:05

well you don't care if it's inlined :)

borkdude19:12:43

maybe the inlined one does as well btw. it's the same.

user=> (. clojure.lang.RT (alength (into-array [1 2 3])))
Reflection warning, NO_SOURCE_PATH:1:1 - call to static method alength on clojure.lang.RT can't be resolved (argument types: unknown).
3
just wanted to check if this is expected

Alex Miller (Clojure team)20:12:41

I don’t think so w how inlining works

Alex Miller (Clojure team)20:12:24

Given the amount of time I’ve spent optimizing array code in bytecode with Clojure, I’m pretty sure I would have noticed that

cfleming20:12:05

Perhaps if it’s inlined, in a lot of cases local inference will take care of it?

borkdude19:12:07

(ran into an issue with graalvm with this)

borkdude19:12:03

$ bb -e "(count (into-array [1 2 3]))"
3
$ bb -e "(alength (into-array [1 2 3]))"
----- Error --------------------------------------------------------------------
Type:     java.lang.ClassNotFoundException
Message:  clojure.lang.RT
^ the last error is because of the reflection at runtime, I think, because it's not statically clear which alength method it's going to call

hiredman20:12:28

Sort of amusing, because the jvm alength instruction doesn't care about the array type, so doesn't require reflection, but you can't write a java method that takes any array type (prims or objects), so RT has a bunch of static methods, alength could call any which introduces reflection