[pypy-svn] r17832 - in pypy/dist/pypy: annotation rpython

arigo at codespeak.net arigo at codespeak.net
Sat Sep 24 17:57:01 CEST 2005


Author: arigo
Date: Sat Sep 24 17:56:57 2005
New Revision: 17832

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/rpython/lltype.py
Log:
* Minor optimizations.
* Safety-check that the annotator is not running on 'python -O'.


Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Sat Sep 24 17:56:57 2005
@@ -482,12 +482,20 @@
 
 def unionof(*somevalues):
     "The most precise SomeValue instance that contains all the values."
-    s1 = SomeImpossibleValue()
-    for s2 in somevalues:
+    try:
+        s1, s2 = somevalues
+    except ValueError:
+        s1 = SomeImpossibleValue()
+        for s2 in somevalues:
+            if s1 != s2:
+                s1 = pair(s1, s2).union()
+    else:
+        # this is just a performance shortcut
         if s1 != s2:
             s1 = pair(s1, s2).union()
-    if DEBUG and s1.caused_by_merge is None and len(somevalues) > 1:
-        s1.caused_by_merge = somevalues
+    if DEBUG:
+        if s1.caused_by_merge is None and len(somevalues) > 1:
+            s1.caused_by_merge = somevalues
     return s1
 
 def isdegenerated(s_value):
@@ -548,6 +556,17 @@
         return SomeImpossibleValue()
     setattr(cls, name, default_op)
 
+#
+# safety check that no-one is trying to make annotation and translation
+# faster by providing the -O option to Python.
+try:
+    assert False
+except AssertionError:
+    pass   # fine
+else:
+    raise RuntimeError("The annotator relies on 'assert' statements from the\n"
+                     "\tannotated program: you cannot run it with 'python -O'.")
+
 # this has the side-effect of registering the unary and binary operations
 from pypy.annotation.unaryop  import UNARY_OPERATIONS
 from pypy.annotation.binaryop import BINARY_OPERATIONS

Modified: pypy/dist/pypy/rpython/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltype.py	Sat Sep 24 17:56:57 2005
@@ -622,11 +622,12 @@
             if field_name in self._T._flds:
                 T1 = self._T._flds[field_name]
                 T2 = typeOf(val)
-                if T1 != T2:
+                if T1 == T2:
+                    setattr(self._obj, field_name, val)
+                else:
                     raise TypeError("%r instance field %r:\n"
                                     "expects %r\n"
                                     "    got %r" % (self._T, field_name, T1, T2))
-                setattr(self._obj, field_name, val)
                 return
         raise AttributeError("%r instance has no field %r" % (self._T,
                                                               field_name))



More information about the Pypy-commit mailing list