Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r75613:3da78a2719fc
Date: 2015-01-31 17:57 +0100
http://bitbucket.org/pypy/pypy/changeset/3da78a2719fc/

Log:    Make 'added_blocks' a thread-local too

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -38,7 +38,6 @@
         self.translator = translator
         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
         self.notify = {}        # {block: {positions-to-reflow-from-when-done}}
         self.fixed_graphs = stmset()  # set of graphs not to annotate again
@@ -56,18 +55,6 @@
             bookkeeper = Bookkeeper(self)
         self.bookkeeper = bookkeeper
 
-    def __getstate__(self):
-        attrs = """translator pendingblocks annotated links_followed
-        notify bookkeeper frozen policy added_blocks""".split()
-        ret = self.__dict__.copy()
-        for key, value in ret.items():
-            if key not in attrs:
-                assert type(value) is dict, (
-                    "%r is not dict. please update %s.__getstate__" %
-                    (key, self.__class__.__name__))
-                ret[key] = {}
-        return ret
-
     #___ convenience high-level interface __________________
 
     def build_types(self, function, input_arg_types, complete_now=True,
@@ -124,16 +111,15 @@
         return graph
 
     def complete_helpers(self, policy):
-        saved = self.added_blocks
+        prevaddedblocks = self.bookkeeper.change_added_blocks({})
         prevpolicy = self.bookkeeper.change_policy(policy)
         try:
-            self.added_blocks = {}
             self.complete()
             # invoke annotation simplifications for the new blocks
-            self.simplify(block_subset=self.added_blocks)
+            self.simplify(block_subset=self.bookkeeper.get_added_blocks())
         finally:
             self.bookkeeper.change_policy(prevpolicy)
-            self.added_blocks = saved
+            self.bookkeeper.change_added_blocks(prevaddedblocks)
 
     def build_graph_types(self, flowgraph, inputcells, complete_now=True):
         checkgraph(flowgraph)
@@ -204,8 +190,9 @@
             if not self.pendingblocks:
                 break   # finished
         # make sure that the return variables of all graphs is annotated
-        if self.added_blocks is not None:
-            newgraphs = [self.annotated[block] for block in self.added_blocks]
+        added_blocks = self.bookkeeper.get_added_blocks()
+        if added_blocks is not None:
+            newgraphs = [self.annotated[block] for block in added_blocks]
             newgraphs = dict.fromkeys(newgraphs)
             got_blocked_blocks = False in newgraphs
         else:
@@ -357,8 +344,9 @@
         # The dict 'added_blocks' is used by rpython.annlowlevel to
         # detect which are the new blocks that annotating an additional
         # small helper creates.
-        if self.added_blocks is not None:
-            self.added_blocks[block] = True
+        added_blocks = self.bookkeeper.get_added_blocks()
+        if added_blocks is not None:
+            added_blocks[block] = True
 
     def reflowpendingblock(self, graph, block):
         assert not self.frozen
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -85,6 +85,14 @@
         self.bkTLS.policy = new_policy
         return old_policy
 
+    def get_added_blocks(self):
+        return getattr(self.bkTLS, 'added_blocks', None)
+
+    def change_added_blocks(self, new_added_blocks):
+        old_added_blocks = self.get_added_blocks()
+        self.bkTLS.added_blocks = new_added_blocks
+        return old_added_blocks
+
     @property
     def position_key(self):
         return self.bkTLS.position_key
@@ -107,7 +115,7 @@
         self.enter(None)
         try:
             def call_sites():
-                newblocks = self.annotator.added_blocks
+                newblocks = self.get_added_blocks()
                 if newblocks is None:
                     newblocks = self.annotator.annotated  # all of them
                 annotation = self.annotator.annotation
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to