[pypy-commit] pypy stm: 'transaction_boundary' is better for the transformer.

arigo noreply at buildbot.pypy.org
Fri Oct 28 12:16:24 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48558:cf109f42d6ab
Date: 2011-10-28 11:54 +0200
http://bitbucket.org/pypy/pypy/changeset/cf109f42d6ab/

Log:	'transaction_boundary' is better for the transformer.

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
@@ -10,13 +10,17 @@
     pass
 
 
-def eval_stm_graph(llinterp, graph, values, stm_mode="not_in_transaction"):
+def eval_stm_graph(llinterp, graph, values, stm_mode="not_in_transaction",
+                   final_stm_mode=Ellipsis, automatic_promotion=False):
     llinterp.frame_class = LLSTMFrame
     try:
         llinterp.stm_mode = stm_mode
+        llinterp.stm_automatic_promotion = automatic_promotion
         llinterp.last_transaction_started_in_frame = None
         res = llinterp.eval_graph(graph, values)
-        assert llinterp.stm_mode == stm_mode, (
+        if final_stm_mode is Ellipsis:
+            final_stm_mode = stm_mode
+        assert llinterp.stm_mode == final_stm_mode, (
             "llinterp.stm_mode is %r after eval_graph, but should be %r" % (
             llinterp.stm_mode, stm_mode))
         return res
@@ -43,7 +47,10 @@
     def returning_from_frame_now(self):
         if (self.llinterpreter.stm_mode == "regular_transaction" and
                 self.llinterpreter.last_transaction_started_in_frame is self):
-            raise ReturnWithTransactionActive(self.graph)
+            if self.llinterpreter.stm_automatic_promotion:
+                self.llinterpreter.stm_mode = "inevitable_transaction"
+            else:
+                raise ReturnWithTransactionActive(self.graph)
 
     def getoperationhandler(self, opname):
         ophandler = getattr(self, 'opstm_' + opname, None)
@@ -103,3 +110,8 @@
     def opstm_stm_commit_transaction(self):
         self.check_stm_mode(lambda m: m != "not_in_transaction")
         self.llinterpreter.stm_mode = "not_in_transaction"
+
+    def opstm_stm_transaction_boundary(self):
+        self.check_stm_mode(lambda m: m != "not_in_transaction")
+        self.llinterpreter.stm_mode = "regular_transaction"
+        self.llinterpreter.last_transaction_started_in_frame = self
diff --git a/pypy/translator/stm/rstm.py b/pypy/translator/stm/rstm.py
--- a/pypy/translator/stm/rstm.py
+++ b/pypy/translator/stm/rstm.py
@@ -80,11 +80,15 @@
         _rffi_stm.stm_write_word(p, val)
 
 def begin_transaction():
-    "NOT_RPYTHON"
+    "NOT_RPYTHON.  For tests only"
     raise NotImplementedError("hard to really emulate")
 
 def commit_transaction():
-    "NOT_RPYTHON"
+    "NOT_RPYTHON.  For tests only"
+    raise NotImplementedError("hard to really emulate")
+
+def transaction_boundary():
+    "NOT_RPYTHON.  This is the one normally used"
     raise NotImplementedError("hard to really emulate")
 
 # ____________________________________________________________
@@ -123,7 +127,7 @@
 
 
 class ExtEntry(ExtRegistryEntry):
-    _about_ = (begin_transaction, commit_transaction)
+    _about_ = (begin_transaction, commit_transaction, transaction_boundary)
 
     def compute_result_annotation(self):
         return None
diff --git a/pypy/translator/stm/test/test_llstminterp.py b/pypy/translator/stm/test/test_llstminterp.py
--- a/pypy/translator/stm/test/test_llstminterp.py
+++ b/pypy/translator/stm/test/test_llstminterp.py
@@ -37,7 +37,8 @@
     interp, graph = get_interpreter(func, [p])
     # forbidden in "not_in_transaction" mode
     py.test.raises(ForbiddenInstructionInSTMMode,
-                   eval_stm_graph, interp, graph, [p])
+                   eval_stm_graph, interp, graph, [p],
+                   stm_mode="not_in_transaction")
     # works in "regular_transaction" mode
     res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
     assert res == 42
@@ -106,3 +107,17 @@
     interp, graph = get_interpreter(func, [])
     py.test.raises(ReturnWithTransactionActive,
                    eval_stm_graph, interp, graph, [])
+
+def test_transaction_boundary():
+    def func(n):
+        if n > 5:
+            rstm.transaction_boundary()
+    interp, graph = get_interpreter(func, [2])
+    eval_stm_graph(interp, graph, [10],
+                   stm_mode="regular_transaction",
+                   final_stm_mode="inevitable_transaction",
+                   automatic_promotion=True)
+    eval_stm_graph(interp, graph, [1],
+                   stm_mode="regular_transaction",
+                   final_stm_mode="regular_transaction",
+                   automatic_promotion=True)


More information about the pypy-commit mailing list