[pypy-commit] pypy default: Create rpython.rtyper.debug and move ll_assert() and fatalerror() there.

rlamy pypy.commits at gmail.com
Fri Feb 5 11:52:33 EST 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r82091:45cce2525cc9
Date: 2016-02-05 03:45 +0000
http://bitbucket.org/pypy/pypy/changeset/45cce2525cc9/

Log:	Create rpython.rtyper.debug and move ll_assert() and fatalerror()
	there.

	This reduces the number of imports from rpython/rtyper/ to
	rpython.rlib and avoids a cyclical import dependency.

diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -1,76 +1,41 @@
-import sys, time
+import sys
+import time
+
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.rlib.objectmodel import we_are_translated
 from rpython.rlib.rarithmetic import is_valid_int
 from rpython.rtyper.extfunc import ExtFuncEntry
 from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem import rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 
-
-def ll_assert(x, msg):
-    """After translation to C, this becomes an RPyAssert."""
-    assert type(x) is bool, "bad type! got %r" % (type(x),)
-    assert x, msg
-
-class Entry(ExtRegistryEntry):
-    _about_ = ll_assert
-
-    def compute_result_annotation(self, s_x, s_msg):
-        assert s_msg.is_constant(), ("ll_assert(x, msg): "
-                                     "the msg must be constant")
-        return None
-
-    def specialize_call(self, hop):
-        vlist = hop.inputargs(lltype.Bool, lltype.Void)
-        hop.exception_cannot_occur()
-        hop.genop('debug_assert', vlist)
-
-class FatalError(Exception):
-    pass
-
-def fatalerror(msg):
-    # print the RPython traceback and abort with a fatal error
-    if not we_are_translated():
-        raise FatalError(msg)
-    from rpython.rtyper.lltypesystem import lltype
-    from rpython.rtyper.lltypesystem.lloperation import llop
-    llop.debug_print_traceback(lltype.Void)
-    llop.debug_fatalerror(lltype.Void, msg)
-fatalerror._dont_inline_ = True
-fatalerror._jit_look_inside_ = False
-fatalerror._annenforceargs_ = [str]
-
-def fatalerror_notb(msg):
-    # a variant of fatalerror() that doesn't print the RPython traceback
-    if not we_are_translated():
-        raise FatalError(msg)
-    from rpython.rtyper.lltypesystem import lltype
-    from rpython.rtyper.lltypesystem.lloperation import llop
-    llop.debug_fatalerror(lltype.Void, msg)
-fatalerror_notb._dont_inline_ = True
-fatalerror_notb._jit_look_inside_ = False
-fatalerror_notb._annenforceargs_ = [str]
+# Expose these here (public interface)
+from rpython.rtyper.debug import (
+    ll_assert, FatalError, fatalerror, fatalerror_notb)
 
 
 class DebugLog(list):
     def debug_print(self, *args):
         self.append(('debug_print',) + args)
+
     def debug_start(self, category, time=None):
         self.append(('debug_start', category, time))
+
     def debug_stop(self, category, time=None):
-        for i in xrange(len(self)-1, -1, -1):
+        for i in xrange(len(self) - 1, -1, -1):
             if self[i][0] == 'debug_start':
                 assert self[i][1] == category, (
                     "nesting error: starts with %r but stops with %r" %
                     (self[i][1], category))
                 starttime = self[i][2]
                 if starttime is not None or time is not None:
-                    self[i:] = [(category, starttime, time, self[i+1:])]
+                    self[i:] = [(category, starttime, time, self[i + 1:])]
                 else:
-                    self[i:] = [(category, self[i+1:])]
+                    self[i:] = [(category, self[i + 1:])]
                 return
         assert False, ("nesting error: no start corresponding to stop %r" %
                        (category,))
+
     def __repr__(self):
         import pprint
         return pprint.pformat(list(self))
@@ -161,7 +126,6 @@
             return self.bookkeeper.immutablevalue(False)
 
     def specialize_call(self, hop):
-        from rpython.rtyper.lltypesystem import lltype
         t = hop.rtyper.annotator.translator
         hop.exception_cannot_occur()
         if t.config.translation.log:
