[pypy-svn] r14781 - in pypy/dist/pypy: rpython translator translator/goal

pedronis at codespeak.net pedronis at codespeak.net
Tue Jul 19 18:29:55 CEST 2005


Author: pedronis
Date: Tue Jul 19 18:29:37 2005
New Revision: 14781

Modified:
   pypy/dist/pypy/rpython/callparse.py
   pypy/dist/pypy/rpython/rmodel.py
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/translator/goal/translate_pypy.py
   pypy/dist/pypy/translator/translator.py
Log:
- changes to support continuing rtyping even in the presence of errors
  (along the lines of this mail http://codespeak.net/pipermail/pypy-dev/2005q3/002210.html , Thanks to the poster)

- '-t-insist' option for translate_pypy to continue specializing even after errors



Modified: pypy/dist/pypy/rpython/callparse.py
==============================================================================
--- pypy/dist/pypy/rpython/callparse.py	(original)
+++ pypy/dist/pypy/rpython/callparse.py	Tue Jul 19 18:29:37 2005
@@ -2,8 +2,9 @@
 from pypy.interpreter.argument import Arguments, ArgErr
 from pypy.annotation import model as annmodel
 from pypy.rpython import rtuple
+from pypy.rpython.rmodel import TyperError
 
-class CallPatternTooComplex(Exception):
+class CallPatternTooComplex(TyperError):
     pass
 
 
@@ -47,7 +48,7 @@
     try:
         holders = arguments.match_signature(signature, defs_h)
     except ArgErr, e:
-        raise TypeError, "signature mismatch: %s" % e.getmsg(arguments, func.__name__)
+        raise TyperError, "signature mismatch: %s" % e.getmsg(arguments, func.__name__)
 
     assert len(holders) == len(rinputs), "argument parsing mismatch"
     vlist = []

Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py	(original)
+++ pypy/dist/pypy/rpython/rmodel.py	Tue Jul 19 18:29:37 2005
@@ -56,6 +56,12 @@
     def get_ll_eq_function(self): 
         raise TyperError, 'no equality function for %r' % self
 
+    def rtype_bltn_list(self, hop):
+        raise TyperError, 'no list() support for %r' % self
+
+    def rtype_unichr(self, hop):
+        raise TyperError, 'no unichr() support for %r' % self
+
     # default implementation of some operations
 
     def rtype_getattr(self, hop):
@@ -165,7 +171,9 @@
 for opname in annmodel.BINARY_OPERATIONS:
     setattr_default(pairtype(Repr, Repr),
                     'rtype_' + opname, missing_rtype_operation)
-
+# not in BINARY_OPERATIONS
+    setattr_default(pairtype(Repr, Repr),
+                    'rtype_contains', missing_rtype_operation)
 
 class __extend__(pairtype(Repr, Repr)):
     def convert_from_to((r_from, r_to), v, llops):

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Tue Jul 19 18:29:37 2005
@@ -264,7 +264,8 @@
             if curstr:
                 r.append(curstr)
             curstr = ''
-            assert f in 'xdsrf'
+            if f not in 'xdsrf':
+                raise TyperError("Unsupported formatting specifier: %r in %r" % (f, fmt))
 
             r.append((f,))
         else:
@@ -294,6 +295,8 @@
             code = thing[0]
             vitem, r_arg = argsiter.next()
             rep = inputconst(Void, r_arg)
+            if not hasattr(r_arg, 'll_str'):
+                raise TyperError("ll_str unsupported for: %r" % r_arg)
             if code == 's' or (code == 'r' and isinstance(r_arg, InstanceRepr)):
                 vchunk = hop.gendirectcall(r_arg.ll_str, vitem, rep)
             elif code == 'd':

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Tue Jul 19 18:29:37 2005
@@ -31,7 +31,7 @@
 
 log = py.log.Producer("rtyper")
 py.log.setconsumer("rtyper", None) 
-crash_on_first_typeerror = True
+
 
 class RPythonTyper:
 
@@ -44,7 +44,8 @@
         self.instance_reprs = {}
         self.pbc_reprs = {}
         self.class_pbc_attributes = {}
-        self.typererror = None
+        self.typererrors = []
+        self.typererror_count = 0
         # make the primitive_to_repr constant mapping
         self.primitive_to_repr = {}
         for s_primitive, lltype in annmodel.annotation_to_ll_map:
@@ -68,7 +69,7 @@
             print '*' * len(s)
             print s
             print '*' * len(s)
-
+        self.crash_on_first_typeerror = True
 
 
 
@@ -98,8 +99,9 @@
     def bindingrepr(self, var):
         return self.getrepr(self.binding(var))
 
-    def specialize(self, dont_simplify_again=False):
+    def specialize(self, dont_simplify_again=False, crash_on_first_typeerror = True):
         """Main entry point: specialize all annotated blocks of the program."""
+        self.crash_on_first_typeerror = crash_on_first_typeerror
         # specialize depends on annotator simplifications
         if not dont_simplify_again:
             self.annotator.simplify()
@@ -141,17 +143,29 @@
                 n = len(self.already_seen)
                 if n % 100 == 0:
                     total = len(self.annotator.annotated)
-                    print 'specializing: %d / %d blocks   (%d%%)' % (
-                        n, total, 100 * n // total)
+                    if self.typererror_count:
+                        error_report = " but %d errors" % self.typererror_count
+                    else:
+                        error_report = ''
+                    print 'specializing: %d / %d blocks   (%d%%)%s' % (
+                        n, total, 100 * n // total, error_report)
             # make sure all reprs so far have had their setup() called
             self.call_all_setups()
 
-        # re-raise the first TyperError caught
-        if self.typererror:
-            exc, value, tb = self.typererror
-            self.typererror = None
-            #self.annotator.translator.view()
-            raise exc, value, tb
+        if self.typererrors:
+            c = 1
+            for err in self.typererrors:
+                block, position = err.where
+                func = self.annotator.annotated.get(block, None)
+                if func:
+                    func = "(%s:%s)" %(func.__module__ or '?', func.__name__)
+                else:
+                    func = "(?:?)"
+                print "TyperError-%d: %s %r {%s}" % (c, func, block, position)
+                print str(err)
+                c += 1
+            raise TyperError("there were %d error" % len(self.typererrors))
+        
         # make sure that the return variables of all graphs are concretetype'd
         for graph in self.annotator.translator.flowgraphs.values():
             v = graph.getreturnvar()
@@ -203,7 +217,12 @@
 
     def specialize_block(self, block):
         # give the best possible types to the input args
-        self.setup_block_entry(block)
+        try:
+            self.setup_block_entry(block)
+        except TyperError, e:
+            self.gottypererror(e, block, "block-entry", None)
+            return  # cannot continue this block            
+            
 
         # specialize all the operations, as far as possible
         if block.operations == ():   # return or except block
@@ -272,6 +291,7 @@
                     new_a1 = newops.convertvar(a1, r_a1, r_a2)
                 except TyperError, e:
                     self.gottypererror(e, block, link, newops)
+                    continue # try other args
                 if new_a1 != a1:
                     newlinkargs[i] = new_a1
 
@@ -347,12 +367,13 @@
         Put a 'TyperError' operation in the graph instead.
         """
         e.where = (block, position)
-        if crash_on_first_typeerror:
+        self.typererror_count += 1
+        if self.crash_on_first_typeerror:
             raise
-        if self.typererror is None:
-            self.typererror = sys.exc_info()
-        c1 = inputconst(Void, Exception.__str__(e))
-        llops.genop('TYPER ERROR', [c1], resulttype=Void)
+        self.typererrors.append(e)
+        if llops:
+            c1 = inputconst(Void, Exception.__str__(e))
+            llops.genop('TYPER ERROR', [c1], resulttype=Void)
 
     # __________ regular operations __________
 

Modified: pypy/dist/pypy/translator/goal/translate_pypy.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate_pypy.py	(original)
+++ pypy/dist/pypy/translator/goal/translate_pypy.py	Tue Jul 19 18:29:37 2005
@@ -14,6 +14,7 @@
    -text      Don't start the Pygame viewer
    -no-a      Don't infer annotations, just translate everything
    -no-t      Don't type-specialize the graph operations with the C typer
+   -t-insist  Specialize should not stop at the first error
    -no-o      Don't do backend-oriented optimizations
    -no-c      Don't generate the C code
    -fork      (UNIX) Create a restartable checkpoint after annotation
@@ -112,7 +113,8 @@
         unixcheckpoint.restartable_point(auto='run')
     if a and not options['-no-t']:
         print 'Specializing...'
-        t.specialize(dont_simplify_again=True)
+        t.specialize(dont_simplify_again=True,
+                     crash_on_first_typeerror=not options['-t-insist'])
     if not options['-no-o']:
         print 'Back-end optimizations...'
         t.backend_optimizations()
@@ -257,6 +259,7 @@
                '-no-mark-some-objects': False,
                '-no-a': False,
                '-no-t': False,
+               '-t-insist': False,
                '-no-o': False,
                '-tcc':  False,
                '-d': False,

Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py	(original)
+++ pypy/dist/pypy/translator/translator.py	Tue Jul 19 18:29:37 2005
@@ -138,14 +138,14 @@
         for graph in self.flowgraphs.itervalues():
             checkgraph(graph)
 
-    def specialize(self, dont_simplify_again=False):
+    def specialize(self, **flags):
         if self.annotator is None:
             raise ValueError("you need to call annotate() first")
         if self.rtyper is not None:
             raise ValueError("cannot specialize() several times")
         from pypy.rpython.rtyper import RPythonTyper
         self.rtyper = RPythonTyper(self.annotator)
-        self.rtyper.specialize(dont_simplify_again=dont_simplify_again)
+        self.rtyper.specialize(**flags)
 
     def backend_optimizations(self):
         from pypy.translator.backendoptimization import backend_optimizations



More information about the Pypy-commit mailing list