Author: Ronan Lamy <[email protected]>
Branch: py3.6
Changeset: r97102:4a80ca49fc90
Date: 2019-08-08 13:42 +0000
http://bitbucket.org/pypy/pypy/changeset/4a80ca49fc90/

Log:    Merged in __debug__-optimize (pull request #662)

        Fix handling of __debug__ and sys.flags.optimize

diff --git a/lib-python/3/opcode.py b/lib-python/3/opcode.py
--- a/lib-python/3/opcode.py
+++ b/lib-python/3/opcode.py
@@ -224,7 +224,6 @@
 hasname.append(201)
 def_op('CALL_METHOD', 202)            # #args not including 'self'
 def_op('BUILD_LIST_FROM_ARG', 203)
-jrel_op('JUMP_IF_NOT_DEBUG', 204)     # jump over assert statements
 def_op('LOAD_REVDB_VAR', 205)         # reverse debugger (syntax example: $5)
 
 del def_op, name_op, jrel_op, jabs_op
diff --git a/lib-python/3/test/test_dis.py b/lib-python/3/test/test_dis.py
--- a/lib-python/3/test/test_dis.py
+++ b/lib-python/3/test/test_dis.py
@@ -146,26 +146,24 @@
               1)
     pass
 
-# PyPy change: JUMP_IF_NOT_DEBUG
-dis_bug1333982 = """\
-%3d           0 JUMP_IF_NOT_DEBUG       26 (to 28)
-              2 LOAD_CONST               1 (0)
-              4 POP_JUMP_IF_TRUE        28
-              6 LOAD_GLOBAL              0 (AssertionError)
-              8 LOAD_CONST               2 (<code object <listcomp> at 0x..., 
file "%s", line %d>)
-             10 LOAD_CONST               3 ('bug1333982.<locals>.<listcomp>')
-             12 MAKE_FUNCTION            0
-             14 LOAD_FAST                0 (x)
-             16 GET_ITER
-             18 CALL_FUNCTION            1
+_bug1333982 = """\
+%3d           0 LOAD_CONST               1 (0)
+              2 POP_JUMP_IF_TRUE        26
+              4 LOAD_GLOBAL              0 (AssertionError)
+              6 LOAD_CONST               2 (<code object <listcomp> at 0x..., 
file "%s", line %d>)
+              8 LOAD_CONST               3 ('bug1333982.<locals>.<listcomp>')
+             10 MAKE_FUNCTION            0
+             12 LOAD_FAST                0 (x)
+             14 GET_ITER
+             16 CALL_FUNCTION            1
 
-%3d          20 LOAD_CONST               4 (1)
-             22 BINARY_ADD
-             24 CALL_FUNCTION            1
-             26 RAISE_VARARGS            1
+%3d          18 LOAD_CONST               4 (1)
+             20 BINARY_ADD
+             22 CALL_FUNCTION            1
+             24 RAISE_VARARGS            1
 
-%3d     >>   28 LOAD_CONST               0 (None)
-             30 RETURN_VALUE
+%3d     >>   26 LOAD_CONST               0 (None)
+             28 RETURN_VALUE
 """ % (bug1333982.__code__.co_firstlineno + 1,
        __file__,
        bug1333982.__code__.co_firstlineno + 1,
diff --git a/pypy/bin/pyinteractive.py b/pypy/bin/pyinteractive.py
--- a/pypy/bin/pyinteractive.py
+++ b/pypy/bin/pyinteractive.py
@@ -42,7 +42,7 @@
     StrOption("warn",
               "warning control (arg is action:message:category:module:lineno)",
               default=None, cmdline="-W"),
- 
+
     ])
 
 pypy_init = gateway.applevel('''
@@ -102,10 +102,9 @@
         space.appexec([], """():
             import sys
             flags = list(sys.flags)
-            flags[6] = 2
+            flags[3] = 2
             sys.flags = type(sys.flags)(flags)
-            import __pypy__
-            __pypy__.set_debug(False)
+            __builtins__.__dict__['__debug__'] = False
         """)
 
     # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and
@@ -119,7 +118,7 @@
     # set warning control options (if any)
     warn_arg = interactiveconfig.warn
     if warn_arg is not None:
-        space.appexec([space.wrap(warn_arg)], """(arg): 
+        space.appexec([space.wrap(warn_arg)], """(arg):
         import sys
         sys.warnoptions.append(arg)""")
 
