[pypy-svn] r61960 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

fijal at codespeak.net fijal at codespeak.net
Tue Feb 17 09:55:48 CET 2009


Author: fijal
Date: Tue Feb 17 09:55:46 2009
New Revision: 61960

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py
Log:
Tests and fixes. Disable lazy list optimization for now
(as it requires knowledge about append/pop operations as well)


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	Tue Feb 17 09:55:46 2009
@@ -285,8 +285,8 @@
             self.dependency_graph.append((instnode, fieldnode))
             instnode.origfields[field] = fieldnode
         self.nodes[box] = fieldnode
-        if self.first_escaping_op:
-            instnode.expanded_fields[field] = None
+        #if self.first_escaping_op:
+        #    instnode.expanded_fields[field] = None
 
     def find_nodes_insert(self, instnode, field, fieldnode):
         for ofs, node in instnode.curfields.items():
@@ -363,6 +363,9 @@
                     continue
                 else:
                     instnode.escaped = True
+                    self.nodes[op.results[0]] = InstanceNode(op.results[0],
+                                                             escaped=True)
+                    continue
             elif opname == 'append':
                 instnode = self.getnode(op.args[1])
                 assert isinstance(instnode.cls.source, ListDescr)
@@ -397,6 +400,11 @@
                         del instnode.curfields[field]                
                     print instnode, instnode.curfields, instnode.known_length
                     continue
+                self.nodes[op.results[0]] = InstanceNode(op.results[0],
+                                                         escaped=True)
+                self.dependency_graph.append((instnode,
+                                              self.nodes[op.results[0]]))
+                continue
             elif opname == 'len' or opname == 'listnonzero':
                 instnode = self.getnode(op.args[1])
                 if not instnode.escaped:
@@ -415,9 +423,11 @@
                     assert field < instnode.known_length
                     self.find_nodes_setfield(instnode, field,
                                              self.getnode(op.args[3]))
-                    print instnode, instnode.curfields, instnode.known_length
+                    print "XXX", instnode, " <- ", self.getnode(fieldbox)
                     continue
                 else:
+                    self.dependency_graph.append((instnode,
+                                                 self.getnode(op.args[3])))
                     instnode.escaped = True
             elif opname == 'guard_class':
                 instnode = self.getnode(op.args[0])
@@ -712,21 +722,21 @@
             elif opname == 'append':
                 instnode = self.nodes[op.args[1]]
                 valuenode = self.getnode(op.args[2])
-                if instnode.virtual:
+                if not instnode.escaped:
                     ofs = instnode.known_length
                     instnode.known_length = instnode.known_length + 1
                     self.optimize_setfield(instnode, ofs, valuenode, op.args[2])
                     continue
             elif opname == 'insert':
                 instnode = self.nodes[op.args[1]]
-                if instnode.virtual:
+                if not instnode.escaped:
                     ofs = self.getsource(op.args[2]).getint()
                     valuenode = self.nodes[op.args[3]]
                     self.optimize_insert(instnode, ofs, valuenode, op.args[3])
                     continue
             elif opname == 'pop':
                 instnode = self.nodes[op.args[1]]
-                if instnode.virtual:
+                if not instnode.escaped:
                     instnode.known_length = instnode.known_length - 1
                     ofs = instnode.known_length
                     if self.optimize_getfield(instnode, ofs, op.results[0]):

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py	Tue Feb 17 09:55:46 2009
@@ -44,7 +44,6 @@
         assert res == 42
 
     def test_accumulator(self):
-        py.test.skip("x")
         path = py.path.local(tlc.__file__).dirpath('accumulator.tlc.src')
         code = path.read()
         res = self.exec_code(code, 20)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py	Tue Feb 17 09:55:46 2009
@@ -279,7 +279,25 @@
         res = self.meta_interp(f, [30])
         assert res == 0
         self.check_loops(append=1)
-        
+
+    def test_virtual_escaping_via_list(self):
+        jitdriver = JitDriver(greens = [], reds = ['n', 'l'])
+        class Stuff(object):
+            def __init__(self, x):
+                self.x = x
+
+        def f(n):
+            l = [Stuff(n-i) for i in range(n)]
+
+            while n > 0:
+                jitdriver.can_enter_jit(n=n, l=l)
+                jitdriver.jit_merge_point(n=n, l=l)
+                s = l.pop()
+                n -= s.x
+
+        res = self.meta_interp(f, [20])
+        assert res == f(20)
+        self.check_loops(pop=1, getfield_gc=1)
 
     def test_extend(self):
         py.test.skip("XXX")



More information about the Pypy-commit mailing list