     }
 
     public static func clearCaches() {
-        allDeclarationsByType = [:]
+        declarationMapNeedsRebuilding = true
+        _allDeclarationsByType = [:]
         structureCache.clear()
         syntaxMapCache.clear()
     }
 
-    public private(set) static var allDeclarationsByType: [String: [String]] = [:]
+    public static var allDeclarationsByType: [String: [String]] {
+        if declarationMapNeedsRebuilding {
+            rebuildAllDeclarationsByType()
+        }
+        return _allDeclarationsByType
+    }
 }
 
 private func dictFromKeyValuePairs<Key: Hashable, Value>(pairs: [(Key, Value)]) -> [Key: Value] {

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

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