Debian Codegraph @

rpython/rtyper/debug.py

raw symbols SCIP
1 from rpython.rlib.objectmodel import we_are_translated
2 from rpython.rtyper.extregistry import ExtRegistryEntry
3 from rpython.rtyper.lltypesystem import lltype
4
5 def ll_assert(x, msg):
6 """After translation to C, this becomes an RPyAssert."""
7 assert type(x) is bool, "bad type! got %r" % (type(x),)
8 assert x, msg
9
10 class Entry(ExtRegistryEntry):
11 _about_ = ll_assert
12
13 def compute_result_annotation(self, s_x, s_msg):
14 assert s_msg.is_constant(), ("ll_assert(x, msg): "
15 "the msg must be constant")
16 return None
17
18 def specialize_call(self, hop):
19 vlist = hop.inputargs(lltype.Bool, lltype.Void)
20 hop.exception_cannot_occur()
21 hop.genop('debug_assert', vlist)
22
23 def ll_assert_not_none(x):
24 """assert x is not None"""
25 assert x is not None, "ll_assert_not_none(%r)" % (x,)
26 return x
27
28 class Entry(ExtRegistryEntry):
29 _about_ = ll_assert_not_none
30
31 def compute_result_annotation(self, s_x):
32 return s_x.nonnoneify()
33
34 def specialize_call(self, hop):
35 from rpython.annotator import model as annmodel
36 from rpython.rtyper.error import TyperError
37 if annmodel.s_None.contains(hop.args_s[0]):
38 raise TyperError("ll_assert_not_none(None) detected. This might "
39 "come from something that annotates as "
40 "'raise None'.")
41 [v0] = hop.inputargs(hop.args_r[0])
42 hop.exception_cannot_occur()
43 hop.genop('debug_assert_not_none', [v0])
44 return v0
45
46 class FatalError(Exception):
47 pass
48
49 def fatalerror(msg):
50 # print the RPython traceback and abort with a fatal error
51 if not we_are_translated():
52 raise FatalError(msg)
53 from rpython.rtyper.lltypesystem import lltype
54 from rpython.rtyper.lltypesystem.lloperation import llop
55 llop.debug_print_traceback(lltype.Void)
56 llop.debug_fatalerror(lltype.Void, msg)
57 fatalerror._dont_inline_ = True
58 fatalerror._jit_look_inside_ = False
59 fatalerror._annenforceargs_ = [str]
60
61 def fatalerror_notb(msg):
62 # a variant of fatalerror() that doesn't print the RPython traceback
63 if not we_are_translated():
64 raise FatalError(msg)
65 from rpython.rtyper.lltypesystem import lltype
66 from rpython.rtyper.lltypesystem.lloperation import llop
67 llop.debug_fatalerror(lltype.Void, msg)
68 fatalerror_notb._dont_inline_ = True
69 fatalerror_notb._jit_look_inside_ = False
70 fatalerror_notb._annenforceargs_ = [str]
71
72 def debug_print_traceback():
73 # print to stderr the RPython traceback of the last caught exception,
74 # but without interrupting the program
75 from rpython.rtyper.lltypesystem import lltype
76 from rpython.rtyper.lltypesystem.lloperation import llop
77 llop.debug_print_traceback(lltype.Void)
78 debug_print_traceback._dont_inline_ = True
79 debug_print_traceback._jit_look_inside_ = False