[pypy-svn] r79416 - in pypy/branch/out-of-line-guards/pypy/rpython: . lltypesystem ootypesystem test

fijal at codespeak.net fijal at codespeak.net
Tue Nov 23 17:09:27 CET 2010


Author: fijal
Date: Tue Nov 23 17:09:25 2010
New Revision: 79416

Modified:
   pypy/branch/out-of-line-guards/pypy/rpython/lltypesystem/rclass.py
   pypy/branch/out-of-line-guards/pypy/rpython/ootypesystem/rclass.py
   pypy/branch/out-of-line-guards/pypy/rpython/rclass.py
   pypy/branch/out-of-line-guards/pypy/rpython/test/test_rclass.py
Log:
Implement _jit_invariant_fields_ on rclass


Modified: pypy/branch/out-of-line-guards/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/out-of-line-guards/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/branch/out-of-line-guards/pypy/rpython/lltypesystem/rclass.py	Tue Nov 23 17:09:25 2010
@@ -366,7 +366,7 @@
                 adtmeths = {}
             if hints is None:
                 hints = {}
-            hints = self._check_for_immutable_hints(hints)
+            hints = self._check_for_hints(hints)
             kwds = {}
             if self.gcflavor == 'gc':
                 kwds['rtti'] = True

Modified: pypy/branch/out-of-line-guards/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/branch/out-of-line-guards/pypy/rpython/ootypesystem/rclass.py	(original)
+++ pypy/branch/out-of-line-guards/pypy/rpython/ootypesystem/rclass.py	Tue Nov 23 17:09:25 2010
@@ -183,7 +183,7 @@
                 hints = classdef.classdesc.pyobj._rpython_hints
             else:
                 hints = {}
-            hints = self._check_for_immutable_hints(hints)
+            hints = self._check_for_hints(hints)
             self.lowleveltype = ootype.Instance(classdef.name, b, {}, {}, _hints = hints)
         self.iprebuiltinstances = identity_dict()
         self.object_type = self.lowleveltype

Modified: pypy/branch/out-of-line-guards/pypy/rpython/rclass.py
==============================================================================
--- pypy/branch/out-of-line-guards/pypy/rpython/rclass.py	(original)
+++ pypy/branch/out-of-line-guards/pypy/rpython/rclass.py	Tue Nov 23 17:09:25 2010
@@ -157,19 +157,27 @@
     def _setup_repr(self):
         pass
 
-    def _check_for_immutable_hints(self, hints):
+    def _check_for_hints(self, hints):
         if self.classdef.classdesc.lookup('_immutable_') is not None:
             hints = hints.copy()
             hints['immutable'] = True
-        self.immutable_field_list = []  # unless overwritten below
+        self.immutable_fields = []  # unless overwritten below
+        self.jit_invariant_fields = []
         if self.classdef.classdesc.lookup('_immutable_fields_') is not None:
             hints = hints.copy()
             immutable_fields = self.classdef.classdesc.classdict.get(
                 '_immutable_fields_')
             if immutable_fields is not None:
-                self.immutable_field_list = immutable_fields.value
+                self.immutable_fields = immutable_fields.value
             accessor = FieldListAccessor()
             hints['immutable_fields'] = accessor
+        if self.classdef.classdesc.lookup('_jit_invariant_fields_') is not None:
+            hints = hints.copy()
+            invariant_fields = self.classdef.classdesc.classdict.get(
+                '_jit_invariant_fields_')
+            self.jit_invariant_fields = invariant_fields.value
+            accessor = FieldListAccessor()
+            hints['jit_invariant_fields'] = accessor
         return hints
 
     def __repr__(self):
@@ -187,20 +195,21 @@
         return 'InstanceR %s' % (clsname,)
 
     def _setup_repr_final(self):
-        self._setup_immutable_field_list()
+        self._setup_field_list('immutable_fields')
         self._check_for_immutable_conflicts()
+        self._setup_field_list('jit_invariant_fields')
 
-    def _setup_immutable_field_list(self):
+    def _setup_field_list(self, varname):
         hints = self.object_type._hints
-        if "immutable_fields" in hints:
-            accessor = hints["immutable_fields"]
+        if varname in hints:
+            accessor = hints[varname]
             if not hasattr(accessor, 'fields'):
