Skip to content

Commit

Permalink
XXX something is weird with typeinstance._code disappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
sklam committed Jan 29, 2024
1 parent 095768c commit 4b6cc78
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions numba/core/types/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def _autoincr():
assert n < 2 ** 32, "Limited to 4 billion types"
return n

_typecache: ptDict[weakref.ref, weakref.ref] = {}

def _on_type_disposal(wr, _pop=_typecache.pop):
_pop(wr, None)
_typecache = weakref.WeakKeyDictionary()


class _TypeMetaclass(ABCMeta):
Expand All @@ -48,15 +45,9 @@ def __init__(cls, name, bases, orig_vars):

def _intern(cls, inst):
# Try to intern the created instance
wr = weakref.ref(inst, _on_type_disposal)
orig = _typecache.get(wr)
orig = orig and orig()
if orig is not None:
return orig
else:
inst._code = _autoincr()
_typecache[wr] = wr
return inst
if inst not in _typecache:
_typecache[inst] = _autoincr()
return inst

def __call__(cls, *args, **kwargs):
"""
Expand Down Expand Up @@ -93,6 +84,10 @@ class Type(metaclass=_TypeMetaclass):
def __init__(self, name):
self.name = name

@property
def _code(self):
return _typecache[self]

@property
def key(self):
"""
Expand Down Expand Up @@ -228,6 +223,8 @@ def is_internal(self):
def dump(self, tab=''):
print(f'{tab}DUMP {type(self).__name__}[code={self._code}, name={self.name}]')



# XXX we should distinguish between Dummy (no meaningful
# representation, e.g. None or a builtin function) and Opaque (has a
# meaningful representation, e.g. ExternalFunctionPointer)
Expand Down

0 comments on commit 4b6cc78

Please sign in to comment.