@@ -202,6 +201,6 @@
 
 if __name__ == '__main__':
     if hasattr(sys, 'setrecursionlimit'):
-        # for running "python -i pyinteractive.py -Si -- py.py -Si" 
+        # for running "python -i pyinteractive.py -Si -- py.py -Si"
         sys.setrecursionlimit(3000)
     sys.exit(main_(sys.argv))
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -540,10 +540,6 @@
         sys.flags = type(sys.flags)(flags)
         sys.dont_write_bytecode = bool(sys.flags.dont_write_bytecode)
 
-        if sys.flags.optimize >= 1:
-            import __pypy__
-            __pypy__.set_debug(False)
-
     sys._xoptions = dict(x.split('=', 1) if '=' in x else (x, True)
                          for x in options['_xoptions'])
 
diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -723,7 +723,6 @@
     ops.JUMP_IF_FALSE_OR_POP: 0,
     ops.POP_JUMP_IF_TRUE: -1,
     ops.POP_JUMP_IF_FALSE: -1,
-    ops.JUMP_IF_NOT_DEBUG: 0,
 
     ops.SETUP_ANNOTATIONS: 0,
     ops.STORE_ANNOTATION: -1,
diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -507,9 +507,9 @@
     def visit_Assert(self, asrt):
         if self.compile_info.optimize >= 1:
             return
+        assert self.compile_info.optimize == 0
         self.update_position(asrt.lineno)
         end = self.new_block()
-        self.emit_jump(ops.JUMP_IF_NOT_DEBUG, end)
         asrt.test.accept_jump_if(self, True, end)
         self.emit_op_name(ops.LOAD_GLOBAL, self.names, "AssertionError")
         if asrt.msg:
@@ -542,7 +542,8 @@
     def visit_If(self, if_):
         self.update_position(if_.lineno, True)
         end = self.new_block()
-        test_constant = if_.test.as_constant_truth(self.space)
+        test_constant = if_.test.as_constant_truth(
+            self.space, self.compile_info)
         if test_constant == optimize.CONST_FALSE:
             self.visit_sequence(if_.orelse)
         elif test_constant == optimize.CONST_TRUE:
@@ -686,7 +687,7 @@
 
     def visit_While(self, wh):
         self.update_position(wh.lineno, True)
-        test_constant = wh.test.as_constant_truth(self.space)
+        test_constant = wh.test.as_constant_truth(self.space, 
self.compile_info)
         if test_constant == optimize.CONST_FALSE:
             self.visit_sequence(wh.orelse)
         else:
@@ -1207,7 +1208,7 @@
         count = len(elts) if elts is not None else 0
         consts_w = [None] * count
         for i in range(count):
-            w_value = elts[i].as_constant()
+            w_value = elts[i].as_constant(self.space, self.compile_info)
             if w_value is None:
                 # Not all constants
                 return None
@@ -1342,11 +1343,16 @@
             if len(d.keys) < 0xffff:
                 all_constant_keys_w = []
                 for key in d.keys:
-                    if key is None or key.as_constant() is None:
+                    if key is None:
+                        constant_key = None
+                    else:
+                        constant_key = key.as_constant(
+                            self.space, self.compile_info)
+                    if constant_key is None:
                         all_constant_keys_w = None
                         break
                     else:
-                        all_constant_keys_w.append(key.as_constant())
+                        all_constant_keys_w.append(constant_key)
             for i in range(len(d.values)):
                 key = d.keys[i]
                 is_unpacking = key is None
diff --git a/pypy/interpreter/astcompiler/optimize.py 
b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -20,14 +20,14 @@
 
 class __extend__(ast.AST):
 
-    def as_constant_truth(self, space):
+    def as_constant_truth(self, space, compile_info):
         """Return the truth of this node if known."""
-        const = self.as_constant()
+        const = self.as_constant(space, compile_info)
         if const is None:
             return CONST_NOT_CONST
         return int(space.is_true(const))
 
