[pypy-svn] r24841 - in pypy/branch/explicit-exceptions/translator/backendopt: . test
mwh at codespeak.net
mwh at codespeak.net
Thu Mar 23 00:54:18 CET 2006
Author: mwh
Date: Thu Mar 23 00:54:16 2006
New Revision: 24841
Modified:
pypy/branch/explicit-exceptions/translator/backendopt/inline.py
pypy/branch/explicit-exceptions/translator/backendopt/test/test_inline.py
Log:
inline doesn't have to care about cleanups any more either.
Modified: pypy/branch/explicit-exceptions/translator/backendopt/inline.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/backendopt/inline.py (original)
+++ pypy/branch/explicit-exceptions/translator/backendopt/inline.py Thu Mar 23 00:54:16 2006
@@ -126,6 +126,7 @@
count = 0
non_recursive = {}
while self.block_to_index:
+ print '!!!', self.block_to_index
block, d = self.block_to_index.popitem()
index_operation, subgraph = d.popitem()
if d:
@@ -135,10 +136,6 @@
else:
non_recursive[subgraph] = True
operation = block.operations[index_operation]
- if getattr(operation, "cleanup", None) is not None:
- finallyops, exceptops = operation.cleanup
- if finallyops or exceptops:
- raise CannotInline("cannot inline a function with cleanup attached")
self.inline_once(block, index_operation)
count += 1
self.cleanup()
@@ -147,7 +144,6 @@
def inline_once(self, block, index_operation):
self.varmap = {}
self._copied_blocks = {}
- self._copied_cleanups = {}
self.op = block.operations[index_operation]
self.graph_to_inline = self.op.args[0].value._obj.graph
self.exception_guarded = False
@@ -203,26 +199,8 @@
def copy_operation(self, op):
args = [self.get_new_name(arg) for arg in op.args]
result = SpaceOperation(op.opname, args, self.get_new_name(op.result))
- if getattr(op, "cleanup", None) is not None:
- result.cleanup = self.copy_cleanup(op.cleanup)
return result
- def copy_cleanup(self, cleanup):
- if cleanup is None:
- return None
- if cleanup in self._copied_cleanups:
- return self._copied_cleanups[cleanup]
- finallyops, exceptops = cleanup
- copyfinallyops = []
- for op in finallyops:
- copyfinallyops.append(self.copy_operation(op))
- copyexceptops = []
- for op in exceptops:
- copyexceptops.append(self.copy_operation(op))
- copycleanup = (tuple(copyfinallyops), tuple(copyexceptops))
- self._copied_cleanups[cleanup] = copycleanup
- return copycleanup
-
def copy_block(self, block):
if block in self._copied_blocks:
return self._copied_blocks[block]
@@ -407,6 +385,7 @@
linktoinlined.target = copiedstartblock
linktoinlined.args = passon_args
afterblock.inputargs = [self.op.result] + afterblock.inputargs
+ print '@@@@', (block.operations, afterblock.operations)
afterblock.operations = self.generate_keepalive(afterblock.inputargs) + afterblock.operations[1:]
if self.graph_to_inline.returnblock in self.entrymap:
self.rewire_returnblock(afterblock)
Modified: pypy/branch/explicit-exceptions/translator/backendopt/test/test_inline.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/backendopt/test/test_inline.py (original)
+++ pypy/branch/explicit-exceptions/translator/backendopt/test/test_inline.py Thu Mar 23 00:54:16 2006
@@ -427,46 +427,3 @@
return 1
assert x4() == 1
py.test.raises(CannotInline, check_inline, x3, x4, [])
-
-def test_dont_inline_with_cleanups():
- from pypy.objspace.flow.model import Variable, SpaceOperation, Constant
- from pypy.rpython.lltypesystem.lltype import Signed
- import math
- def f(x):
- return math.sqrt(x)
- def g(x):
- return f(x)
- t = translate(g, [int])
- graph = graphof(t, f)
- ggraph = graphof(t, g)
- xvar = ggraph.startblock.inputargs[0]
- result = Variable()
- result.concretetype = Signed
- cleanupop = SpaceOperation("int_add", [Constant(1, Signed), xvar], result)
- cleanup = ((cleanupop, ), (cleanupop, ))
- ggraph.startblock.operations[0].cleanup = cleanup
- py.test.raises(CannotInline, inline_function, t, f, ggraph)
-
-def test_inline_copies_cleanups():
- from pypy.objspace.flow.model import Variable, SpaceOperation, Constant
- from pypy.rpython.lltypesystem.lltype import Signed
- import math
- def f(x):
- return math.sqrt(x)
- def g(x):
- return f(x)
- t = translate(g, [int])
- graph = graphof(t, f)
- ggraph = graphof(t, g)
- xvar = graph.startblock.inputargs[0]
- result = Variable()
- result.concretetype = Signed
- cleanupop = SpaceOperation("int_add", [Constant(1, Signed), xvar], result)
- cleanup = ((cleanupop, ), (cleanupop, ))
- graph.startblock.operations[0].cleanup = cleanup
- inline_function(t, f, ggraph)
- if option.view:
- t.view()
- assert hasattr(ggraph.startblock.operations[0], "cleanup")
-
-
More information about the Pypy-commit
mailing list