Skip to content

Commit

Permalink
Fix letfn instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Pedro Monetta Sanchez authored and Juan Pedro Monetta Sanchez committed Jun 6, 2023
1 parent 1d892e1 commit d465d10
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Bugs fixed

- Another fix for extend-type for basic types extensions in ClojureScript
- Fix letfn instrumentation

## 0.1.60 (30-05-2023)

Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
org.clojure/tools.namespace {:mvn/version "1.4.4"}}
:aliases {:dev {:extra-paths ["dev-src"]}
:storm {:classpath-overrides {org.clojure/clojure nil}
:extra-deps {com.github.jpmonettas/flow-storm-dbg {:mvn/version "3.6.0-SNAPSHOT"}
com.github.jpmonettas/clojure {:mvn/version "1.12.0-master-SNAPSHOT"}}
:extra-deps {com.github.jpmonettas/flow-storm-dbg {:mvn/version "3.6.2"}
com.github.jpmonettas/clojure {:mvn/version "1.12.0-alpha3_1"}}
:jvm-opts ["-Dproject-name=hansel" "-Djdk.attach.allowAttachSelf" "-XX:+UnlockDiagnosticVMOptions" "-XX:+DebugNonSafepoints" ;; for the profilers
"-Dflowstorm.startRecording=true"
"-Dclojure.storm.instrumentEnable=true"
Expand Down
33 changes: 31 additions & 2 deletions src/hansel/instrument/forms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,38 @@

[[name & args :as form] ctx]

(let [bindings (->> (first args)
(let [bindings-vec (first args)
bindings (->> bindings-vec
(partition 2))
inst-bindings-vec (if (#{'loop* 'letfn*} name)
inst-bindings-vec (cond
;; don't add any binding for loop* since it will messup the recur call
(= name 'loop*)
bindings-vec

;; don't add any binding since there is nothing to see on the value
;; but instrument fn bodies
(= name 'letfn*)
(->> bindings
(mapcat (fn [[symb x]]
;; like [a (+ 1 2)] will became
;; [a (instrument-form-recursively (+ 1 2))]
;; we have to remove the meta of the form here because
;; the compiler complains if the letfn* fn* form contains any meta
[symb (with-meta (instrument-form-recursively x ctx) {})]))
vec)

;; it is a let*, so we add binding traces after each binding
(= name 'let*)
(->> bindings
(mapcat (fn [[symb x]]
;; like [a (+ 1 2)] will became
;; [a (instrument-form-recursively (+ 1 2))
;; _ (bind-tracer a ...)]
(-> [symb (instrument-form-recursively x ctx)]
(into ['_ (bind-tracer symb (-> form meta ::coor) ctx)]))))
vec))

#_(if (#{'loop* 'letfn*} name)
;; don't mess with the bindings for loop* and letfn*
;; letfn* doesn't make sense since all the bindings are fns and
;; there is nothing to see there.
Expand Down

0 comments on commit d465d10

Please sign in to comment.