sci 2022-11-11

has anyone seen this before?

[:clerk] Build failure:
------ ERROR -------------------------------------------------------------------
 File: jar:file:/Users/sritchie/.m2/repository/org/babashka/sci/0.4.33/sci-0.4.33.jar!/sci/impl/namespaces.cljc:1477:20
--------------------------------------------------------------------------------
1474 |    'unchecked-subtract (copy-core-var unchecked-subtract)
1475 |    'unchecked-negate-int (copy-core-var unchecked-negate-int)
1476 |    'unchecked-inc (copy-core-var unchecked-inc)
1477 |    'unchecked-char (copy-core-var unchecked-char)
--------------------------^-----------------------------------------------------
Encountered error when macroexpanding sci.impl.namespaces/copy-var.
NullPointerException: Cannot invoke "clojure.lang.IFn.invoke(Object, Object)" because the return value of "clojure.lang.Var.getRawRoot()" is null
	sci.impl.namespaces/copy-var (namespaces.cljc:91)
	sci.impl.namespaces/copy-var (namespaces.cljc:73)
	clojure.core/apply (core.clj:671)
	clojure.core/apply (core.clj:662)
I am getting this when I try and upgrade clerk, and sci => 0.4.33 from 0.3.5.

@borkdude I can push a repro of course. very odd since this is the 4th project I’m upgrading… obviously I’ll need to find the difference here

check your clojurescript version

org.clojure/clojurescript {:mvn/version "1.11.4"}

I’m making sure it’s getting picked up…

and your shadow-cljs version?

also removing .shadow-cljs might help

thheller/shadow-cljs {:mvn/version "2.17.4"}

that's pretty old, maybe that's the issue

same as on the other projects where it works

well, not that old, so not sure

i’m killing all caches

ah, killing .cpcache got me to a new error

maybe… trying again

nope, same problem. let me try and shrink down the project

feel free to push a repro

smaller repro is better indeed

------ ERROR -------------------------------------------------------------------
 File: /Users/sritchie/code/clj/repro/src/demo/viewers.cljs:33:10
--------------------------------------------------------------------------------
  30 |          #_#_'demo.mathbox (sci/copy-ns demo.mathbox (sci/create-ns 'demo.mathbox))
  31 |
  32 |          'demo.jsxgraph
  33 |          (sci/copy-ns demo.jsxgraph (sci/create-ns 'demo.jsxgraph))
----------------^---------------------------------------------------------------
Encountered error when macroexpanding sci.core/copy-ns.
NullPointerException: Cannot invoke "clojure.lang.IFn.invoke(Object)" because the return value of "clojure.lang.Var.getRawRoot()" is null
	sci.core/copy-ns (core.cljc:409)
	sci.core/copy-ns (core.cljc:362)
	clojure.core/apply (core.clj:671)

the error tightened up when i re-checked out the project. compilation is fine until i use copy-ns on any namespace

(working on a repro, feeding a baby too, sorry for livestream)

it’s a flaky bug, doesn’t happen every time, trying to pin it down

@borkdude there might be an issue, seeing this now:

Encountered error when macroexpanding sci.core/copy-ns.
IllegalStateException: Attempting to call unbound fn: #'sci.impl.cljs/cljs-ns-publics
	clojure.lang.Var$Unbound.throwArity (Var.java:45)
	sci.core/copy-ns (core.cljc:411)

Can you update your repro? I'll clone it locally

yup, will do, going to pin it down now

yikes, deleting .shadow-cljs fixes it

I’m going to keep digging, it is back again

no clerk, sicmutils etc, this is basically just SCI. It seems that if I require either sci.core or anything that transitively requires sci.core in my user namespace, then I get this big error later calling copy-ns in cljs code.

ok, will try

thanks @borkdude, no rush!

This weekend I don't have to give a talk, hehe

FAIR, but still I can work around this now that I know what’s causing it

you are the most productive dude of all time, of course I’m just making it clear that I’m not trying to toss more on your extremely full plate!

Thanks 😅

@borkdude interesting, doesn’t happen with 0.3.5

only with 0.4.33 and 0.5.34

@sritchie09 You can work around this with:

(ns user
  (:require [cljs.analyzer.api]
            [sci.core]))

The issue is that when you load sci.core without loading CLJS cljs.analyzer.api resolves to nil. But then later you are loading SCI again, but as a ClojureScript dependency and the logic that needs the cljs analyzer doesn't have the right var

is there some way to use something like requiring-resolve here if it’s nil?

not without screwing up graalvm builds

what I was doing in user.clj is rebinding some dynamic variables that I use for rendering options, so that when my cljs loads and creates my SCI namespaces I have the proper values set inside of Clerk

I'll take another look at this now

perhaps there is something to improve, perhaps not

it’s odd, presumably cljs is on the classpath at this point. but I am probably misunderstanding the load order

So the issue is in cljs.cljc:

(macros/deftime
  #?(:clj (do (def cljs-ns-publics (resolve 'cljs.analyzer.api/ns-publics))
              (prn :yes cljs-ns-publics)))
  #_:clj-kondo/ignore
  (defmacro ^:private require-cljs-analyzer-api []
    (macros/? :clj
              ;; noop, macro executed from JVM Clojure, not within CLJS compiler
              nil
              :cljs #?(;; macro executed from JVM Clojure, within CLJS compiler
                       :clj
                       (do (require '[cljs.analyzer.api])
                           (def cljs-ns-publics (resolve 'cljs.analyzer.api/ns-publics)))
                       ;; self-hosted CLJS, no require supported but also not necessary
                       :cljs nil))))

The first time you load this, then cljs-ns-publics becomes nil if you have not yet loaded clojurescript

it doesn't require clojurescript since that's an optional dependency. I guess I could use requiring-resolve there (but this requires clojure 1.10) but the downside there is that maybe you do have CLJS on the classpath, but you're not really using it, so then it loads it for nothing

I would argue that the fix for the user there is easy, to exclude cljs

But yeah I hear you

Side effects making life complicated, as usual!

I'm still thinking about an improvement

👍 1

I think I found a solution

for JVM Clojure... now satisfying self-hosted...

always self-hosted :(

ok fix coming up ...

🎉 1

I can do a proper release on monday, so it can be bumped in clerk as well

Excellent trying in 10-15m

@borkdude works great!!

🎉 1

amazing, thank you @borkdude

@borkdude thank you, already on a git sha for sci so I’ll just bump it, no need for a release

👍 1

@sritchie09 I reverted the fix I did to solve the problem since it caused more issues than it solved. Here is a workaround for the user.clj situation https://github.com/babashka/sci#shadow-cljs--userclj

thank you!

👍 1

@borkdude I made this tiny branch to fix some type hint warnings. Not sure if you would go with ^clj or ^js or js/Promise there, I figured ^clj since it should be ok for these to be renamed https://github.com/babashka/sci/compare/master...mhuebert:sci:sci-await-type-hints?expand=1