Author: Armin Rigo <[email protected]>
Branch:
Changeset: r58491:28ae0f0e0b79
Date: 2012-10-27 10:54 +0200
http://bitbucket.org/pypy/pypy/changeset/28ae0f0e0b79/
Log: Don't write directly to "SomeBool().knowntypedata"; instead use a
setter. This lets us do more checking, and fixes a hard-to-
reproduce-in-a-small-test issue whereby sometimes an empty
knowntypedata attribute gets attached, confusing contains().
diff --git a/pypy/annotation/annrpython.py b/pypy/annotation/annrpython.py
--- a/pypy/annotation/annrpython.py
+++ b/pypy/annotation/annrpython.py
@@ -548,7 +548,7 @@
if cell.is_constant():
newcell.const = cell.const
cell = newcell
- cell.knowntypedata = renamed_knowntypedata
+ cell.set_knowntypedata(renamed_knowntypedata)
cells.append(cell)
diff --git a/pypy/annotation/binaryop.py b/pypy/annotation/binaryop.py
--- a/pypy/annotation/binaryop.py
+++ b/pypy/annotation/binaryop.py
@@ -144,7 +144,7 @@
# XXX HACK HACK HACK
bk = getbookkeeper()
if bk is not None: # for testing
- knowntypedata = r.knowntypedata = {}
+ knowntypedata = {}
fn, block, i = bk.position_key
annotator = bk.annotator
@@ -168,6 +168,7 @@
bind(obj2, obj1, 0)
bind(obj1, obj2, 1)
+ r.set_knowntypedata(knowntypedata)
return r
@@ -337,8 +338,7 @@
case = opname in ('gt', 'ge', 'eq')
add_knowntypedata(knowntypedata, case, [op.args[0]],
SomeInteger(nonneg=True,
knowntype=tointtype(int1)))
- if knowntypedata:
- r.knowntypedata = knowntypedata
+ r.set_knowntypedata(knowntypedata)
# a special case for 'x < 0' or 'x >= 0',
# where 0 is a flow graph Constant
# (in this case we are sure that it cannot become a r_uint later)
@@ -369,8 +369,7 @@
if hasattr(boo1, 'knowntypedata') and \
hasattr(boo2, 'knowntypedata'):
ktd = merge_knowntypedata(boo1.knowntypedata, boo2.knowntypedata)
- if ktd:
- s.knowntypedata = ktd
+ s.set_knowntypedata(ktd)
return s
def and_((boo1, boo2)):
diff --git a/pypy/annotation/builtin.py b/pypy/annotation/builtin.py
--- a/pypy/annotation/builtin.py
+++ b/pypy/annotation/builtin.py
@@ -188,10 +188,10 @@
variables = [op.args[1]]
for variable in variables:
assert bk.annotator.binding(variable) == s_obj
- r.knowntypedata = {}
-
+ knowntypedata = {}
if not hasattr(typ, '_freeze_') and isinstance(s_type, SomePBC):
- add_knowntypedata(r.knowntypedata, True, variables,
bk.valueoftype(typ))
+ add_knowntypedata(knowntypedata, True, variables,
bk.valueoftype(typ))
+ r.set_knowntypedata(knowntypedata)
return r
# note that this one either needs to be constant, or we will create SomeObject
diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -195,6 +195,10 @@
unsigned = False
def __init__(self):
pass
+ def set_knowntypedata(self, knowntypedata):
+ assert not hasattr(self, 'knowntypedata')
+ if knowntypedata:
+ self.knowntypedata = knowntypedata
class SomeStringOrUnicode(SomeObject):
immutable = True
diff --git a/pypy/annotation/unaryop.py b/pypy/annotation/unaryop.py
--- a/pypy/annotation/unaryop.py
+++ b/pypy/annotation/unaryop.py
@@ -76,7 +76,7 @@
s_obj.is_true_behavior(r)
bk = getbookkeeper()
- knowntypedata = r.knowntypedata = {}
+ knowntypedata = {}
fn, block, i = bk.position_key
op = block.operations[i]
assert op.opname == "is_true" or op.opname == "nonzero"
@@ -86,8 +86,8 @@
if s_obj.can_be_none():
s_nonnone_obj = s_obj.nonnoneify()
add_knowntypedata(knowntypedata, True, [arg], s_nonnone_obj)
+ r.set_knowntypedata(knowntypedata)
return r
-
def nonzero(obj):
return obj.is_true()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit