Fork me on GitHub
#babashka
<
2021-02-27
>
borkdude09:02:06

@wilkerlucio Should now work on master :)

./bb -e '(defprotocol Foo (foo [_])) (extend-protocol Foo clojure.lang.Atom (foo [this] @this)) (foo (atom 1))'
1

wilkerlucio11:02:19

good luck! 👍

wilkerlucio11:02:09

seems like my utils are compiling fine now!

wilkerlucio11:02:47

this is the next I found 🙂

----- Error --------------------------------------------------------------------
Type:     java.lang.IllegalArgumentException
Message:  No implementation of method: :getName of protocol: #'sci.impl.vars/HasName found for class: nil
Location: /Users/wilkerlucio/Development/pathom3/src/main/com/wsscode/pathom3/connect/operation.cljc:53:1

----- Context ------------------------------------------------------------------
49: ; endregion
50:
51: ; region records
52:
53: (defrecord Resolver [config resolve]
    ^--- No implementation of method: :getName of protocol: #'sci.impl.vars/HasName found for class: nil
54:   pop/IOperation
55:   (-operation-config [_] config)
56:   (-operation-type [_] ::operation-type-resolver)
57:
58:   pop/IResolver

----- Stack trace --------------------------------------------------------------
com.wsscode.pathom3.connect.operation - /Users/wilkerlucio/Development/pathom3/src/main/com/wsscode/pathom3/connect/operation.cljc:53:1

borkdude11:02:33

Can you make a repro?

borkdude11:02:27

If you will push your dev branch, I will try locally

borkdude11:02:14

E.g. this works:

$ ./bb -e '(ns p) (defprotocol Foo (foo [_])) (ns r (:require p)) (defrecord Bar [x] p/Foo (foo [this] x)) (p/foo (->Bar 1))'
1

borkdude11:02:37

so I'm not sure what edge case you're hitting here

wilkerlucio11:02:17

working on the repro

wilkerlucio11:02:43

got it:

(ns pathom
  (:require [babashka.deps :as deps]))

(deps/add-deps
  '{:deps {borkdude/spartan.spec      {:git/url ""
                                       :sha     "ef1fd1564d559dd446b3c11a35674eb9531e73b2"}
           com.wsscode/cljc-misc      {:git/url ""
                                       :sha     "bd48f6d1643a76db0d7046b5a007dfe77850e3db"}
           com.wsscode/pathom3        {:git/url ""
                                       :sha     "d0ef2f59dd9a83ddb4130cb7898926670ce89be9"}
           com.fulcrologic/guardrails {:git/url ""
                                       :sha     "b777e4244f9b608d5f4de0d74296ce3bb1ed732c"}}})

;; Loading spartan.spec will create a namespace clojure.spec.alpha for compatibility:
(require 'spartan.spec)
(alias 's 'clojure.spec.alpha)

; Expound expects some vars to be there, like `with-gen`. Spartan prints warnings that these are used, but doesn't implement them yet.
(require '[com.wsscode.pathom3.connect.operation :as pco])

wilkerlucio11:02:39

ok, got it simpler

wilkerlucio11:02:50

its about trying to extend clojure.lang.IFn

wilkerlucio11:02:53

(ns repro
  (:require [babashka.deps :as deps]))

(defrecord FnExtender
   clojure.lang.IFn
  (invoke [_this] nil)
  (invoke [_this input] nil)
  (invoke [_this env input] nil))

borkdude11:02:33

This is a nasty edge case in babashka: reify works on protocols OR classes, but not both at the same time. This is a limitation related to not being able to define new classes in a graalvm native image

wilkerlucio11:02:53

gotcha, gonna try to ignore the FN extension at definition on babashka

wilkerlucio11:02:06

this is not required for pathom to work, is more a user convenience

wilkerlucio12:02:05

just got my first pathom output in babashka! 😄 🎉

wilkerlucio12:02:55

just the defresolver macro still doesn't work

wilkerlucio12:02:23

when I try to use that, I get:

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Parameter declaration missing.
Phase:    analysis

borkdude12:02:37

OK, repro would be nice

wilkerlucio12:02:43

ok, one moment

wilkerlucio12:02:44

(ns pathom
  (:require [babashka.deps :as deps]))

(deps/add-deps
  '{:deps {borkdude/spartan.spec      {:git/url ""
                                       :sha     "ef1fd1564d559dd446b3c11a35674eb9531e73b2"}
           com.wsscode/cljc-misc      {:git/url ""
                                       :sha     "bd48f6d1643a76db0d7046b5a007dfe77850e3db"}
           com.wsscode/pathom3        {:git/url ""
                                       :sha     "ef871acc1e3302f95aae404369d0fdd50ccd9b63"}
           com.fulcrologic/guardrails {:git/url ""
                                       :sha     "b777e4244f9b608d5f4de0d74296ce3bb1ed732c"}}})

