Hi,

I suppose that the explanation that you put in the commit message should also go in a comment inside the source code, else when someone sees it it's just obscure.
Also, it'd be nice to have some tests about ShuffleDict :)

On Thu, Nov 9, 2017 at 2:55 AM, fijal <pypy.commits@gmail.com> wrote:
Author: fijal
Branch:
Changeset: r92981:cb9634421fa2
Date: 2017-11-08 17:54 -0800
http://bitbucket.org/pypy/pypy/changeset/cb9634421fa2/

Log:    "eh". On pypy we need to be careful in which order we have
        pendingblocks. Otherwise we end up in a setup where we have blocks
        a, b and c where a and b are blocked because c needs to add an
        attribute, but c is never appended since popitem() would always
        return an a or b. I wonder if the same condition can be repeated on
        CPython, but I cannot. Unclear how would you write a test for it
        since it depends on dictionary order.

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -15,10 +15,34 @@
     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."""
@@ -33,7 +57,7 @@
             translator = TranslationContext()
             translator.annotator = self
         self.translator = translator
-        self.pendingblocks = {}  # map {block: graph-containing-it}
+        self.pendingblocks = ShuffleDict()  # 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
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit