Fork me on GitHub
#babashka
<
2022-05-01
>
Matthew Davidson (kingmob)16:05:35

Do make-array and into-array support specifying types? I see https://github.com/babashka/babashka/issues/1144 was closed, but it’s not working as expected if I specify a type:

(make-array ArrayDeque 5)
: Class java.util.ArrayDeque[] is instantiated reflectively but was never registered. Register the class by using org.graalvm.nativeimage.hosted.RuntimeReflection edit-distance 

(->> (repeatedly 5 #(ArrayDeque.))
     (into-array ArrayDeque))
: Class java.util.ArrayDeque[] is instantiated reflectively but was never registered. Register the class by using org.graalvm.nativeimage.hosted.RuntimeReflection edit-distance 

borkdude17:05:18

@kingmob Just use (into-array Object ...) ?

borkdude17:05:36

Typed arrays need specific reflection support in the native image

borkdude18:05:36

@kingmob Did that make sense?

Matthew Davidson (kingmob)18:05:06

Yeah, that’s what I ended up doing

borkdude18:05:47

@kingmob Do you think it makes sense to fall back on the Object array in case of this error? I didn't know the consequences of that decision

Matthew Davidson (kingmob)18:05:15

It seemed to work out ok

Matthew Davidson (kingmob)18:05:45

Sorry, it’s been ages since I thought about casts in Clojure, it’s 230am here, and my brain is fried from implementing the Hunt-Szymanski LCS algorithm so…lemme think about it 😄

borkdude18:05:33

take it easy :)

👍 1
ambrosebs22:05:33

@U04V15CAJ don't think that makes sense since arrays are covariant.

user=> (cast (class (make-array String 0)) (make-array Object 0))
Execution error (ClassCastException) at java.lang.Class/cast (Class.java:3889).
Cannot cast [Ljava.lang.Object; to [Ljava.lang.String;

borkdude22:05:46

I know, but in practice, I haven't seen any code in Clojure which actually cares about the specific type in an object array?

borkdude22:05:09

I know that Java cares, but within Clojure code objects are usually passed around as Objects

ambrosebs22:05:59

yeah, but why else would you bother creating a non-Object array if not to pass to a Java method that needs it?

ambrosebs00:05:10

nvm didn't realize into-array inferred the type from the args.

ambrosebs00:05:48

thought you were talking about the 2 argument make-array case, carry on.

ambrosebs00:05:57

FWIW I don't remember ever seeing code that cared about the array type that didn't specify it explicitly. Defaulting to Object[] for 1 args into-array makes sense to me. I also agree with https://github.com/babashka/babashka/issues/1144#issuecomment-1013853068

borkdude09:05:36

@U055XFK8V just to be sure, do you think anything should be changed, or not?

ambrosebs14:05:39

@U04V15CAJ tough call! on the fence.

borkdude20:05:24

aw yeah! a source-compatible aws-api for babashka https://twitter.com/grzm/status/1520863547076587520

🎉 6
🚀 5
👍 3
❤️ 1