[pypy-commit] pypy default: Implement skipping asserts when -O option is set
waedt
noreply at buildbot.pypy.org
Tue Jun 4 11:58:32 CEST 2013
Author: Tyler Wade <wayedt at gmail.com>
Branch:
Changeset: r64750:5e679b2d667e
Date: 2013-04-28 04:23 -0500
http://bitbucket.org/pypy/pypy/changeset/5e679b2d667e/
Log: Implement skipping asserts when -O option is set
diff --git a/lib-python/2.7/opcode.py b/lib-python/2.7/opcode.py
--- a/lib-python/2.7/opcode.py
+++ b/lib-python/2.7/opcode.py
@@ -193,5 +193,6 @@
hasname.append(201)
def_op('CALL_METHOD', 202) # #args not including 'self'
def_op('BUILD_LIST_FROM_ARG', 203)
+jabs_op('JUMP_IF_NOT_DEBUG', 204) # Target address
del def_op, name_op, jrel_op, jabs_op
diff --git a/pypy/bin/pyinteractive.py b/pypy/bin/pyinteractive.py
--- a/pypy/bin/pyinteractive.py
+++ b/pypy/bin/pyinteractive.py
@@ -27,7 +27,7 @@
BoolOption("completer", "use readline commandline completer",
default=False, cmdline="-C"),
BoolOption("optimize",
- "remove docstrings when importing modules (like CPython -OO)",
+ "skip assert statements and remove docstrings when importing modules",
default=False, cmdline="-O"),
BoolOption("no_site_import", "do not 'import site' on initialization",
default=False, cmdline="-S"),
@@ -91,12 +91,13 @@
space = option.make_objspace(config)
if interactiveconfig.optimize:
- flags = space.sys.get('flags').getitems_copy()
+ flags_w = space.sys.get('flags').getitems_copy()
#change optimize flag's value
- flags[6] = space.wrap(2)
- flags = type(space.sys.get('flags'))(flags)
- flags.user_setup(space, space.sys.get('flags').w__class__)
- space.sys.w_dict.setitem(space.wrap('flags'), flags)
+ import pdb; pdb.set_trace()
+ flags_w[6] = space.wrap(2)
+ w_flags = type(space.sys.get('flags'))(flags_w)
+ w_flags.user_setup(space, space.sys.get('flags').w__class__)
+ space.sys.w_dict.setitem(space.wrap('flags'), w_flags)
space._starttime = starttime
space.setitem(space.sys.w_dict, space.wrap('executable'),
diff --git a/pypy/doc/man/pypy.1.rst b/pypy/doc/man/pypy.1.rst
--- a/pypy/doc/man/pypy.1.rst
+++ b/pypy/doc/man/pypy.1.rst
@@ -16,10 +16,10 @@
Inspect interactively after running script.
-O
- Dummy optimization flag for compatibility with C Python.
+ Skip assert statements.
-OO
- Remove docstrings when importing modules (like CPython -OO).
+ Remove docstrings when importing modules in addition to -O.
-c *cmd*
Program passed in as CMD (terminates option list).
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
@@ -4,8 +4,8 @@
"""
options:
-i inspect interactively after running script
- -O dummy optimization flag for compatibility with C Python
- -OO remove docstrings when importing modules (like CPython -OO)
+ -O skip assert statements
+ -OO remove docstrings when importing modules in addition to -O
-c cmd program passed in as CMD (terminates option list)
-S do not 'import site' on initialization
-u unbuffered binary stdout and stderr
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
@@ -634,6 +634,7 @@
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.BUILD_LIST_FROM_ARG: 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
@@ -373,6 +373,7 @@
def visit_Assert(self, asrt):
self.update_position(asrt.lineno)
end = self.new_block()
+ self.emit_jump(ops.JUMP_IF_NOT_DEBUG, end, True)
asrt.test.accept_jump_if(self, True, end)
self.emit_op_name(ops.LOAD_GLOBAL, self.names, "AssertionError")
if asrt.msg:
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
@@ -844,6 +844,23 @@
yield self.check, dict_w, "C4.__doc__", 'docstring'
yield self.check, dict_w, "__doc__", None
+ def test_assert_skipping(self):
+ space = self.space
+ source = """if 1:
+ assert False
+ """
+ w_saved_flags = space.sys.get('flags')
+ flags_w = space.sys.get('flags').getitems_copy()
+ flags_w[6] = space.wrap(1)
+ w_flags = type(space.sys.get('flags'))(flags_w)
+ w_flags.user_setup(space, w_saved_flags.w__class__)
+ space.sys.w_dict.setitem(space.wrap('flags'), w_flags)
+ try:
+ self.run(source)
+ finally:
+ space.sys.w_dict.setitem(space.wrap('flags'), w_saved_flags)
+
+
class AppTestCompiler:
def test_docstring_not_loaded(self):
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -876,6 +876,15 @@
self.popvalue()
return next_instr
+ def JUMP_IF_NOT_DEBUG(self, target, next_instr):
+ try:
+ optimize = self.space.sys.get_flag('optimize')
+ except:
+ optimize = 0
+ if optimize >= 1:
+ return target
+ return next_instr
+
def GET_ITER(self, oparg, next_instr):
w_iterable = self.popvalue()
w_iterator = self.space.iter(w_iterable)
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -800,6 +800,9 @@
self.popvalue()
return next_instr
+ def JUMP_IF_NOT_DEBUG(self, target, next_instr):
+ return next_instr
+
def GET_ITER(self, oparg, next_instr):
w_iterable = self.popvalue()
w_iterator = self.space.iter(w_iterable)
More information about the pypy-commit
mailing list