[pypy-svn] pypy default: be sure that we don't allow alpha-renaming for ConstClass(...) in match()
antocuni
commits-noreply at bitbucket.org
Wed Feb 23 23:36:41 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r42248:8b7fa8e31c35
Date: 2011-02-23 23:20 +0100
http://bitbucket.org/pypy/pypy/changeset/8b7fa8e31c35/
Log: be sure that we don't allow alpha-renaming for ConstClass(...) in
match()
diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py
--- a/pypy/module/pypyjit/test_pypy_c/model.py
+++ b/pypy/module/pypyjit/test_pypy_c/model.py
@@ -133,6 +133,13 @@
for op in self._ops_for_chunk(chunk, include_debug_merge_points):
yield op
+ def print_ops(self, id=None):
+ if id is None:
+ ops = self.allops()
+ else:
+ ops = self.ops_by_id(id)
+ print '\n'.join(map(str, ops))
+
def ops_by_id(self, id, include_debug_merge_points=False, opcode=None):
opcode_name = opcode
target_opcodes = self.ids[id]
@@ -186,13 +193,22 @@
src = src.replace('--TICK--', ticker_check)
return src
+ @classmethod
+ def _get_match_var(cls):
+ def is_const(v1):
+ return isinstance(v1, str) and v1.startswith('ConstClass(')
+ alpha_map = {}
+ def match_var(v1, v2):
+ if is_const(v1) or is_const(v2):
+ return v1 == v2
+ if v1 not in alpha_map:
+ alpha_map[v1] = v2
+ return alpha_map[v1] == v2
+ return match_var
+
def match_ops(self, ops, expected_src):
expected_src = self.preprocess_expected_src(expected_src)
- alpha_map = {}
- def match_var(v1, v2):
- if v1 not in alpha_map:
- alpha_map[v1] = v2
- assert alpha_map[v1] == v2, "variable mismatch"
+ match_var = self._get_match_var()
#
expected_ops = self.parse_ops(expected_src)
assert len(ops) == len(expected_ops), "wrong number of operations"
@@ -201,7 +217,7 @@
match_var(op.res, exp_res)
assert len(op.args) == len(exp_args), "wrong number of arguments"
for arg, exp_arg in zip(op.args, exp_args):
- match_var(arg, exp_arg)
+ assert match_var(arg, exp_arg), "variable mismatch"
return True
def match(self, expected_src):
diff --git a/pypy/module/pypyjit/test_pypy_c/test_model.py b/pypy/module/pypyjit/test_pypy_c/test_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_model.py
@@ -76,6 +76,22 @@
opcodes_names = [opcode.__class__.__name__ for opcode in myline]
assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 'STORE_FAST']
+ def test_match_var(self):
+ match_var = LoopWithIds._get_match_var()
+ assert match_var('v0', 'V0')
+ assert not match_var('v0', 'V1')
+ assert match_var('v0', 'V0')
+ #
+ # for ConstPtr, we allow the same alpha-renaming as for variables
+ assert match_var('ConstPtr(ptr0)', 'PTR0')
+ assert not match_var('ConstPtr(ptr0)', 'PTR1')
+ assert match_var('ConstPtr(ptr0)', 'PTR0')
+ #
+ # for ConstClass, we want the exact matching
+ assert match_var('ConstClass(foo)', 'ConstClass(foo)')
+ assert not match_var('ConstClass(bar)', 'v1')
+ assert not match_var('v2', 'ConstClass(baz)')
+
class TestRunPyPyC(BaseTestPyPyC):
def test_run_function(self):
@@ -249,3 +265,23 @@
i4 = int_sub_ovf(i3, 1)
guard_no_overflow()
""")
+
+ def test_match_constants(self):
+ def f():
+ i = 0L # force it to long, so that we get calls to rbigint
+ while i < 1003:
+ i += 1L # ID: increment
+ a = 0
+ return i
+ log = self.run(f)
+ loop, = log.loops_by_id('increment')
+ assert loop.match_by_id('increment', """
+ p12 = call(ConstClass(rbigint.add), p4, ConstPtr(ptr11))
+ guard_no_exception()
+ """)
+ #
+ py.test.raises(AssertionError, loop.match_by_id, 'increment', """
+ p12 = call(ConstClass(rbigint.SUB), p4, ConstPtr(ptr11))
+ guard_no_exception()
+ """)
+
More information about the Pypy-commit
mailing list