[pypy-svn] r78961 - in pypy/branch/rlist-jit/pypy: annotation annotation/test interpreter rlib rlib/rsre rlib/rsre/test rlib/test
arigo at codespeak.net
arigo at codespeak.net
Wed Nov 10 14:00:11 CET 2010
Author: arigo
Date: Wed Nov 10 14:00:10 2010
New Revision: 78961
Modified:
pypy/branch/rlist-jit/pypy/annotation/listdef.py
pypy/branch/rlist-jit/pypy/annotation/test/test_annrpython.py
pypy/branch/rlist-jit/pypy/interpreter/pycode.py
pypy/branch/rlist-jit/pypy/rlib/debug.py
pypy/branch/rlist-jit/pypy/rlib/rsre/rsre_core.py
pypy/branch/rlist-jit/pypy/rlib/rsre/test/test_zjit.py
pypy/branch/rlist-jit/pypy/rlib/test/test_debug.py
Log:
Rename make_sure_not_modified() to list_not_modified_any_more(),
who has only part of the effect: the *returned* list is flagged
as immutable, but the argument list's annotation is not changed.
Modified: pypy/branch/rlist-jit/pypy/annotation/listdef.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/annotation/listdef.py (original)
+++ pypy/branch/rlist-jit/pypy/annotation/listdef.py Wed Nov 10 14:00:10 2010
@@ -14,7 +14,7 @@
resized = False # True for lists resized after creation
range_step = None # the step -- only for lists only created by a range()
dont_change_any_more = False # set to True when too late for changes
- must_not_mutate = False # make_sure_not_modified()
+ must_not_mutate = False # list_not_modified_any_more()
must_not_resize = False # make_sure_not_resized()
# what to do if range_step is different in merge.
Modified: pypy/branch/rlist-jit/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/branch/rlist-jit/pypy/annotation/test/test_annrpython.py Wed Nov 10 14:00:10 2010
@@ -3357,11 +3357,29 @@
# not a constant: both __enter__ and __exit__ have been annotated
assert not s.is_constant()
- def test_make_sure_not_modified(self):
- from pypy.rlib.debug import make_sure_not_modified
+ def test_make_sure_not_resized(self):
+ from pypy.rlib.debug import make_sure_not_resized
def pycode(consts):
- make_sure_not_modified(consts)
+ make_sure_not_resized(consts)
+ def build1():
+ return pycode(consts=[1])
+ def build2():
+ return pycode(consts=[0])
+ def fn():
+ build1()
+ build2()
+
+ a = self.RPythonAnnotator()
+ a.translator.config.translation.list_comprehension_operations = True
+ a.build_types(fn, [])
+ # assert did not raise ListChangeUnallowed
+
+ def test_list_not_modified_any_more(self):
+ from pypy.rlib.debug import list_not_modified_any_more
+
+ def pycode(consts):
+ return list_not_modified_any_more(consts)
def build1():
return pycode(consts=[1])
def build2():
Modified: pypy/branch/rlist-jit/pypy/interpreter/pycode.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/interpreter/pycode.py (original)
+++ pypy/branch/rlist-jit/pypy/interpreter/pycode.py Wed Nov 10 14:00:10 2010
@@ -15,7 +15,7 @@
CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS, CO_NESTED,
CO_GENERATOR, CO_CONTAINSGLOBALS)
from pypy.rlib.rarithmetic import intmask
-from pypy.rlib.debug import make_sure_not_resized, make_sure_not_modified
+from pypy.rlib.debug import make_sure_not_resized, list_not_modified_any_more
from pypy.rlib import jit
from pypy.rlib.objectmodel import compute_hash
from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
@@ -69,7 +69,7 @@
self.co_stacksize = stacksize
self.co_flags = flags
self.co_code = code
- self.co_consts_w = make_sure_not_modified(consts)
+ self.co_consts_w = list_not_modified_any_more(consts)
self.co_names_w = [space.new_interned_str(aname) for aname in names]
self.co_varnames = varnames
self.co_freevars = freevars
Modified: pypy/branch/rlist-jit/pypy/rlib/debug.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/rlib/debug.py (original)
+++ pypy/branch/rlist-jit/pypy/rlib/debug.py Wed Nov 10 14:00:10 2010
@@ -226,14 +226,15 @@
hop.exception_cannot_occur()
return hop.inputarg(hop.args_r[0], arg=0)
-def make_sure_not_modified(arg):
- """ Function checking whether annotation of SomeList is never resized
- and never modified, useful for debugging. Does nothing when run directly
+def list_not_modified_any_more(arg):
+ """ Returns an annotator-time copy of the list 'arg' which is
+ flagged as 'don't mutate me'. Actually implemented as just
+ returning 'arg'. This is useful for debugging only.
"""
return arg
class Entry(ExtRegistryEntry):
- _about_ = make_sure_not_modified
+ _about_ = list_not_modified_any_more
def compute_result_annotation(self, s_arg):
from pypy.annotation.model import SomeList
@@ -241,10 +242,11 @@
# the logic behind it is that we try not to propagate
# make_sure_not_resized, when list comprehension is not on
if self.bookkeeper.annotator.translator.config.translation.list_comprehension_operations:
+ s_arg = s_arg.listdef.offspring()
s_arg.listdef.never_mutate()
else:
from pypy.annotation.annrpython import log
- log.WARNING('make_sure_not_modified called, but has no effect since list_comprehension is off')
+ log.WARNING('list_not_modified_any_more called, but has no effect since list_comprehension is off')
return s_arg
def specialize_call(self, hop):
Modified: pypy/branch/rlist-jit/pypy/rlib/rsre/rsre_core.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/rlib/rsre/rsre_core.py (original)
+++ pypy/branch/rlist-jit/pypy/rlib/rsre/rsre_core.py Wed Nov 10 14:00:10 2010
@@ -1,5 +1,5 @@
import sys
-from pypy.rlib.debug import check_nonneg, make_sure_not_modified
+from pypy.rlib.debug import check_nonneg, list_not_modified_any_more
from pypy.rlib.unroll import unrolling_iterable
from pypy.rlib.rsre import rsre_char
from pypy.tool.sourcetools import func_with_new_name
@@ -91,7 +91,7 @@
# and they must not be more than len(string).
check_nonneg(match_start)
check_nonneg(end)
- self.pattern = pattern
+ self.pattern = list_not_modified_any_more(pattern)
self.match_start = match_start
self.end = end
self.flags = flags
@@ -471,7 +471,6 @@
while True:
op = ctx.pat(ppos)
ppos += 1
- make_sure_not_modified(ctx.pattern)
#jit.jit_debug("sre_match", op, ppos, ptr)
#
Modified: pypy/branch/rlist-jit/pypy/rlib/rsre/test/test_zjit.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/rlib/rsre/test/test_zjit.py (original)
+++ pypy/branch/rlist-jit/pypy/rlib/rsre/test/test_zjit.py Wed Nov 10 14:00:10 2010
@@ -1,6 +1,5 @@
from pypy.jit.metainterp.test import test_basic
from pypy.rlib.nonconst import NonConstant
-from pypy.rlib.debug import make_sure_not_modified
from pypy.rlib.rsre.test.test_match import get_code
from pypy.rlib.rsre import rsre_core
from pypy.rpython.lltypesystem import lltype
Modified: pypy/branch/rlist-jit/pypy/rlib/test/test_debug.py
==============================================================================
--- pypy/branch/rlist-jit/pypy/rlib/test/test_debug.py (original)
+++ pypy/branch/rlist-jit/pypy/rlib/test/test_debug.py Wed Nov 10 14:00:10 2010
@@ -42,14 +42,14 @@
py.test.raises(IntegerCanBeNegative, interpret, g, [9])
def test_make_sure_not_resized():
- from pypy.annotation.listdef import TooLateForChange
+ from pypy.annotation.listdef import ListChangeUnallowed
def f():
result = [1,2,3]
make_sure_not_resized(result)
result.append(4)
return len(result)
- py.test.raises(TooLateForChange, interpret, f, [],
+ py.test.raises(ListChangeUnallowed, interpret, f, [],
list_comprehension_operations=True)
More information about the Pypy-commit
mailing list