@@ -49,8 +49,12 @@ class RType:
4949 #
5050 # TODO: This shouldn't be specific to C or a string
5151 c_undefined : str
52- # If unboxed: does the unboxed version use reference counting?
53- is_refcounted = True
52+
53+ @property
54+ def is_refcounted (self ) -> bool :
55+ # If unboxed: does the unboxed version use reference counting?
56+ return True
57+
5458 # C type; use Emitter.ctype() to access
5559 _ctype : str
5660 # If True, error/undefined value overlaps with a valid value. To
@@ -204,7 +208,7 @@ def __init__(
204208
205209 self .name = name
206210 self .is_unboxed = is_unboxed
207- self .is_refcounted = is_refcounted
211+ self ._is_refcounted = is_refcounted
208212 self .is_native_int = is_native_int
209213 self .is_signed = is_signed
210214 self ._ctype = ctype
@@ -233,6 +237,10 @@ def __init__(
233237 else :
234238 assert False , "Unrecognized ctype: %r" % ctype
235239
240+ @property
241+ def is_refcounted (self ) -> bool :
242+ return self ._is_refcounted
243+
236244 def accept (self , visitor : RTypeVisitor [T ]) -> T :
237245 return visitor .visit_rprimitive (self )
238246
@@ -822,12 +830,17 @@ class RInstance(RType):
822830
823831 is_unboxed = False
824832
825- def __init__ (self , class_ir : ClassIR ) -> None :
833+ def __init__ (self , class_ir : ClassIR , is_refcounted : bool = True ) -> None :
826834 # name is used for formatting the name in messages and debug output
827835 # so we want the fullname for precision.
828836 self .name = class_ir .fullname
829837 self .class_ir = class_ir
830838 self ._ctype = "PyObject *"
839+ self ._is_refcounted = is_refcounted
840+
841+ @property
842+ def is_refcounted (self ) -> bool :
843+ return self ._is_refcounted
831844
832845 def accept (self , visitor : RTypeVisitor [T ]) -> T :
833846 return visitor .visit_rinstance (self )
@@ -885,10 +898,6 @@ def accept(self, visitor: RTypeVisitor[T]) -> T:
885898 def is_refcounted (self ) -> bool :
886899 return any (t .is_refcounted for t in self .class_ir .all_attributes ().values ())
887900
888- @is_refcounted .setter
889- def is_refcounted (self , value : bool ) -> None :
890- raise NotImplementedError ("is_refcounted is read-only for RInstanceValue" )
891-
892901 def __repr__ (self ) -> str :
893902 return "<RInstanceValue %s>" % self .name
894903
@@ -1005,7 +1014,10 @@ def __init__(self, item_type: RType, length: int) -> None:
10051014 self .item_type = item_type
10061015 # Number of items
10071016 self .length = length
1008- self .is_refcounted = False
1017+
1018+ @property
1019+ def is_refcounted (self ) -> bool :
1020+ return False
10091021
10101022 def accept (self , visitor : RTypeVisitor [T ]) -> T :
10111023 return visitor .visit_rarray (self )
0 commit comments