[pypy-commit] pypy stm-gc: Special-case 'instantiate'.

arigo noreply at buildbot.pypy.org
Thu Feb 16 13:05:25 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r52548:1add335091c6
Date: 2012-02-16 13:05 +0100
http://bitbucket.org/pypy/pypy/changeset/1add335091c6/

Log:	Special-case 'instantiate'.

diff --git a/pypy/translator/stm/gcsource.py b/pypy/translator/stm/gcsource.py
--- a/pypy/translator/stm/gcsource.py
+++ b/pypy/translator/stm/gcsource.py
@@ -1,5 +1,5 @@
 from pypy.objspace.flow.model import Variable
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, rclass
 from pypy.translator.simplify import get_graph
 
 
@@ -62,6 +62,19 @@
                         for tograph in tographs:
                             call(tograph, op.args[1:-1], op.result)
                         continue
+                    # special-case to detect 'instantiate'
+                    is_instantiate = False
+                    v_func = op.args[0]
+                    for op1 in block.operations:
+                        if (v_func is op1.result and
+                            op1.opname == 'getfield' and
+                            op1.args[0].concretetype == rclass.CLASSTYPE and
+                            op1.args[1].value == 'instantiate'):
+                            is_instantiate = True
+                            break
+                    if is_instantiate:
+                        resultlist.append(('instantiate', op.result))
+                        continue
                 #
                 if _is_gc(op.result):
                     resultlist.append((op, op.result))
diff --git a/pypy/translator/stm/localtracker.py b/pypy/translator/stm/localtracker.py
--- a/pypy/translator/stm/localtracker.py
+++ b/pypy/translator/stm/localtracker.py
@@ -29,6 +29,8 @@
                     return False
             elif src is None:
                 return False
+            elif src == 'instantiate':
+                pass
             else:
-                raise AssertionError(src)
+                raise AssertionError(repr(src))
         return True
diff --git a/pypy/translator/stm/test/test_localtracker.py b/pypy/translator/stm/test/test_localtracker.py
--- a/pypy/translator/stm/test/test_localtracker.py
+++ b/pypy/translator/stm/test/test_localtracker.py
@@ -199,6 +199,17 @@
         self.translate(f, [int])
         self.check([])
 
+    def test_instantiate_returns_fresh_object(self):
+        def f(n):
+            if n > 5:
+                cls = X
+            else:
+                cls = Y
+            _see(cls(n), 'x')
+        #
+        self.translate(f, [int])
+        self.check(['x'])
+
 
 S = lltype.GcStruct('S', ('n', lltype.Signed))
 


More information about the pypy-commit mailing list