@@ -189,7 +153,6 @@
         return annmodel.SomeInteger()
 
     def specialize_call(self, hop):
-        from rpython.rtyper.lltypesystem import lltype
         hop.exception_cannot_occur()
         return hop.genop('debug_offset', [], resulttype=lltype.Signed)
 
@@ -223,7 +186,6 @@
         return None
 
     def specialize_call(self, hop):
-        from rpython.rtyper.lltypesystem import lltype
         vlist = hop.inputargs(lltype.Signed)
         hop.exception_cannot_occur()
         return hop.genop('debug_forked', vlist)
@@ -244,7 +206,6 @@
     def compute_result_annotation(self, s_RESTYPE, s_pythonfunction, *args_s):
         from rpython.annotator import model as annmodel
         from rpython.rtyper.llannotation import lltype_to_annotation
-        from rpython.rtyper.lltypesystem import lltype
         assert s_RESTYPE.is_constant()
         assert s_pythonfunction.is_constant()
         s_result = s_RESTYPE.const
@@ -255,7 +216,6 @@
 
     def specialize_call(self, hop):
         from rpython.annotator import model as annmodel
-        from rpython.rtyper.lltypesystem import lltype
         RESTYPE = hop.args_s[0].const
         if not isinstance(RESTYPE, lltype.LowLevelType):
             assert isinstance(RESTYPE, annmodel.SomeObject)
@@ -283,7 +243,8 @@
 
     def compute_result_annotation(self, s_arg, s_checker):
         if not s_checker.is_constant():
-            raise ValueError("Second argument of check_annotation must be constant")
+            raise ValueError(
+                "Second argument of check_annotation must be constant")
         checker = s_checker.const
         checker(s_arg, self.bookkeeper)
         return s_arg
@@ -308,11 +269,14 @@
         assert isinstance(s_arg, SomeList)
         # the logic behind it is that we try not to propagate
         # make_sure_not_resized, when list comprehension is not on
-        if self.bookkeeper.annotator.translator.config.translation.list_comprehension_operations:
+        config = self.bookkeeper.annotator.translator.config
+        if config.translation.list_comprehension_operations:
             s_arg.listdef.never_resize()
         else:
             from rpython.annotator.annrpython import log
-            log.WARNING('make_sure_not_resized called, but has no effect since list_comprehension is off')
+            log.WARNING(
+                "make_sure_not_resized called, but has no effect since "
+                "list_comprehension is off")
         return s_arg
 
     def specialize_call(self, hop):
@@ -434,9 +398,6 @@
 
 if not sys.platform.startswith('win'):
     def _make_impl_attach_gdb():
-        # circular imports fun :-(
-        import sys
-        from rpython.rtyper.lltypesystem import rffi
         if sys.platform.startswith('linux'):
             # Only necessary on Linux
             eci = ExternalCompilationInfo(includes=['string.h', 'assert.h',
@@ -482,7 +443,7 @@
                         os.strerror(e.errno)))
                     raise SystemExit
             else:
-                time.sleep(1) # give the GDB time to attach
+                time.sleep(1)  # give the GDB time to attach
 
         return impl_attach_gdb
 else:
diff --git a/rpython/rtyper/lltypesystem/rbuilder.py b/rpython/rtyper/lltypesystem/rbuilder.py
--- a/rpython/rtyper/lltypesystem/rbuilder.py
+++ b/rpython/rtyper/lltypesystem/rbuilder.py
@@ -1,7 +1,7 @@
 from rpython.rlib import rgc, jit
 from rpython.rlib.objectmodel import enforceargs
 from rpython.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rtyper.rptr import PtrRepr
 from rpython.rtyper.lltypesystem import lltype, rffi, rstr
@@ -11,7 +11,7 @@
 from rpython.rtyper.rbuilder import AbstractStringBuilderRepr
 from rpython.tool.sourcetools import func_with_new_name
 from rpython.rtyper.annlowlevel import llstr, llunicode
-        
+
 
 
 # ------------------------------------------------------------
