Author: Armin Rigo <[email protected]>
Branch:
Changeset: r93085:d00a16ef468f
Date: 2017-11-19 23:04 +0100
http://bitbucket.org/pypy/pypy/changeset/d00a16ef468f/
Log: Follow-up for cb9634421fa2: revert the very general change and
instead improve the logic at the point where it matters, with a
comment.
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -15,34 +15,10 @@
typeof, s_ImpossibleValue, SomeInstance, intersection, difference)
from rpython.annotator.bookkeeper import Bookkeeper
from rpython.rtyper.normalizecalls import perform_normalizations
-from collections import deque
log = AnsiLogger("annrpython")
-class ShuffleDict(object):
- def __init__(self):
- self._d = {}
- self.keys = deque()
-
- def __setitem__(self, k, v):
- if k in self._d:
- self._d[k] = v
- else:
- self._d[k] = v
- self.keys.append(k)
-
- def __getitem__(self, k):
- return self._d[k]
-
- def popitem(self):
- key = self.keys.popleft()
- item = self._d.pop(key)
- return (key, item)
-
- def __nonzero__(self):
- return bool(self._d)
-
class RPythonAnnotator(object):
"""Block annotator for RPython.
See description in doc/translation.txt."""
@@ -57,7 +33,7 @@
translator = TranslationContext()
translator.annotator = self
self.translator = translator
- self.pendingblocks = ShuffleDict() # map {block: graph-containing-it}
+ self.pendingblocks = {} # map {block: graph-containing-it}
self.annotated = {} # set of blocks already seen
self.added_blocks = None # see processblock() below
self.links_followed = {} # set of links that have ever been followed
@@ -216,8 +192,15 @@
def complete_pending_blocks(self):
while self.pendingblocks:
- block, graph = self.pendingblocks.popitem()
- self.processblock(graph, block)
+ # Grab all blocks from 'self.pendingblocks' in a list, and
+ # walk that list. This prevents a situation where the same
+ # block is added over and over again to 'self.pendingblocks'
+ # and the code here would pop that same block from the dict
+ # over and over again, without ever looking at other blocks.
+ all_blocks = self.pendingblocks.keys()
+ for block in all_blocks:
+ graph = self.pendingblocks.pop(block)
+ self.processblock(graph, block)
def complete(self):
"""Process pending blocks until none is left."""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit