Source

pypy / pypy / translator / backendopt / removeassert.py

Diff from to

pypy/translator/backendopt/removeassert.py

 
 def remove_asserts(translator, graphs):
     rtyper = translator.rtyper
+    excdata = rtyper.exceptiondata
     clsdef = translator.annotator.bookkeeper.getuniqueclassdef(AssertionError)
-    r_AssertionError = rclass.getclassrepr(rtyper, clsdef)
-    ll_AssertionError = r_AssertionError.convert_const(AssertionError)
+    ll_AssertionError = excdata.get_standard_ll_exc_instance(rtyper, clsdef)
     total_count = [0, 0]
 
     for graph in graphs:
             join_blocks(graph)
             for link in graph.iterlinks():
                 if (link.target is graph.exceptblock
-                    and isinstance(link.args[0], Constant)
-                    and link.args[0].value == ll_AssertionError):
+                    and isinstance(link.args[1], Constant)
+                    and link.args[1].value == ll_AssertionError):
                     if kill_assertion_link(graph, link):
                         count += 1
                         morework = True
                 log.removeassert("removed %d asserts in %s" % (count, graph.name))
             checkgraph(graph)
             #transform_dead_op_vars(graph, translator)
-    log.removeassert("Could not remove %d asserts, but removed %d asserts." % tuple(total_count))
+    total_count = tuple(total_count)
+    if total_count[0] == 0:
+        if total_count[1] == 0:
+            msg = None
+        else:
+            msg = "Removed %d asserts" % (total_count[1],)
+    else:
+        if total_count[1] == 0:
+            msg = "Could not remove %d asserts" % (total_count[0],)
+        else:
+            msg = "Could not remove %d asserts, but removed %d asserts." % total_count
+    if msg is not None:
+        log.removeassert(msg)
 
 
 def kill_assertion_link(graph, link):