Author: Alex Gaynor <[email protected]>
Branch: 
Changeset: r64409:d64dc3f388ad
Date: 2013-05-21 15:48 -0700
http://bitbucket.org/pypy/pypy/changeset/d64dc3f388ad/

Log:    Don't generate guard_class for an exception when its type is known

diff --git a/rpython/jit/metainterp/pyjitpl.py 
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1053,9 +1053,10 @@
     @arguments("box", "orgpc")
     def opimpl_raise(self, exc_value_box, orgpc):
         # xxx hack
-        clsbox = self.cls_of_box(exc_value_box)
-        self.generate_guard(rop.GUARD_CLASS, exc_value_box, [clsbox],
-                            resumepc=orgpc)
+        if not self.metainterp.heapcache.is_class_known(exc_value_box):
+            clsbox = self.cls_of_box(exc_value_box)
+            self.generate_guard(rop.GUARD_CLASS, exc_value_box, [clsbox],
+                                resumepc=orgpc)
         self.metainterp.class_of_last_exc_is_const = True
         self.metainterp.last_exc_value_box = exc_value_box
         self.metainterp.popframe()
diff --git a/rpython/jit/metainterp/test/test_tracingopts.py 
b/rpython/jit/metainterp/test/test_tracingopts.py
--- a/rpython/jit/metainterp/test/test_tracingopts.py
+++ b/rpython/jit/metainterp/test/test_tracingopts.py
@@ -5,8 +5,6 @@
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rlib.rstring import StringBuilder
 
-import py
-
 
 class TestLLtype(LLJitMixin):
     def test_dont_record_repeated_guard_class(self):
@@ -628,3 +626,22 @@
         res = self.interp_operations(fn, [0])
         assert res == 1
         self.check_operations_history(getarrayitem_gc=0, 
getarrayitem_gc_pure=0)
+
+    def test_raise_known_class_no_guard_class(self):
+        def raise_exc(cls):
+            raise cls
+
+        def fn(n):
+            if n:
+                cls = ValueError
+            else:
+                cls = TypeError
+            try:
+                raise_exc(cls)
+            except ValueError:
+                return -1
+            return n
+
+        res = self.interp_operations(fn, [1])
+        assert res == -1
+        self.check_operations_history(guard_class=0)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to