Author: Carl Friedrich Bolz <[email protected]>
Branch: remove-objspace-options
Changeset: r83869:f77dd6069673
Date: 2016-04-25 17:16 +0300
http://bitbucket.org/pypy/pypy/changeset/f77dd6069673/

Log:    (cfbolz, arigo advising) test the cutoff and make it less random

diff --git a/rpython/translator/backendopt/test/test_writeanalyze.py 
b/rpython/translator/backendopt/test/test_writeanalyze.py
--- a/rpython/translator/backendopt/test/test_writeanalyze.py
+++ b/rpython/translator/backendopt/test/test_writeanalyze.py
@@ -313,6 +313,38 @@
         assert name2.endswith("x")
         assert T1 == T2
 
+    def test_cutoff(self):
+        from rpython.rlib.unroll import unrolling_iterable
+        cutoff = 20
+        attrs = unrolling_iterable(["s%s" % i for i in range(cutoff + 5)])
+
+        class A(object):
+            def __init__(self, y):
+                for attr in attrs:
+                    setattr(self, attr, y)
+            def f(self):
+                self.x = 1
+                res = 0
+                for attr in attrs:
+                    res += getattr(self, attr)
+                return res
+
+        def h(flag):
+            obj = A(flag)
+            return obj.f()
+
+        t, wa = self.translate(h, [int])
+        wa.cutoff = cutoff
+        hgraph = graphof(t, h)
+        op_call_f = hgraph.startblock.operations[-1]
+
+        # check that we fished the expected ops
+        assert op_call_f.opname == "direct_call"
+        assert op_call_f.args[0].value._obj._name == 'A.f'
+
+        result = wa.analyze(op_call_f)
+        assert result is top_set
+
     def test_contains(self):
         def g(x, y, z):
             l = [x]
diff --git a/rpython/translator/backendopt/writeanalyze.py 
b/rpython/translator/backendopt/writeanalyze.py
--- a/rpython/translator/backendopt/writeanalyze.py
+++ b/rpython/translator/backendopt/writeanalyze.py
@@ -7,6 +7,8 @@
 CUTOFF = 1000
 
 class WriteAnalyzer(graphanalyze.GraphAnalyzer):
+    cutoff = CUTOFF
+
     def bottom_result(self):
         return empty_set
 
@@ -22,9 +24,9 @@
     def add_to_result(self, result, other):
         if other is top_set:
             return top_set
-        if len(other) + len(result) > CUTOFF:
+        result.update(other)
+        if len(result) > self.cutoff:
             return top_set
-        result.update(other)
         return result
 
     def finalize_builder(self, result):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to