(defn calculate-deps
"Takes a map of pass-name -> pass-info and adds to each pass-info :dependencies and
:dependants info, which also contain the transitive dependencies"
[passes]
(let [passes (desugar-deps passes)
dependencies (reduce-kv (fn [deps pname {:keys [depends]}]
(calc-deps deps pname depends passes))
{} passes)
dependants (reduce-kv (fn [m k v] (reduce (fn [m v] (update-in m [v] (fnil conj #{}) k))
(update-in m [k] (fnil into #{}) nil) v))
{} dependencies)]
(reduce-kv (fn [m k v] (assoc m k (merge (dissoc (passes k) :depends)
{:dependencies (set v) :dependants (set (dependants k))})))
{} dependencies)))