Fork me on GitHub

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 :)


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).
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


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


(ran into an issue with graalvm with this)


$ bb -e "(count (into-array [1 2 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


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