 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;      Tree Summarizers      ;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(declare sp-ts get-stub-output)
-
-;; Does not need to watch stub, that happens automatically to ensure ordering.
+(declare sp-ts get-stub-output norm-name)
+
 ;; TODO: now this will never be true; how to avoid extra connections ?
-
-(defprotocol TreeSummarizer (ts-stub [ts]))
+(defprotocol TreeSummarizer
+  (ts-stub [ts])
+  (subsuming-tss [ts]) ; True tree summarizers subsuming this one.
+  (add-subsuming-ts! [ts subsuming-ts]))  
+  
 
 (defn- make-tree-summarizer [stb]
-  (let [ret (traits/reify-traits [summaries/or-summarizable summaries/simple-cached-node]
-              TreeSummarizer (ts-stub [ts] stb))]
+  (let [subsuming-tss-list (ArrayList.)
+        ret (traits/reify-traits [summaries/or-summarizable summaries/simple-cached-node]
+              TreeSummarizer
+              (ts-stub [ts] stb)
+              (subsuming-tss [ts] (seq subsuming-tss-list))
+              (add-subsuming-ts! [ts subsuming-ts]
+                (util/assert-is (= (norm-name (stub-name stb)) (norm-name (stub-name (ts-stub subsuming-ts)))))                 
+                (.add subsuming-tss-list subsuming-ts)
+                (summaries/connect-subsumed! subsuming-ts ts)))]
     (when-not (get-stub-output stb)
       (summaries/connect! ret stb)
       (summaries/connect-subsumed! ret stb))

    (set-stub-output! ret (sp-fn ret))
    ret))

;; TODO: Connect ts to something ??
(defn- make-wrapping-stub [[nm in-set] inner-stub sp-fn]
  (let [ret (traits/reify-traits [summaries/or-summarizable watched-node]
              Stub (stub-name       [s] nm)



(defn- make-pair-stub2 [left-sp right-stub]
;  (util/assert-is (= (first (sp-name left-sp)) :SA))
;  (util/assert-is (= (first (stub-name right-stub)) :SA))  
  (let [nm (pair-name (sp-name left-sp) (stub-name right-stub))
        is (input-set (stub left-sp))]
    (assert (= (output-set left-sp) (input-set right-stub)))