-    def as_constant(self):
+    def as_constant(self, space, compile_info):
         """Return the value of this node as a wrapped constant if possible."""
         return None
 
@@ -47,46 +47,52 @@
 
 class __extend__(ast.Num):
 
-    def as_constant(self):
+    def as_constant(self, space, compile_info):
         return self.n
 
 
 class __extend__(ast.Str):
 
-    def as_constant(self):
+    def as_constant(self, space, compile_info):
         return self.s
 
 
 class __extend__(ast.Bytes):
 
-    def as_constant(self):
+    def as_constant(self, space, compile_info):
         return self.s
 
 
 class __extend__(ast.Ellipsis):
-
-    def as_constant_truth(self, space):
-        return True
+    def as_constant(self, space, compile_info):
+        return space.w_Ellipsis
 
 
 class __extend__(ast.Constant):
 
-    def as_constant(self):
+    def as_constant(self, space, compile_info):
         return self.value
 
+class __extend__(ast.Name):
+    def as_constant(self, space, compile_info):
+        if self.id == '__debug__':
+            return space.newbool(compile_info.optimize == 0)
+        else:
+            return None
+
+
 class __extend__(ast.NameConstant):
-
-    def as_constant(self):
+    def as_constant(self, space, compile_info):
         return self.value
 
 class __extend__(ast.Index):
-    def as_constant(self):
-        return self.value.as_constant()
+    def as_constant(self, space, compile_info):
+        return self.value.as_constant(space, compile_info)
 
 class __extend__(ast.Slice):
-    def as_constant(self):
+    def as_constant(self, space, compile_info):
         # XXX: this ought to return a slice object if all the indices are
-        # constants, but we don't have a space here.
+        # constants
         return None
 
 class __extend__(ast.UnaryOp):
@@ -189,9 +195,9 @@
         return node
 
     def visit_BinOp(self, binop):
-        left = binop.left.as_constant()
+        left = binop.left.as_constant(self.space, self.compile_info)
         if left is not None:
-            right = binop.right.as_constant()
+            right = binop.right.as_constant(self.space, self.compile_info)
             if right is not None:
                 op = binop.op
                 try:
@@ -218,7 +224,7 @@
         return binop
 
     def visit_UnaryOp(self, unary):
-        w_operand = unary.operand.as_constant()
+        w_operand = unary.operand.as_constant(self.space, self.compile_info)
         op = unary.op
         if w_operand is not None:
             try:
@@ -254,7 +260,7 @@
         we_are_and = bop.op == ast.And
         i = 0
         while i < len(values) - 1:
-            truth = values[i].as_constant_truth(self.space)
+            truth = values[i].as_constant_truth(self.space, self.compile_info)
             if truth != CONST_NOT_CONST:
                 if (truth != CONST_TRUE) == we_are_and:
                     del values[i + 1:]
@@ -267,26 +273,14 @@
             return values[0]
         return bop
 
-    def visit_Repr(self, rep):
-        w_const = rep.value.as_constant()
-        if w_const is not None:
-            w_repr = self.space.repr(w_const)
-            return ast.Constant(w_repr, rep.lineno, rep.col_offset)
-        return rep
-
     def visit_Name(self, name):
         """Turn loading None, True, and False into a constant lookup."""
         if name.ctx == ast.Del:
             return name
         space = self.space
-        iden = name.id
         w_const = None
-        if iden == "None":
-            w_const = space.w_None
-        elif iden == "True":
-            w_const = space.w_True
-        elif iden == "False":
-            w_const = space.w_False
+        if name.id == '__debug__':
+            w_const = space.newbool(self.compile_info.optimize == 0)
         if w_const is not None:
             return ast.NameConstant(w_const, name.lineno, name.col_offset)
         return name
@@ -300,7 +294,7 @@
             consts_w = [None]*len(tup.elts)
             for i in range(len(tup.elts)):
                 node = tup.elts[i]
-                w_const = node.as_constant()
+                w_const = node.as_constant(self.space, self.compile_info)
                 if w_const is None:
                     new_elts = self._optimize_constant_star_unpacks(tup.elts)
                     if new_elts is not None:
