griffinbank / griffinbank/rules_clojure

compile-time use of `construct-proxy`/`definterface` etc. doesn't work due to ClassLoader

Open
#51 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
60
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Clojure assumes that clojure.lang.Compiler/LOADER is a DynamicClassLoader in a few places, but rules-clojure.persistentClassLoader is what's set to the ClassLoader instead. This causes the compilation step to fail. Compiling a namespace referencing a namespace containing (def foo (get-proxy-class ExceptionInfo)) should reproduce the error, with the message :cause class rules_clojure.persistentClassLoader cannot be cast to class clojure.lang.DynamicClassLoader (rules_clojure.persistentClassLoader is in unnamed module of loader 'app'; clojure.lang.DynamicClassLoader is in unnamed module of loader rules_clojure.persistentClassLoader @65ff29ae)

(note: for some reason I have to put that repro in b, and then compile a which :requires b)

~/src/github.com/clojure/clojure master* 
❯ rg '\^.*DynamicClassLoader'           
src/clj/clojure/genclass.clj
722:      (.defineClass ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER)

src/clj/clojure/repl/deps.clj
32:      (.addURL ^DynamicClassLoader loader u)

src/clj/clojure/core_proxy.clj
293:            (. ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode [super interfaces]))))))

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the DynamicClassLoader uses in src/clj/clojure/genclass.clj, src/clj/clojure/repl/deps.clj, and src/clj/clojure/core_proxy.clj, then reproduce the failure by compiling namespace b containing the get-proxy-class form and compiling namespace a that requires b. Trace how rules_clojure.persistentClassLoader becomes Compiler/LOADER. Done means the compile-time proxy case no longer fails with the ClassLoader cast error.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.