|
539 | 539 | init-state (if ran-macros? |
540 | 540 | (init-state-fn) |
541 | 541 | init-state)] |
542 | | - (loop [{:as state :keys [->analysis-info analyzed-file-set counter]} |
543 | | - init-state] |
| 542 | + (loop [{:as state :keys [->analysis-info analyzed-file-set counter]} init-state] |
544 | 543 | (let [unhashed (unhashed-deps ->analysis-info) |
545 | 544 | loc->syms (apply dissoc |
546 | 545 | (group-by find-location unhashed) |
|
569 | 568 | make-deps-inherit-no-cache |
570 | 569 | (dissoc :analyzed-file-set :counter))))))) |
571 | 570 |
|
| 571 | +(comment |
| 572 | + (reset! !file->analysis-cache {}) |
| 573 | + |
| 574 | + (def parsed (parser/parse-file {:doc? true} "src/nextjournal/clerk/webserver.clj")) |
| 575 | + (def analysis (time (-> parsed analyze-doc build-graph))) |
| 576 | + (-> analysis :->analysis-info keys set) |
| 577 | + (let [{:keys [->analysis-info]} analysis] |
| 578 | + (dissoc (group-by find-location (unhashed-deps ->analysis-info)) nil)) |
| 579 | + (nextjournal.clerk/clear-cache!)) |
| 580 | + |
572 | 581 | #_(do (time (build-graph (parser/parse-clojure-string (slurp "notebooks/how_clerk_works.clj")))) :done) |
573 | 582 | #_(do (time (build-graph (parser/parse-clojure-string (slurp "notebooks/viewer_api.clj")))) :done) |
574 | 583 |
|
|
595 | 604 |
|
596 | 605 |
|
597 | 606 | (defn ^:private canonicalize-form |
598 | | - "Undoes the non-deterministic transformations done by the splicing |
599 | | - reader macro." |
| 607 | + "Undoes the non-deterministic transformations done by the splicing reader macro." |
600 | 608 | [form] |
601 | 609 | (walk/postwalk (fn [f] |
602 | 610 | (if-let [orig-name (and (simple-symbol? f) |
|
612 | 620 |
|
613 | 621 | (defn hash-codeblock [->hash {:keys [ns graph record-missing-hash-fn]} {:as codeblock :keys [hash form id vars graph-node]}] |
614 | 622 | (let [deps (when id (dep/immediate-dependencies graph id)) |
615 | | - hashed-deps (into #{} (keep ->hash) deps)] |
| 623 | + hashed-deps (into (sorted-set) (keep ->hash) deps)] |
616 | 624 | ;; NOTE: missing hashes on deps might occur e.g. when some dependencies are interned at runtime |
617 | 625 | (when record-missing-hash-fn |
618 | 626 | (when-some [dep-with-missing-hash |
|
623 | 631 | (record-missing-hash-fn (assoc codeblock |
624 | 632 | :dep-with-missing-hash dep-with-missing-hash |
625 | 633 | :graph-node graph-node :ns ns)))) |
626 | | - (sha1-base58 (binding [*print-length* nil] |
627 | | - (pr-str (set/union (conj hashed-deps (if form (-> form remove-type-meta canonicalize-form) hash)) |
628 | | - vars)))))) |
| 634 | + (binding [*print-length* nil] |
| 635 | + (let [form-with-deps-sorted |
| 636 | + (-> hashed-deps |
| 637 | + (conj (if form |
| 638 | + (-> form remove-type-meta canonicalize-form pr-str) |
| 639 | + hash)) |
| 640 | + (into (map str) vars))] |
| 641 | + (sha1-base58 (pr-str form-with-deps-sorted)))))) |
629 | 642 |
|
630 | 643 | #_(hash-codeblock {} {:graph (dep/graph)} {}) |
631 | 644 | #_(hash-codeblock {} {:graph (dep/graph)} {:hash "foo"}) |
|
0 commit comments