Skip to content

Commit

Permalink
Move maybe-execute-storm-specials into Compiler.eval to support nrepl…
Browse files Browse the repository at this point in the history
… >= 1.3.0
  • Loading branch information
jpmonettas committed Jul 19, 2024
1 parent 5848c38 commit c8c4f58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- Don't instrument in .class compilation path
- Lein init form instrumentation ignore
- Move maybe-init-flow-storm out of clojure.main/repl to support nrepl >= 1.3.0
- Move maybe-execute-storm-specials into Compiler.eval to support nrepl >= 1.3.0

### Bugs fixed

Expand Down
26 changes: 11 additions & 15 deletions src/clj/clojure/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
;;(:use [clojure.repl :only (demunge root-cause stack-element-str)])
)

(storm-repl/maybe-init-flow-storm)

(declare main)

;;;;;;;;;;;;;;;;;;; redundantly copied from clojure.repl to avoid dep ;;;;;;;;;;;;;;
Expand Down Expand Up @@ -412,11 +414,6 @@ by default when a new command-line REPL is started."} repl-requires
[& options]
(let [cl (.getContextClassLoader (Thread/currentThread))]
(.setContextClassLoader (Thread/currentThread) (clojure.lang.DynamicClassLoader. cl)))

;; the if needed part is because nrepl will call this
;; repl fn on each evaluation. Maybe we should find a better place
;; to initialize flow-storm recordings
(storm-repl/init-flow-storm-if-needed)

(let [{:keys [init need-prompt prompt flush read eval print caught]
:or {init #()
Expand All @@ -440,16 +437,15 @@ by default when a new command-line REPL is started."} repl-requires
(with-read-known (read request-prompt request-exit))
(catch LispReader$ReaderException e
(throw (ex-info nil {:clojure.error/phase :read-source} e))))]
(or (storm-repl/maybe-execute-storm-specials input)
(#{request-prompt request-exit} input)
(let [value (binding [*read-eval* read-eval] (eval input))]
(set! *3 *2)
(set! *2 *1)
(set! *1 value)
(try
(print value)
(catch Throwable e
(throw (ex-info nil {:clojure.error/phase :print-eval-result} e)))))))
(or (#{request-prompt request-exit} input)
(let [value (binding [*read-eval* read-eval] (eval input))]
(set! *3 *2)
(set! *2 *1)
(set! *1 value)
(try
(print value)
(catch Throwable e
(throw (ex-info nil {:clojure.error/phase :print-eval-result} e)))))))
(catch Throwable e
(caught e)
(set! *e e))))]
Expand Down
8 changes: 2 additions & 6 deletions src/clj/clojure/storm/repl.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
(ns clojure.storm.repl
(:import [clojure.storm Emitter Tracer]))

(def ^:private storm-initialized? (atom false))

(defn- call-flow-storm [fn-symb & args]
(try
(let [fqsym (symbol "flow-storm.storm-api" (name fn-symb))
Expand Down Expand Up @@ -41,8 +39,6 @@
:noinst (do (Emitter/setInstrumentationEnable false) true)
(call-flow-storm 'maybe-execute-flow-storm-specials input)))

(defn init-flow-storm-if-needed []
(when-not @storm-initialized?
(call-flow-storm 'start-recorder)
(reset! storm-initialized? true)))
(defn maybe-init-flow-storm []
(call-flow-storm 'start-recorder))

12 changes: 12 additions & 0 deletions src/jvm/clojure/lang/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7925,7 +7925,19 @@ private static void maybeRegisterForm(Integer formId, String file, Object line,

}
}

public static void stormEnhancedReplEval(Object form) {
try {
Var maybeExecuteStormSpecials = Var.find(Symbol.create("clojure.storm.repl", "maybe-execute-storm-specials"));
if (maybeExecuteStormSpecials != null)
((IFn)(maybeExecuteStormSpecials.deref())).invoke(form);
} catch (Exception e) {}
}

public static Object eval(Object form, boolean freshLoader) {

stormEnhancedReplEval(form);

boolean createdLoader = false;

if(true)//!LOADER.isBound())
Expand Down

0 comments on commit c8c4f58

Please sign in to comment.