@@ -350,7 +344,7 @@
                 after_last_star_index = i + 1
                 new_elts.append(elt)
             elif const_since_last_star_w is not None:
-                w_const = elt.as_constant()
+                w_const = elt.as_constant(self.space, self.compile_info)
                 if w_const is None:
                     new_elts.extend(elts[after_last_star_index:i + 1])
                     const_since_last_star_w = None
@@ -375,9 +369,9 @@
 
     def visit_Subscript(self, subs):
         if subs.ctx == ast.Load:
-            w_obj = subs.value.as_constant()
+            w_obj = subs.value.as_constant(self.space, self.compile_info)
             if w_obj is not None:
-                w_idx = subs.slice.as_constant()
+                w_idx = subs.slice.as_constant(self.space, self.compile_info)
                 if w_idx is not None:
                     try:
                         w_const = self.space.getitem(w_obj, w_idx)
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py 
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1041,20 +1041,6 @@
         code_w.exec_code(self.space, dict_w, dict_w)
         self.check(dict_w, expr, result)
 
-    def test_assert_skipping(self):
-        space = self.space
-        mod = space.getbuiltinmodule('__pypy__')
-        w_set_debug = space.getattr(mod, space.wrap('set_debug'))
-        space.call_function(w_set_debug, space.w_False)
-
-        source = """if 1:
-        assert False
-        """
-        try:
-            self.run(source)
-        finally:
-            space.call_function(w_set_debug, space.w_True)
-
     def test_dont_fold_equal_code_objects(self):
         yield self.st, "f=lambda:1;g=lambda:1.0;x=g()", 'type(x)', float
         yield (self.st, "x=(lambda: (-0.0, 0.0), lambda: (0.0, -0.0))[1]()",
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -39,7 +39,7 @@
 # time you make pyc files incompatible.  This value ends up in the frozen
 # importlib, via MAGIC_NUMBER in module/_frozen_importlib/__init__.
 
-pypy_incremental_magic = 176 # bump it by 16
+pypy_incremental_magic = 192 # bump it by 16
 assert pypy_incremental_magic % 16 == 0
 assert pypy_incremental_magic < 3000 # the magic number of Python 3. There are
                                      # no known magic numbers below this value
diff --git a/pypy/interpreter/pycompiler.py b/pypy/interpreter/pycompiler.py
--- a/pypy/interpreter/pycompiler.py
+++ b/pypy/interpreter/pycompiler.py
@@ -117,6 +117,8 @@
             check = True
         if not check:
             raise oefmt(self.space.w_TypeError, "invalid node type")
+        if optimize == -1:
+            optimize = self.space.sys.get_optimize()
 
         fut = misc.parse_future(node, self.future_flags.compiler_features)
         f_flags, f_lineno, f_col = fut
@@ -166,6 +168,9 @@
 
     def compile(self, source, filename, mode, flags, hidden_applevel=False,
             optimize=-1):
+        if optimize == -1:
+            optimize = self.space.sys.get_optimize()
+        assert optimize >= 0
         info = pyparse.CompileInfo(filename, mode, flags,
                 hidden_applevel=hidden_applevel, optimize=optimize)
         mod = self._compile_to_ast(source, info)
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -211,8 +211,6 @@
                 next_instr = self.JUMP_FORWARD(oparg, next_instr)
             elif opcode == opcodedesc.JUMP_IF_FALSE_OR_POP.index:
                 next_instr = self.JUMP_IF_FALSE_OR_POP(oparg, next_instr)
-            elif opcode == opcodedesc.JUMP_IF_NOT_DEBUG.index:
-                next_instr = self.JUMP_IF_NOT_DEBUG(oparg, next_instr)
             elif opcode == opcodedesc.JUMP_IF_TRUE_OR_POP.index:
                 next_instr = self.JUMP_IF_TRUE_OR_POP(oparg, next_instr)
             elif opcode == opcodedesc.POP_JUMP_IF_FALSE.index:
@@ -1180,11 +1178,6 @@
         self.popvalue()
         return next_instr
 
-    def JUMP_IF_NOT_DEBUG(self, jumpby, next_instr):
-        if not self.space.sys.debug:
-            next_instr += jumpby
-        return next_instr
-
     def GET_ITER(self, oparg, next_instr):
         w_iterable = self.popvalue()
         w_iterator = self.space.iter(w_iterable)
diff --git a/pypy/interpreter/pyparser/pyparse.py 
b/pypy/interpreter/pyparser/pyparse.py
--- a/pypy/interpreter/pyparser/pyparse.py
+++ b/pypy/interpreter/pyparser/pyparse.py
@@ -69,14 +69,14 @@
     * hidden_applevel: Will this code unit and sub units be hidden at the
       applevel?
     * optimize: optimization level:
-        -1 = same as interpreter,
          0 = no optmiziation,
          1 = remove asserts,
          2 = remove docstrings.
     """
 
     def __init__(self, filename, mode="exec", flags=0, future_pos=(0, 0),
-                 hidden_applevel=False, optimize=-1):
+                 hidden_applevel=False, optimize=0):
+        assert optimize >= 0
         rstring.check_str0(filename)
         self.filename = filename
         self.mode = mode
diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -13,7 +13,7 @@
 @unwrap_spec(filename='fsencode', mode='text', flags=int, dont_inherit=int,
              optimize=int)
 def compile(space, w_source, filename, mode, flags=0, dont_inherit=0,
-            optimize=0):
+            optimize=-1):
     """Compile the source string (a Python module, statement or expression)
 into a code object that can be executed by the exec statement or eval().
 The filename will be used for run-time error messages.
@@ -42,6 +42,10 @@
         raise oefmt(space.w_ValueError,
                     "compile() arg 3 must be 'exec', 'eval' or 'single'")
 
+    if optimize < -1 or optimize > 2:
+        raise oefmt(space.w_ValueError,
+            "compile(): invalid optimize value")
+
     if space.isinstance_w(w_source, space.gettypeobject(ast.W_AST.typedef)):
         if flags & consts.PyCF_ONLY_AST:
             return w_source
diff --git a/pypy/module/__builtin__/test/apptest_compile.py 
b/pypy/module/__builtin__/test/apptest_compile.py
--- a/pypy/module/__builtin__/test/apptest_compile.py
+++ b/pypy/module/__builtin__/test/apptest_compile.py
@@ -108,31 +108,32 @@
     try:
         assert False
     except AssertionError:
-        return (True, f.__doc__)
+        return (True, f.__doc__, __debug__)
     else:
-        return (False, f.__doc__)
+        return (False, f.__doc__, __debug__)
     '''
 
-    def f(): """doc"""
-    values = [(-1, __debug__, f.__doc__),
-                (0, True, 'doc'),
-                (1, False, 'doc'),
-                (2, False, None)]
+    def f():
+        """doc"""
 
-    for optval, debugval, docstring in values:
+    values = [(-1, __debug__, f.__doc__, __debug__),
+        (0, True, 'doc', True),
+        (1, False, 'doc', False),
+        (2, False, None, False)]
+
+    for optval, *expected in values:
         # test both direct compilation and compilation via AST
         codeobjs = []
-        codeobjs.append(
-                compile(codestr, "<test>", "exec", optimize=optval))
+        codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval))
         tree = ast.parse(codestr)
         codeobjs.append(compile(tree, "<test>", "exec", optimize=optval))
-
         for i, code in enumerate(codeobjs):
-            print(optval, debugval, docstring, i)
+            print(optval, *expected, i)
             ns = {}
             exec(code, ns)
             rv = ns['f']()
-            assert rv == (debugval, docstring)
+            print(rv)
+            assert rv == tuple(expected)
 
 def test_assert_remove():
     """Test removal of the asserts with optimize=1."""
diff --git a/pypy/module/__builtin__/test/test_compile.py 
b/pypy/module/__builtin__/test/test_compile.py
--- a/pypy/module/__builtin__/test/test_compile.py
+++ b/pypy/module/__builtin__/test/test_compile.py
@@ -3,12 +3,18 @@
 
     def setup_method(self, method):
         space = self.space
-        self._sys_debug = space.sys.debug
+        self._w_flags = space.sys.get('flags')
         # imitate -O
-        space.sys.debug = False
+        space.appexec([], """():
+            import sys
+            flags = list(sys.flags)
+            flags[3] = 1
+            sys.flags = type(sys.flags)(flags)
+            """)
 
     def teardown_method(self, method):
-        self.space.sys.debug = self._sys_debug
+        space = self.space
+        space.setitem(space.sys.w_dict, space.newtext('flags'), self._w_flags)
 
     def test_O_optmize_0(self):
         """Test that assert is not ignored if -O flag is set but optimize=0."""
@@ -30,9 +36,3 @@
         space.appexec([], """():
             exec(compile('assert False', '', 'exec', optimize=-1))
         """)
-
-
-# TODO: Check the value of __debug__ inside of the compiled block!
-#       According to the documentation, it should follow the optimize flag.
-#       However, cpython3.5.0a0 behaves the same way as PyPy (__debug__ follows
-#       -O, -OO flags of the interpreter).
diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -117,14 +117,6 @@
     """ Create a new empty list that has an underlying storage of length 
sizehint """
     return space.newlist_hint(sizehint)
 
-@unwrap_spec(debug=int)
-def set_debug(space, debug):
-    debug = bool(debug)
-    space.sys.debug = debug
-    space.setitem(space.builtin.w_dict,
-                  space.newtext('__debug__'),
-                  space.newbool(debug))
-
 @unwrap_spec(estimate=int)
 def add_memory_pressure(space, estimate):
     """ Add memory pressure of estimate bytes. Useful when calling a C function
diff --git a/pypy/module/__pypy__/moduledef.py 
b/pypy/module/__pypy__/moduledef.py
--- a/pypy/module/__pypy__/moduledef.py
+++ b/pypy/module/__pypy__/moduledef.py
@@ -72,7 +72,7 @@
     interpleveldefs = {
         'bufferable': 'interp_buffer.W_Bufferable',
     }
-        
+
 
 class Module(MixedModule):
     """ PyPy specific "magic" functions. A lot of them are experimental and
@@ -106,7 +106,6 @@
         'delitem_if_value_is'       : 'interp_dict.delitem_if_value_is',
         'move_to_end'               : 'interp_dict.move_to_end',
         'strategy'                  : 'interp_magic.strategy',  # dict,set,list
-        'set_debug'                 : 'interp_magic.set_debug',
         'locals_to_fast'            : 'interp_magic.locals_to_fast',
         'set_code_callback'         : 'interp_magic.set_code_callback',
         'decode_long'               : 'interp_magic.decode_long',
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -402,11 +402,7 @@
         raise oefmt(space.w_ImportError, "Bad magic number in %s", cpathname)
     #print "loading pyc file:", cpathname
     code_w = read_compiled_module(space, cpathname, source)
-    try:
-        optimize = space.sys.get_flag('optimize')
-    except RuntimeError:
-        # during bootstrapping
-        optimize = 0
+    optimize = space.sys.get_optimize()
     if optimize >= 2:
         code_w.remove_docstrings(space)
 
diff --git a/pypy/module/sys/moduledef.py b/pypy/module/sys/moduledef.py
--- a/pypy/module/sys/moduledef.py
+++ b/pypy/module/sys/moduledef.py
@@ -25,7 +25,6 @@
         self.recursionlimit = 1000
         self.defaultencoding = "utf-8"
         self.filesystemencoding = None
-        self.debug = True
         self.track_resources = False
         self.finalizing = False
         self.dlopenflags = rdynload._dlopen_default_mode()
@@ -239,3 +238,9 @@
     def get_state(self, space):
         from pypy.module.sys import state
         return state.get(space)
+
+    def get_optimize(self):
+        try:
+            return self.get_flag('optimize')
+        except RuntimeError:  # bootstrapping
+            return 0
diff --git a/pypy/tool/opcode3.py b/pypy/tool/opcode3.py
--- a/pypy/tool/opcode3.py
+++ b/pypy/tool/opcode3.py
@@ -224,6 +224,5 @@
 hasname.append(201)
 def_op('CALL_METHOD', 202)            # #args not including 'self'
 def_op('BUILD_LIST_FROM_ARG', 203)
-jrel_op('JUMP_IF_NOT_DEBUG', 204)     # jump over assert statements
 
 del def_op, name_op, jrel_op, jabs_op
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to