clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
borkdude 2020-12-11T19:46:22.342900Z

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

alexmiller 2020-12-11T19:47:05.343100Z

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

borkdude 2020-12-11T19:48:43.343600Z

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

borkdude 2020-12-11T19:49:07.343800Z

(ran into an issue with graalvm with this)

borkdude 2020-12-11T19:52:03.344600Z

$ 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

2020-12-11T20:26:28.350100Z

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

alexmiller 2020-12-11T20:28:41.351Z

I don’t think so w how inlining works

alexmiller 2020-12-11T20:29:24.352300Z

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

cfleming 2020-12-11T20:49:05.352500Z

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