- ;; TMDM 5.4 and 6.3: union Variants and replace their computed Parent.
- ;; Identifier metadata is not an equality key; reifier remains null.
- (dolist (topic (%topic-map-topics map))
- (loop for pair = (equal-pair (%topic-names topic)
- (lambda (a b)
- (and (string= (%topic-name-value a) (%topic-name-value b))
- (eq (%topic-name-type a) (%topic-name-type b))
- (same-scope-p (%topic-name-scope a) (%topic-name-scope b)))))
- while pair do
- (let* ((a (first pair)) (b (second pair))
- (c (%make-topic-name (%topic-name-value a) (%topic-name-type a) topic)))
- (setf (%topic-name-scope c) (copy-list (%topic-name-scope a))
- (%topic-name-item-identifiers c) (set-union (%topic-name-item-identifiers a) (%topic-name-item-identifiers b) #'string=)
- (%topic-name-variants c) (set-union (%topic-name-variants a) (%topic-name-variants b) #'eq)
- (%topic-names topic) (replace-pair (%topic-names topic) a b c)
- (%topic-name-forward a) c (%topic-name-forward b) c)
- (dolist (item (%topic-name-variants c)) (setf (%variant-parent item) c)))))
+ ;; Rescan live owners after each replacement: merging Reifiers can replace
+ ;; the owner/type/theme of the very Name currently being normalized.
+ (loop for entry = (loop for topic in (%topic-map-topics map)
+ for pair = (equal-pair (%topic-names topic)
+ (lambda (a b) (and (string= (%topic-name-value a) (%topic-name-value b))
+ (eq (%topic-name-type a) (%topic-name-type b))
+ (same-scope-p (%topic-name-scope a) (%topic-name-scope b)))))
+ when pair return (cons topic pair))
+ while entry do
+ (let* ((topic (first entry)) (a (second entry)) (b (third entry))
+ (c (%make-topic-name (%topic-name-value a) (%topic-name-type a) topic)))
+ (setf (%topic-name-scope c) (copy-list (%topic-name-scope a))
+ (%topic-name-item-identifiers c) (set-union (%topic-name-item-identifiers a) (%topic-name-item-identifiers b) #'string=)
+ (%topic-name-variants c) (set-union (%topic-name-variants a) (%topic-name-variants b) #'eq)
+ (%topic-names topic) (replace-pair (%topic-names topic) a b c)
+ (%topic-name-forward a) c (%topic-name-forward b) c)
+ (dolist (v (%topic-name-variants c)) (setf (%variant-parent v) c))
+ (merge-item-reifiers c a b)))