[pypy-svn] r11989 - in pypy/dist/pypy: objspace/flow translator
arigo at codespeak.net
arigo at codespeak.net
Thu May 5 23:52:10 CEST 2005
Author: arigo
Date: Thu May 5 23:52:09 2005
New Revision: 11989
Modified:
pypy/dist/pypy/objspace/flow/framestate.py
pypy/dist/pypy/objspace/flow/model.py
pypy/dist/pypy/translator/annrpython.py
pypy/dist/pypy/translator/gencl.py
pypy/dist/pypy/translator/genpyrex.py
Log:
Make sure that undefined local variables can never propagate in flow graphs.
Modified: pypy/dist/pypy/objspace/flow/framestate.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/framestate.py (original)
+++ pypy/dist/pypy/objspace/flow/framestate.py Thu May 5 23:52:09 2005
@@ -8,13 +8,8 @@
def __init__(self, state):
if isinstance(state, PyFrame):
- data = []
- for w in state.getfastscope():
- if w is None:
- data.append(Constant(undefined_value))
- else:
- data.append(w)
- data.extend(state.valuestack.items)
+ # getfastscope() can return real None, for undefined locals
+ data = state.getfastscope() + state.valuestack.items
if state.last_exception is None:
data.append(Constant(None))
data.append(Constant(None))
@@ -35,7 +30,7 @@
state.__class__.__name__)
self.next_instr = self.nonmergeable[1]
for w1 in self.mergeable:
- assert isinstance(w1, (Variable, Constant)), (
+ assert isinstance(w1, (Variable, Constant)) or w1 is None, (
'%r found in frame state' % w1)
def restoreframe(self, frame):
@@ -43,13 +38,7 @@
fastlocals = len(frame.fastlocals_w)
data = self.mergeable[:]
recursively_unflatten(frame.space, data)
- fastscope = []
- for w in data[:fastlocals]:
- if isinstance(w, Constant) and w.value is undefined_value:
- fastscope.append(None)
- else:
- fastscope.append(w)
- frame.setfastscope(fastscope)
+ frame.setfastscope(data[:fastlocals]) # Nones == undefined locals
frame.valuestack.items[:] = data[fastlocals:-2]
if data[-2] == Constant(None):
assert data[-1] == Constant(None)
@@ -121,6 +110,9 @@
def union(w1, w2):
"Union of two variables or constants."
+ if w1 is None or w2 is None:
+ return None # if w1 or w2 is an undefined local, we "kill" the value
+ # coming from the other path and return an undefined local
if isinstance(w1, Variable) or isinstance(w2, Variable):
return Variable() # new fresh Variable
if isinstance(w1, Constant) and isinstance(w2, Constant):
Modified: pypy/dist/pypy/objspace/flow/model.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/model.py (original)
+++ pypy/dist/pypy/objspace/flow/model.py Thu May 5 23:52:09 2005
@@ -218,7 +218,6 @@
return self.name
last_exception = Atom('last_exception')
last_exc_value = Atom('last_exc_value')
-undefined_value= Atom('*undefined*')
# if Block().exitswitch == Constant(last_exception), it means that we are
# interested in catching the exception that the *last operation* of the
# block could raise. The exitcases of the links are None for no exception
Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py (original)
+++ pypy/dist/pypy/translator/annrpython.py Thu May 5 23:52:09 2005
@@ -5,7 +5,7 @@
from pypy.annotation import model as annmodel
from pypy.annotation.model import pair
from pypy.annotation.bookkeeper import Bookkeeper
-from pypy.objspace.flow.model import Variable, Constant, undefined_value
+from pypy.objspace.flow.model import Variable, Constant
from pypy.objspace.flow.model import SpaceOperation, FunctionGraph
from pypy.objspace.flow.model import last_exception, last_exc_value
@@ -172,8 +172,8 @@
else:
raise
elif isinstance(arg, Constant):
- if arg.value is undefined_value: # undefined local variables
- return annmodel.SomeImpossibleValue()
+ #if arg.value is undefined_value: # undefined local variables
+ # return annmodel.SomeImpossibleValue()
assert not arg.value is last_exception and not arg.value is last_exc_value
return self.bookkeeper.immutablevalue(arg.value)
else:
Modified: pypy/dist/pypy/translator/gencl.py
==============================================================================
--- pypy/dist/pypy/translator/gencl.py (original)
+++ pypy/dist/pypy/translator/gencl.py Thu May 5 23:52:09 2005
@@ -306,7 +306,7 @@
target = link.target.inputargs
print "(psetq", # parallel assignment
for s, t in zip(source, target):
- if s != t and s != Constant(undefined_value):
+ if s != t: # and s != Constant(undefined_value):
print self.str(t), self.str(s),
print ")"
self.emit_jump(link.target)
Modified: pypy/dist/pypy/translator/genpyrex.py
==============================================================================
--- pypy/dist/pypy/translator/genpyrex.py (original)
+++ pypy/dist/pypy/translator/genpyrex.py Thu May 5 23:52:09 2005
@@ -4,7 +4,7 @@
"""
from pypy.interpreter.baseobjspace import ObjSpace
from pypy.interpreter.argument import Arguments
-from pypy.objspace.flow.model import Variable, Constant, undefined_value
+from pypy.objspace.flow.model import Variable, Constant
from pypy.objspace.flow.model import mkentrymap, last_exception
from pypy.translator.annrpython import RPythonAnnotator
from pypy.annotation.model import SomePBC
@@ -407,7 +407,7 @@
# get rid of identity-assignments and assignments of undefined_value
sargs, targs = [], []
for s,t in zip(sourceargs, targetargs):
- if s != t and s != Constant(undefined_value):
+ if s != t: # and s != Constant(undefined_value):
sargs.append(s)
targs.append(t)
if sargs:
More information about the Pypy-commit
mailing list