11from __future__ import annotations
22
33import os
4+ import weakref
45from copy import copy
56from dataclasses import dataclass , field , fields
67from functools import cached_property
8+ from weakref import WeakKeyDictionary
79
810from rustworkx import PyDiGraph
911from typing_extensions import (
@@ -34,6 +36,7 @@ class PredicateRelation(Relation):
3436 The relation carries the predicate instance that asserted the edge and a flag indicating
3537 whether it was inferred transitively or added directly.
3638 """
39+
3740 source : WrappedInstance
3841 target : WrappedInstance
3942 predicate : BinaryPredicate
@@ -51,6 +54,7 @@ def color(self) -> str:
5154@dataclass
5255class WrappedInstance :
5356 """A node wrapper around a concrete Symbol instance used in the instance graph."""
57+
5458 instance : Symbol
5559 index : Optional [int ] = field (init = False , default = None )
5660 _symbol_graph_ : Optional [SymbolGraph ] = field (
@@ -94,7 +98,9 @@ class SymbolGraph:
9498 _instance_graph : PyDiGraph [WrappedInstance , PredicateRelation ] = field (
9599 default_factory = PyDiGraph
96100 )
97- _instance_index : Dict = field (default_factory = dict , init = False , repr = False )
101+ _instance_index : WeakKeyDictionary [Symbol , WrappedInstance ] = field (
102+ default_factory = WeakKeyDictionary , init = False , repr = False
103+ )
98104 _relation_index : Dict [type , set [tuple [int , int ]]] = field (
99105 default_factory = dict , init = False , repr = False
100106 )
0 commit comments