-                immutable_fields = []
+                fields = []
                 rbase = self
                 while rbase.classdef is not None:
-                    immutable_fields += rbase.immutable_field_list
+                    fields += getattr(rbase, varname)
                     rbase = rbase.rbase
-                self._parse_field_list(immutable_fields, accessor)
+                self._parse_field_list(fields, accessor)
 
     def _parse_field_list(self, fields, accessor):
         with_suffix = {}
@@ -233,7 +242,7 @@
                     continue
                 if r.lowleveltype == Void:
                     continue
-                base._setup_immutable_field_list()
+                base._setup_field_list('immutable_fields')
                 if base.object_type._immutable_field(mangled):
                     continue
                 # 'fieldname' is a mutable, non-Void field in the parent
@@ -242,7 +251,7 @@
                         "class %r has _immutable_=True, but parent class %r "
                         "defines (at least) the mutable field %r" % (
                         self, base, fieldname))
-                if fieldname in self.immutable_field_list:
+                if fieldname in self.immutable_fields:
                     raise ImmutableConflictError(
                         "field %r is defined mutable in class %r, but "
                         "listed in _immutable_fields_ in subclass %r" % (

Modified: pypy/branch/out-of-line-guards/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/branch/out-of-line-guards/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/branch/out-of-line-guards/pypy/rpython/test/test_rclass.py	Tue Nov 23 17:09:25 2010
@@ -6,6 +6,7 @@
 from pypy.rlib.rarithmetic import intmask, r_longlong
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 from pypy.objspace.flow.model import summary
+from pypy.jit.metainterp.typesystem import deref
 
 class EmptyBase(object):
     pass
@@ -733,7 +734,6 @@
         assert summary(graph) == {}
 
     def test_immutable_fields(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             _immutable_fields_ = ["x", "y[*]"]
 
@@ -749,8 +749,24 @@
         assert accessor.fields == {"inst_x" : "", "inst_y" : "[*]"} or \
                accessor.fields == {"ox" : "", "oy" : "[*]"} # for ootype
 
+    def test_jit_invariant_fields(self):
+        class A(object):
+
+            _jit_invariant_fields_ = ['x']
+            
+            def __init__(self, x):
+                self.x = x
+
+        def f():
+            return A(3)
+
+        t, typer, graph = self.gengraph(f, [])
+        A_TYPE = deref(graph.getreturnvar().concretetype)
+        accessor = A_TYPE._hints["jit_invariant_fields"]
+        assert accessor.fields == {'inst_x': ''} or \
+               accessor.fields == {'ox': ''}
+
     def test_immutable_fields_subclass_1(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             _immutable_fields_ = ["x"]
             def __init__(self, x):
@@ -769,7 +785,6 @@
                accessor.fields == {"ox" : ""} # for ootype
 
     def test_immutable_fields_subclass_2(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             _immutable_fields_ = ["x"]
             def __init__(self, x):
@@ -789,7 +804,6 @@
                accessor.fields == {"ox" : "", "oy" : ""} # for ootype
 
     def test_immutable_fields_only_in_subclass(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             def __init__(self, x):
                 self.x = x
@@ -832,7 +846,6 @@
         py.test.raises(ImmutableConflictError, self.gengraph, f, [])
 
     def test_immutable_ok_inheritance_2(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             _immutable_fields_ = ['v']
         class B(A):
@@ -853,7 +866,6 @@
                accessor.fields == {"ov" : ""} # for ootype
 
     def test_immutable_subclass_1(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             _immutable_ = True
         class B(A):
@@ -866,7 +878,6 @@
         assert B_TYPE._hints["immutable"]    # inherited from A
 
     def test_immutable_subclass_2(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             pass
         class B(A):
@@ -879,7 +890,6 @@
         assert B_TYPE._hints["immutable"]
 
     def test_immutable_subclass_void(self):
-        from pypy.jit.metainterp.typesystem import deref
         class A(object):
             pass
         class B(A):
@@ -917,6 +927,7 @@
         assert destrptr is not None
     
     def test_del_inheritance(self):
+        import gc
         class State:
             pass
         s = State()
@@ -937,6 +948,8 @@
             A()
             B()
             C()
+            gc.collect()
+            gc.collect()
             return s.a_dels * 10 + s.b_dels
         res = f()
         assert res == 42



More information about the Pypy-commit mailing list