;; Loading spartan.spec will create a namespace clojure.spec.alpha for compatibility:
(require 'spartan.spec)
(alias 's 'clojure.spec.alpha)

; Expound expects some vars to be there, like `with-gen`. Spartan prints warnings that these are used, but doesn't implement them yet.
(require '[com.wsscode.pathom3.connect.operation :as pco])

(pco/defresolver foo [] {})

borkdude12:02:54

Can you maybe look at the macro expansion of this, to see if there's anything weird?

wilkerlucio12:02:33

I'm guessing now its about a unform usage inside of it

wilkerlucio12:02:04

and parameter declaration missing makes sense to me in this case

wilkerlucio12:02:12

because the args parts are coming from unform

borkdude12:02:17

Maybe we can support this in spartan, I just haven't implemented it yet

wilkerlucio12:02:00

you think its an easy one to get in?

wilkerlucio12:02:58

I'm taking a look, its seems mostly about having that interface implemented for different types from spec

borkdude12:02:17

I think so. We just need to add :unform to all the specs and copy it from spec.alpha proper

wilkerlucio12:02:18

cool, but no big priority on it, for me at least, I can make my thing work easely without that 🙂

wilkerlucio12:02:50

but thinking here, would be cool and better to have that, more reach, I was looking in spartan code, not sure how to add the unform, if you can kick it out, I can fill in the implementation for others, should I open an issue for that?

borkdude12:02:32

please do. just check all the places where :cform occurs, we should add something like :unform there. Instead of reify spartan.spec just uses maps to implement all the spec stuff

wilkerlucio12:02:49

I'm working on it now

borkdude13:02:27

That's fast :)

borkdude13:02:50

I'm looking into .dispatchFn if there is a core fn for this like get-method, etc

borkdude13:02:06

It seems CLJS has dispatch-fn

borkdude13:02:59

user=> (def mm (defmulti foo identity))
#'user/mm
user=> @mm
#object[clojure.lang.MultiFn 0x27b000f7 "clojure.lang.MultiFn@27b000f7"]
user=> (.dispatchFn @mm)
#object[clojure.core$identity 0xde88ac6 "clojure.core$identity@de88ac6"]

wilkerlucio13:02:34

cool! with that my defresolver works without changes 🙂

borkdude13:02:08

Cool! I left a few remarks, some of them should not be necessary anymore on bb master

wilkerlucio13:02:36

fixed that one 👍

borkdude15:11:25

@wilkerlucio Do you remember why we were talking about dispatch-fn?

borkdude15:11:51

I added that issue there that came out of our conversation here.

wilkerlucio18:11:01

sorry, I don't remember the context

wilkerlucio11:02:47

this is the next I found 🙂

----- Error --------------------------------------------------------------------
Type:     java.lang.IllegalArgumentException
Message:  No implementation of method: :getName of protocol: #'sci.impl.vars/HasName found for class: nil
Location: /Users/wilkerlucio/Development/pathom3/src/main/com/wsscode/pathom3/connect/operation.cljc:53:1

----- Context ------------------------------------------------------------------
49: ; endregion
50:
51: ; region records
52:
53: (defrecord Resolver [config resolve]
    ^--- No implementation of method: :getName of protocol: #'sci.impl.vars/HasName found for class: nil
54:   pop/IOperation
55:   (-operation-config [_] config)
56:   (-operation-type [_] ::operation-type-resolver)
57:
58:   pop/IResolver

----- Stack trace --------------------------------------------------------------
com.wsscode.pathom3.connect.operation - /Users/wilkerlucio/Development/pathom3/src/main/com/wsscode/pathom3/connect/operation.cljc:53:1

wilkerlucio15:02:37

nice! is there gonna be a video available of the talk?

borkdude15:02:30

It is recorded, but I don't know if it and when will be publicly available

wilkerlucio16:02:41

cool, and how was it? had fun doing it?

borkdude16:02:37

It's always a bit weird to speak before non-Clojure community about Clojure, but I think it went well

borkdude16:02:33

There are several talks going on now how they are using GraalVM at Facebook, Shopify, etc.

👀 3
borkdude16:02:45

Also academic talks about comining machine learning with compiler optimizations