diff --git a/rpython/rtyper/lltypesystem/rbytearray.py b/rpython/rtyper/lltypesystem/rbytearray.py
--- a/rpython/rtyper/lltypesystem/rbytearray.py
+++ b/rpython/rtyper/lltypesystem/rbytearray.py
@@ -1,7 +1,7 @@
 
 from rpython.rtyper.rbytearray import AbstractByteArrayRepr
 from rpython.rtyper.lltypesystem import lltype, rstr
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 
 BYTEARRAY = lltype.GcForwardReference()
 
diff --git a/rpython/rtyper/lltypesystem/rdict.py b/rpython/rtyper/lltypesystem/rdict.py
--- a/rpython/rtyper/lltypesystem/rdict.py
+++ b/rpython/rtyper/lltypesystem/rdict.py
@@ -4,7 +4,7 @@
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rlib import objectmodel, jit
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 from rpython.rlib.rarithmetic import r_uint, intmask, LONG_BIT
 from rpython.rtyper import rmodel
 from rpython.rtyper.error import TyperError
diff --git a/rpython/rtyper/lltypesystem/rlist.py b/rpython/rtyper/lltypesystem/rlist.py
--- a/rpython/rtyper/lltypesystem/rlist.py
+++ b/rpython/rtyper/lltypesystem/rlist.py
@@ -1,5 +1,5 @@
 from rpython.rlib import rgc, jit, types
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 from rpython.rlib.signature import signature
 from rpython.rtyper.error import TyperError
 from rpython.rtyper.lltypesystem import rstr
diff --git a/rpython/rtyper/lltypesystem/rordereddict.py b/rpython/rtyper/lltypesystem/rordereddict.py
--- a/rpython/rtyper/lltypesystem/rordereddict.py
+++ b/rpython/rtyper/lltypesystem/rordereddict.py
@@ -6,7 +6,7 @@
 from rpython.rlib import objectmodel, jit, rgc, types
 from rpython.rlib.signature import signature
 from rpython.rlib.objectmodel import specialize, likely
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 from rpython.rlib.rarithmetic import r_uint, intmask
 from rpython.rtyper import rmodel
 from rpython.rtyper.error import TyperError
diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -2,12 +2,12 @@
 
 from rpython.annotator import model as annmodel
 from rpython.rlib import jit, types
-from rpython.rlib.debug import ll_assert
 from rpython.rlib.objectmodel import (malloc_zero_filled, we_are_translated,
     _hash_string, keepalive_until_here, specialize, enforceargs)
 from rpython.rlib.signature import signature
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rtyper.error import TyperError
+from rpython.rtyper.debug import ll_assert
 from rpython.rtyper.lltypesystem import ll_str, llmemory
 from rpython.rtyper.lltypesystem.lltype import (GcStruct, Signed, Array, Char,
     UniChar, Ptr, malloc, Bool, Void, GcArray, nullptr, cast_primitive,
diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py
--- a/rpython/rtyper/rlist.py
+++ b/rpython/rtyper/rlist.py
@@ -1,7 +1,7 @@
 from rpython.annotator import model as annmodel
 from rpython.flowspace.model import Constant
 from rpython.rlib import rgc, jit, types
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 from rpython.rlib.objectmodel import malloc_zero_filled, enforceargs, specialize
 from rpython.rlib.signature import signature
 from rpython.rlib.rarithmetic import ovfcheck, widen, r_uint, intmask
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -7,7 +7,7 @@
 from rpython.annotator.classdesc import ClassDesc
 from rpython.flowspace.model import Constant
 from rpython.annotator.argument import simple_args
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rtyper import rclass, callparse
 from rpython.rtyper.rclass import CLASSTYPE, OBJECT_VTABLE, OBJECTPTR
diff --git a/rpython/rtyper/test/test_rlist.py b/rpython/rtyper/test/test_rlist.py
--- a/rpython/rtyper/test/test_rlist.py
+++ b/rpython/rtyper/test/test_rlist.py
@@ -3,7 +3,7 @@
 
 import py
 
-from rpython.rlib.debug import ll_assert
+from rpython.rtyper.debug import ll_assert
 from rpython.rtyper.error import TyperError
 from rpython.rtyper.llinterp import LLException, LLAssertFailure
 from rpython.rtyper.lltypesystem import rlist as ll_rlist


More information about the pypy-commit mailing list