Fork me on GitHub
#sci
<
2022-11-11
>
mhuebert06:11:51

@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

Sam Ritchie15:11:09

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.

Sam Ritchie15:11:49

@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

borkdude15:11:00

check your clojurescript version

Sam Ritchie15:11:21

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

Sam Ritchie15:11:27

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

borkdude15:11:41

and your shadow-cljs version?

borkdude15:11:46

also removing .shadow-cljs might help

Sam Ritchie15:11:49

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

borkdude15:11:59

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

Sam Ritchie15:11:24

same as on the other projects where it works

borkdude15:11:27

well, not that old, so not sure

Sam Ritchie15:11:28

i’m killing all caches

Sam Ritchie15:11:03

ah, killing .cpcache got me to a new error

Sam Ritchie15:11:41

maybe… trying again

Sam Ritchie15:11:29

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

borkdude15:11:50

feel free to push a repro

borkdude15:11:59

smaller repro is better indeed

Sam Ritchie15:11:13

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

Sam Ritchie15:11:42

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

Sam Ritchie15:11:52

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

Sam Ritchie16:11:53

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

Sam Ritchie18:11:26

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.

borkdude18:11:58

ok, will try

borkdude18:11:35

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

Sam Ritchie18:11:07

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

Sam Ritchie18:11:36

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!

borkdude18:11:12

Thanks 😅

Sam Ritchie18:11:17

@borkdude interesting, doesn’t happen with 0.3.5

Sam Ritchie18:11:25

only with 0.4.33 and 0.5.34

borkdude18:11:30

@U017QJZ9M7W You can work around this with:

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

borkdude18:11:01

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

Sam Ritchie18:11:47

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

borkdude18:11:03

not without screwing up graalvm builds

Sam Ritchie18:11:52

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

borkdude18:11:40

I'll take another look at this now

borkdude18:11:47

perhaps there is something to improve, perhaps not

Sam Ritchie18:11:04

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

borkdude18:11:32

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

borkdude18:11:48

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

borkdude18:11:58

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

Sam Ritchie18:11:21

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

Sam Ritchie18:11:25

But yeah I hear you

Sam Ritchie18:11:09

Side effects making life complicated, as usual!

borkdude18:11:51

I'm still thinking about an improvement

👍 1
borkdude19:11:53

I think I found a solution

borkdude19:11:41

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

borkdude19:11:01

always self-hosted :(

borkdude19:11:26

ok fix coming up ...

🎉 1
borkdude20:11:27

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

Sam Ritchie20:11:47

Excellent trying in 10-15m

Sam Ritchie20:11:29

@borkdude works great!!

🎉 1
Sam Ritchie20:11:39

amazing, thank you @borkdude

mkvlr20:11:32

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

👍 1
Sam Ritchie15:11:08

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

borkdude15:11:36

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

Sam Ritchie15:11:55

yup, will do, going to pin it down now

Sam Ritchie15:11:55

yikes, deleting .shadow-cljs fixes it

Sam Ritchie15:11:14

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

borkdude19:11:05

@U017QJZ9M7W 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

Sam Ritchie20:11:47

thank you!

👍 1