         let value = factory(file)
         values[key] = value
         if value is Structure {
-            rebuildAllDeclarationsByType()
+            declarationMapNeedsRebuilding = true
         }
         return value
     }

        }
        return (name, substructure.flatMap({ $0["key.name"] as? String }))
    }
    File.allDeclarationsByType = dictFromKeyValuePairs(allDeclarationsByType)
}

    }

    public static func clearCaches() {
        declarationMapNeedsRebuilding = true
        _allDeclarationsByType = [:]
        structureCache.clear()
        syntaxMapCache.clear()
    }

    public static var allDeclarationsByType: [String: [String]] {
        if declarationMapNeedsRebuilding {
            rebuildAllDeclarationsByType()
        }
        return _allDeclarationsByType
    }
}

private func dictFromKeyValuePairs<Key: Hashable, Value>(pairs: [(Key, Value)]) -> [Key: Value] {
