[pypy-commit] pypy default: These should be immutable!

alex_gaynor noreply at buildbot.pypy.org
Sun Jun 30 05:54:53 CEST 2013


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r65117:068f69b29ef0
Date: 2013-06-29 20:53 -0700
http://bitbucket.org/pypy/pypy/changeset/068f69b29ef0/

Log:	These should be immutable!

diff --git a/pypy/module/pypyjit/test_pypy_c/test_containers.py b/pypy/module/pypyjit/test_pypy_c/test_containers.py
--- a/pypy/module/pypyjit/test_pypy_c/test_containers.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_containers.py
@@ -201,10 +201,27 @@
         def main(n):
             i = 0
             while i < n:
-                s = set([1,2,3])
+                s = set([1, 2, 3])
                 i += 1
         log = self.run(main, [1000])
         assert log.result == main(1000)
         loop, = log.loops_by_filename(self.filepath)
         opnames = log.opnames(loop.allops())
         assert opnames.count('new_with_vtable') == 0
+
+    def test_specialised_tuple(self):
+        def main(n):
+            import pypyjit
+
+            f = lambda: None
+            tup = (n, n)
+            while n > 0:
+                tup[0]  # ID: getitem
+                pypyjit.residual_call(f)
+                n -= 1
+
+        log = self.run(main, [1000])
+        assert log.result == main(1000)
+        loop, = log.loops_by_filename(self.filepath)
+        ops = loop.ops_by_id('getitem')
+        assert log.opnames(ops) == []
diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -18,6 +18,8 @@
     iter_n = unrolling_iterable(range(typelen))
 
     class cls(W_AbstractTupleObject):
+        _immutable_fields_ = ['value%s' % i for i in iter_n]
+
         def __init__(self, space, *values_w):
             self.space = space
             assert len(values_w) == typelen


More information about the pypy-commit mailing list