[pypy-commit] pypy default: test that we actually avoid to import the world when using the mock model with oparser, and fix the tests
antocuni
noreply at buildbot.pypy.org
Thu Jun 9 14:13:40 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r44869:f20d00165f88
Date: 2011-06-09 14:14 +0200
http://bitbucket.org/pypy/pypy/changeset/f20d00165f88/
Log: test that we actually avoid to import the world when using the mock
model with oparser, and fix the tests
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -1063,8 +1063,6 @@
Explodes if the annotator only thinks it is an instance of AbstractValue.
"""
if x is not None:
- if not we_are_translated() and getattr(x, 'I_am_a_descr', False):
- return # needed for the mock case in oparser_model
assert isinstance(x, AbstractDescr)
class Entry(ExtRegistryEntry):
diff --git a/pypy/jit/metainterp/resoperation.py b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -191,9 +191,15 @@
# of the operation. It must inherit from AbstractDescr. The
# backend provides it with cpu.fielddescrof(), cpu.arraydescrof(),
# cpu.calldescrof(), and cpu.typedescrof().
+ self._check_descr(descr)
+ self._descr = descr
+
+ def _check_descr(self, descr):
+ if not we_are_translated() and getattr(descr, 'I_am_a_descr', False):
+ return # needed for the mock case in oparser_model
from pypy.jit.metainterp.history import check_descr
check_descr(descr)
- self._descr = descr
+
class GuardResOp(ResOpWithDescr):
diff --git a/pypy/jit/tool/oparser.py b/pypy/jit/tool/oparser.py
--- a/pypy/jit/tool/oparser.py
+++ b/pypy/jit/tool/oparser.py
@@ -46,9 +46,8 @@
return FORCE_SPILL(self.OPNUM, self.getarglist()[:])
-def default_fail_descr(fail_args=None):
- from pypy.jit.metainterp.history import BasicFailDescr
- return BasicFailDescr()
+def default_fail_descr(model, fail_args=None):
+ return model.BasicFailDescr()
class OpParser(object):
@@ -237,14 +236,14 @@
"Unknown var in fail_args: %s" % arg)
fail_args.append(fail_arg)
if descr is None and self.invent_fail_descr:
- descr = self.invent_fail_descr(fail_args)
+ descr = self.invent_fail_descr(self.model, fail_args)
if hasattr(descr, '_oparser_uses_descr_of_guard'):
descr._oparser_uses_descr_of_guard(self, fail_args)
else:
fail_args = None
if opnum == rop.FINISH:
if descr is None and self.invent_fail_descr:
- descr = self.invent_fail_descr()
+ descr = self.invent_fail_descr(self.model)
elif opnum == rop.JUMP:
if descr is None and self.invent_fail_descr:
descr = self.looptoken
diff --git a/pypy/jit/tool/oparser_model.py b/pypy/jit/tool/oparser_model.py
--- a/pypy/jit/tool/oparser_model.py
+++ b/pypy/jit/tool/oparser_model.py
@@ -6,6 +6,7 @@
from pypy.jit.metainterp.history import TreeLoop, LoopToken
from pypy.jit.metainterp.history import Box, BoxInt, BoxFloat
from pypy.jit.metainterp.history import ConstInt, ConstObj, ConstPtr, ConstFloat
+ from pypy.jit.metainterp.history import BasicFailDescr
from pypy.jit.metainterp.typesystem import llhelper
from pypy.jit.metainterp.history import get_const_ptr_for_string
@@ -41,6 +42,9 @@
class LoopToken(object):
I_am_a_descr = True
+ class BasicFailDescr(object):
+ I_am_a_descr = True
+
class Box(object):
_counter = 0
type = 'b'
diff --git a/pypy/jit/tool/test/test_oparser.py b/pypy/jit/tool/test/test_oparser.py
--- a/pypy/jit/tool/test/test_oparser.py
+++ b/pypy/jit/tool/test/test_oparser.py
@@ -1,4 +1,5 @@
import py
+import sys
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.jit.tool.oparser import parse, OpParser
@@ -42,7 +43,7 @@
def test_descr(self):
class Xyz(AbstractDescr):
- pass
+ I_am_a_descr = True # for the mock case
x = """
[p0]
@@ -63,7 +64,7 @@
def test_descr_setfield(self):
class Xyz(AbstractDescr):
- pass
+ I_am_a_descr = True # for the mock case
x = """
[p0]
@@ -122,6 +123,7 @@
def test_jump_target_other(self):
looptoken = LoopToken()
+ looptoken.I_am_a_descr = True # for the mock case
x = '''
[]
jump(descr=looptoken)
@@ -242,8 +244,31 @@
assert isinstance(b.sum0, BoxInt)
+class ForbiddenModule(object):
+ def __init__(self, name, old_mod):
+ self.name = name
+ self.old_mod = old_mod
+
+ def __getattr__(self, attr):
+ assert False, "You should not import module %s" % self.name
+
class TestOpParserWithMock(BaseTestOparser):
class OpParser(OpParser):
use_mock_model = True
+
+ def setup_class(cls):
+ forbidden_mods = [
+ 'pypy.jit.metainterp.history',
+ 'pypy.rpython.lltypesystem.lltype',
+ ]
+ for modname in forbidden_mods:
+ if modname in sys.modules:
+ newmod = ForbiddenModule(modname, sys.modules[modname])
+ sys.modules[modname] = newmod
+
+ def teardown_class(cls):
+ for modname, mod in sys.modules.iteritems():
+ if isinstance(mod, ForbiddenModule):
+ sys.modules[modname] = mod.old_mod
More information about the pypy-commit
mailing list