Fork me on GitHub
#babashka
<
2020-06-10
>
Mikko Harju07:06:10

Hi! I'm trying to compile the babashka on OS X from sources, and I'm getting this

maharj:babashka git:(master) $ script/uberjar
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 25.252-b09-jvmci-20.1-b02, mixed mode)
Compiling babashka.curl
Compiling babashka.impl.async
Compiling babashka.impl.bencode
Syntax error macroexpanding at (interop.cljc:1:1).
Execution error (UnsupportedClassVersionError) at java.lang.ClassLoader/defineClass1 (ClassLoader.java:-2).
sci/impl/Reflector has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
It seems that something is picking up a different compiler at some stage, but I'm quite baffled what and who? Has someone seen this before?

Mikko Harju07:06:36

This is such an awesome tool – I want to do some JDBC-related stuff so hence the need to do a custom build. Been using the brew-version for quite a while now to do things. Thanks so much for making this 🙂

borkdude11:06:38

I thought I could be clever and resolve static Java fields at analysis time instead of "interpretation" time. But now I realize, these fields could be mutable 😕

borkdude13:06:08

@helios @dominicm

$ export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {aero {:mvn/version "1.1.6"}}}')
$ rlwrap lein bb
user=> (require '[aero.core :refer (read-config)])
nil
user=> (slurp "/tmp/config.edn")
"{:classpath #env \"BABASHKA_CLASSPATH\"}\n"
user=> (-> (read-config "/tmp/config.edn") :classpath (subs 0 50))
"src:feature-xml:feature-core-async:feature-yaml:fe"

parrot 2
borkdude13:06:20

This is with commit cc4ac98795c1134efc48dc1b381124e4937fd7c7. New binary should arrive soon in #babashka_circleci_builds for testing.

borkdude13:06:24

$ time bb -e "(require '[aero.core :refer [read-config]]) (-> (read-config \"/tmp/config.edn\") :classpath (subs 0 100))"
"src:feature-xml:feature-core-async:feature-yaml:feature-csv:feature-transit:feature-java-time:featur"
bb -e    0.03s  user 0.02s system 93% cpu 0.060 total

borkdude13:06:03

There are probably still cases that don't work, so I'd appreciate some testing

jkrasnay15:06:55

Does anyone know how to create a self-running bb script on Windows 10?

borkdude15:06:33

do you mean with a shebang?

jkrasnay15:06:04

Yes. The problem is I don’t have WSL on my work laptop.

borkdude15:06:25

don't know, but if you find it out, it would be nice to document

borkdude16:06:32

@dominicm Small update: I've got a metadata issue with bb + aero in alpha.core/reassemble...

dominicm16:06:20

@borkdude what's the problem? :)

dominicm16:06:42

Oh, you probably don't allow dynamic evaluation like that right?

borkdude16:06:26

This works:

$ clj -A:bb-local -cp src -e "(require '[aero.core :as a]) (a/read-config (java.io.StringReader. \"{:x 1 :y #or [#ref [:x] \\\"bar\\\"]}\"))"
{:x 1, :y 1}
but this doesn't:
$ clj -A:bb-local -cp src -e "(require '[aero.core :as a]) (a/read-config (java.io.StringReader. \"{:y #or [#ref [:x] \\\"bar\\\"]}\"))"
WARNING: Unable to resolve "#ref [:x]" at [:y :form 0]
java.lang.Exception: Cannot call nil as a function. [at line 16, column 3]

borkdude16:06:51

so a dangling ref

dominicm16:06:52

Oh, well boo you slack

borkdude16:06:13

Upload as file is better for large code chunks

jeroenvandijk17:06:54

I’ve found a counter example of where Sci’s :termination-safe true doesn’t (really) protect you. It’s using recursion:

((fn a [n] (if (#{0 1} n) 1 (+ (a (- n 2)) (a (- n 1))))) 20)
With n = 100 I had to kill my jvm. Is this within the scope of Sci?

jeroenvandijk17:06:21

Or with bb:

time bb -e '((fn a [n] (if (#{0 1} n) 1 (+ (a (- n 2)) (a (- n 1)))))  30)'
1346269
bb -e '((fn a [n] (if (#{0 1} n) 1 (+ (a (- n 2)) (a (- n 1)))))  30)'  6.82s user 0.11s system 99% cpu 6.944 total

jeroenvandijk17:06:46

40 doesn’t finish with 5 minutes:

time bb -e '((fn a [n] (if (#{0 1} n) 1 (+ (a (- n 2)) (a (- n 1)))))  40)'
^Cbb -e '((fn a [n] (if (#{0 1} n) 1 (+ (a (- n 2)) (a (- n 1)))))  40)'  287.09s user 1.22s system 99% cpu 4:49.90 total

jeroenvandijk17:06:07

I’m guessing protection against situations like this would require a counting mechanism at the interpreter level https://github.com/borkdude/sci/blob/master/src/sci/impl/interpreter.cljc#L537 Not sure what other consequences this would have

borkdude19:06:04

@dominicm yes!

$ clj -A:bb-local -cp src -e "(require '[aero.core :as a]) (a/read-config (java.io.StringReader. \"{:y #or [#ref [:x] \\\"bar\\\"]}\"))"
WARNING: Unable to resolve "#ref [:x]" at [:y :form 0]
{:y "bar"}

borkdude20:06:17

Woohoo, all aero tests are now passing in bb except for one minor thing which I know how to fix.

metal 1
dominicm20:06:01

This is really exciting… I'm wondering what crazy things I can do with this. One idea is a CLI migration tool that will read my config.edn without paying a startup penalty!

dominicm20:06:14

Or maybe static analysis of my config file for linting purposes… so many ideas!

borkdude22:06:53

@dominicm for static analysis, you might also want to look at: https://github.com/babashka/pod-babashka-parcera

borkdude22:06:41

babashka v0.1.1: https://github.com/borkdude/babashka/blob/master/CHANGELOG.md#v011-2020-06-10 This release can now run clj-commons/camel-snake-kebab and juxt/aero as libraries.