[pypy-commit] pypy stm: getarrayitem. Disabled for now because it's missing the C impl.

arigo noreply at buildbot.pypy.org
Thu Nov 3 21:12:45 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48721:104a651020e1
Date: 2011-11-03 21:12 +0100
http://bitbucket.org/pypy/pypy/changeset/104a651020e1/

Log:	getarrayitem. Disabled for now because it's missing the C impl.

diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -397,6 +397,7 @@
 
     'stm_getfield':         LLOp(sideeffects=False, canrun=True),
     'stm_setfield':         LLOp(),
+    'stm_getarrayitem':     LLOp(sideeffects=False, canrun=True),
     'stm_setarrayitem':     LLOp(),
 
     'stm_begin_transaction':            LLOp(),
diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py
--- a/pypy/translator/stm/llstminterp.py
+++ b/pypy/translator/stm/llstminterp.py
@@ -94,6 +94,20 @@
             self.check_stm_mode(lambda m: False)
             assert 0
 
+    def opstm_getarrayitem(self, array, index):
+        ARRAY = lltype.typeOf(struct).TO
+        if ARRAY._immutable_field():
+            # immutable item reads are always allowed
+            return LLFrame.op_getarrayitem(self, array, index)
+        elif ARRAY._gckind == 'raw':
+            # raw getfields are allowed outside a regular transaction
+            self.check_stm_mode(lambda m: m != "regular_transaction")
+            return LLFrame.op_getarrayitem(self, array, index)
+        else:
+            # mutable 'getarrayitems' are always forbidden for now
+            self.check_stm_mode(lambda m: False)
+            assert 0
+
     def opstm_setarrayitem(self, array, index, newvalue):
         ARRAY = lltype.typeOf(struct).TO
         if ARRAY._immutable_field():
@@ -134,6 +148,10 @@
         self.check_stm_mode(lambda m: m != "not_in_transaction")
         LLFrame.op_setfield(self, struct, fieldname, value)
 
+    def opstm_stm_getarrayitem(self, array, index):
+        self.check_stm_mode(lambda m: m != "not_in_transaction")
+        return LLFrame.op_getarrayitem(self, array, index)
+
     def opstm_stm_setarrayitem(self, array, index, value):
         self.check_stm_mode(lambda m: m != "not_in_transaction")
         LLFrame.op_setarrayitem(self, array, index, value)
diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py
--- a/pypy/translator/stm/test/test_transform.py
+++ b/pypy/translator/stm/test/test_transform.py
@@ -56,6 +56,18 @@
     res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
     assert res == 42
 
+def test_getarrayitem():
+    A = lltype.GcArray(lltype.Signed)
+    p = lltype.malloc(A, 100, immortal=True)
+    p[42] = 666
+    def func(p):
+        return p[42]
+    interp, graph = get_interpreter(func, [p])
+    transform_graph(graph)
+    assert summary(graph) == {'stm_getarrayitem': 1}
+    res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
+    assert res == 666
+
 def test_setarrayitem():
     A = lltype.GcArray(lltype.Signed)
     p = lltype.malloc(A, 100, immortal=True)
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
--- a/pypy/translator/stm/transform.py
+++ b/pypy/translator/stm/transform.py
@@ -129,7 +129,18 @@
             op1 = SpaceOperation('stm_setfield', op.args, op.result)
         newoperations.append(op1)
 
-    def stt_setarrayitem(self, newoperations, op):
+    def FINISHME_stt_getarrayitem(self, newoperations, op):
+        ARRAY = op.args[0].concretetype.TO
+        if ARRAY._immutable_field():
+            op1 = op
+        elif ARRAY._gckind == 'raw':
+            turn_inevitable(newoperations, "getarrayitem-raw")
+            op1 = op
+        else:
+            op1 = SpaceOperation('stm_getarrayitem', op.args, op.result)
+        newoperations.append(op1)
+
+    def FINISHME_stt_setarrayitem(self, newoperations, op):
         ARRAY = op.args[0].concretetype.TO
         if ARRAY._immutable_field():
             op1 = op


More information about the pypy-commit mailing list