Commits

Armin Rigo  committed df4fdd5

transform.py should not touch immutable getfields

  • Participants
  • Parent commits d382548
  • Branches stm

Comments (0)

Files changed (2)

File pypy/translator/stm/test/test_transform.py

 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.test.test_llinterp import get_interpreter
+from pypy.objspace.flow.model import summary
 from pypy.translator.stm.llstminterp import eval_stm_graph
 from pypy.translator.stm.transform import transform_graph
 
         return p.x
     interp, graph = get_interpreter(func, [p])
     transform_graph(graph)
+    assert summary(graph) == {'stm_getfield': 1}
     res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
     assert res == 42
+
+def test_immutable_field():
+    S = lltype.GcStruct('S', ('x', lltype.Signed), hints = {'immutable': True})
+    p = lltype.malloc(S, immortal=True)
+    p.x = 42
+    def func(p):
+        return p.x
+    interp, graph = get_interpreter(func, [p])
+    transform_graph(graph)
+    assert summary(graph) == {'getfield': 1}
+    res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
+    assert res == 42

File pypy/translator/stm/transform.py

             self.transform_block(block)
 
     def stt_getfield(self, newoperations, op):
-        op1 = SpaceOperation('stm_getfield', op.args, op.result)
+        STRUCT = op.args[0].concretetype.TO
+        if STRUCT._immutable_field(op.args[1].value):
+            op1 = op
+        else:
+            op1 = SpaceOperation('stm_getfield', op.args, op.result)
         newoperations.append(op1)
 
     def stt_setfield(self, newoperations, op):