File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 639
639
(vary-meta dissoc :type )))
640
640
form))
641
641
642
+
643
+ (defn ^:private canonicalize-form
644
+ " Undoes the non-deterministic transformations done by the splicing
645
+ reader macro."
646
+ [form]
647
+ (walk/postwalk (fn [f]
648
+ (if-let [orig-name (and (simple-symbol? f)
649
+ (second (re-matches #"(.*)__\d +__auto__" (name f))))]
650
+ (symbol (str orig-name " #" ))
651
+ f))
652
+ form))
653
+
654
+ (comment
655
+ (canonicalize-form `foo-bar###)
656
+ (canonicalize-form `(let [a# 1 ]
657
+ (inc a#))))
658
+
642
659
(defn hash-codeblock [->hash {:keys [ns graph record-missing-hash-fn]} {:as codeblock :keys [hash form id vars graph-node]}]
643
660
(let [deps (when id (dep/immediate-dependencies graph id))
644
661
hashed-deps (into #{} (keep ->hash) deps)]
653
670
:dep-with-missing-hash dep-with-missing-hash
654
671
:graph-node graph-node :ns ns ))))
655
672
(sha1-base58 (binding [*print-length* nil ]
656
- (pr-str (set/union (conj hashed-deps (if form (remove-type-meta form) hash))
673
+ (pr-str (set/union (conj hashed-deps (if form (-> form remove-type-meta canonicalize- form) hash))
657
674
vars))))))
658
675
659
676
#_(hash-codeblock {} {:graph (dep/graph )} {})
Original file line number Diff line number Diff line change 287
287
" )]
288
288
(is (not (:no-cache? (get ->analysis-info 'nextjournal.clerk.analyzer-test.redefs/a))))
289
289
(is (not (:no-cache? (get ->analysis-info 'nextjournal.clerk.analyzer-test.redefs/b))))
290
- (is (not (:no-cache? (get ->analysis-info 'nextjournal.clerk.analyzer-test.redefs/a#2 )))))))
290
+ (is (not (:no-cache? (get ->analysis-info 'nextjournal.clerk.analyzer-test.redefs/a#2 ))))))
291
+
292
+
293
+ (testing " hashing is determistics for splicing reader macros"
294
+ (let [hash-single-form (fn [form]
295
+ (ana/hash-codeblock {} {:graph (dep/graph )} (ana/analyze form)))]
296
+ (is (= (hash-single-form `(let [a# 1 ]
297
+ (inc a#)))
298
+ (hash-single-form `(let [a# 1 ]
299
+ (inc a#))))))))
291
300
292
301
(deftest analyze-doc
293
302
(testing " reading a bad block shows block and file info in raised exception"
You can’t perform that action at this time.
0 commit comments