[pypy-commit] pypy union-side-effects-2: Create union() as a side-effect-free binary function to replace unionof() wherever possible

rlamy pypy.commits at gmail.com
Sun Nov 13 09:56:50 EST 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: union-side-effects-2
Changeset: r88348:6639e3b4a1aa
Date: 2016-09-02 19:35 +0100
http://bitbucket.org/pypy/pypy/changeset/6639e3b4a1aa/

Log:	Create union() as a side-effect-free binary function to replace
	unionof() wherever possible

diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -94,16 +94,9 @@
         if self == other:
             return True
         try:
-            TLS.no_side_effects_in_union += 1
-        except AttributeError:
-            TLS.no_side_effects_in_union = 1
-        try:
-            try:
-                return pair(self, other).union() == self
-            except UnionError:
-                return False
-        finally:
-            TLS.no_side_effects_in_union -= 1
+            return union(self, other) == self
+        except UnionError:
+            return False
 
     def is_constant(self):
         d = self.__dict__
@@ -739,6 +732,23 @@
     def __repr__(self):
         return str(self)
 
+def union(s1, s2):
+    """The join operation in the lattice of annotations.
+
+    It is the most precise SomeObject instance that contains both arguments.
+
+    union() is (supposed to be) idempotent, commutative, associative and has
+    no side-effects.
+    """
+    try:
+        TLS.no_side_effects_in_union += 1
+    except AttributeError:
+        TLS.no_side_effects_in_union = 1
+    try:
+        return pair(s1, s2).union()
+    finally:
+        TLS.no_side_effects_in_union -= 1
+
 def unionof(*somevalues):
     "The most precise SomeValue instance that contains all the values."
     try:


More information about the pypy-commit mailing list