[pypy-svn] r51205 - in pypy/dist/pypy: annotation tool/algo tool/algo/test
xoraxax at codespeak.net
xoraxax at codespeak.net
Sat Feb 2 13:16:33 CET 2008
Author: xoraxax
Date: Sat Feb 2 13:16:31 2008
New Revision: 51205
Added:
pypy/dist/pypy/tool/algo/test/test_unionfind.py
Modified:
pypy/dist/pypy/annotation/specialize.py
pypy/dist/pypy/tool/algo/unionfind.py
Log:
Fix the mysterious RTyper warnings. Before, the memo code was registering a callback on the finish method
of every ever created MemoTable instance. But the union find code was merging these tables together.
Now the callback is ignored if it is called for a dominated MemoTable, i.e. one that was merged into another
one.
The accompanied unittest tests the new behaviour of the unionfind code, I do not know how to test the real
issue reproducibly.
The result of this checkin is that translation runs show only a single RTyper warning of this kind:
[rtyper:WARNING] Desc <FrozenDesc for <StdTypeDef name='basestring'>> has no attribute '$memofield_getorbuild_0'
Modified: pypy/dist/pypy/annotation/specialize.py
==============================================================================
--- pypy/dist/pypy/annotation/specialize.py (original)
+++ pypy/dist/pypy/annotation/specialize.py Sat Feb 2 13:16:31 2008
@@ -96,11 +96,19 @@
self.funcdesc = funcdesc
self.table = {args: value}
self.graph = None
+ self.do_not_process = False
+
+ def register_finish(self):
+ bookkeeper = self.funcdesc.bookkeeper
+ bookkeeper.pending_specializations.append(self.finish)
def update(self, other):
self.table.update(other.table)
self.graph = None # just in case
+ def cleanup(self):
+ self.do_not_process = True
+
fieldnamecounter = 0
def getuniquefieldname(self):
@@ -110,6 +118,8 @@
return fieldname
def finish(self):
+ if self.do_not_process:
+ return
from pypy.annotation.model import unionof
assert self.graph is None, "MemoTable already finished"
# list of which argument positions can take more than one value
@@ -273,7 +283,7 @@
def compute_one_result(args):
value = func(*args)
memotable = MemoTable(funcdesc, args, value)
- bookkeeper.pending_specializations.append(memotable.finish)
+ memotable.register_finish()
return memotable
memotables = UnionFind(compute_one_result)
Added: pypy/dist/pypy/tool/algo/test/test_unionfind.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/algo/test/test_unionfind.py Sat Feb 2 13:16:31 2008
@@ -0,0 +1,26 @@
+from pypy.tool.algo.unionfind import UnionFind
+
+
+def test_cleanup():
+ state = []
+ class ReferencedByExternalState(object):
+ def __init__(self, obj):
+ state.append(self)
+ self.obj = obj
+
+ def update(self, other):
+ pass
+
+ def cleanup(self):
+ state.remove(self)
+
+ uf = UnionFind(ReferencedByExternalState)
+ uf.find(1)
+ for i in xrange(1, 10, 2):
+ uf.union(i, 1)
+ uf.find(2)
+ for i in xrange(2, 20, 2):
+ uf.union(i, 2)
+ assert len(state) < 3
+
+
Modified: pypy/dist/pypy/tool/algo/unionfind.py
==============================================================================
--- pypy/dist/pypy/tool/algo/unionfind.py (original)
+++ pypy/dist/pypy/tool/algo/unionfind.py Sat Feb 2 13:16:31 2008
@@ -87,6 +87,8 @@
self.link_to_parent[rep2] = rep1
del self.weight[rep2]
+ if hasattr(info2, "cleanup"):
+ info2.cleanup()
del self.root_info[rep2]
self.weight[rep1] = w
More information about the Pypy-commit
mailing list