[Mesa-dev] [PATCH 1/6] nir/algebraic: Do better error reporting of bad expressions

Dylan Baker dylan at pnwbakers.com
Tue Apr 26 22:22:14 UTC 2016


Quoting Jason Ekstrand (2016-04-26 14:31:10)
> 
> 
> On Tue, Apr 26, 2016 at 12:47 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> 
>     Quoting Jason Ekstrand (2016-04-25 21:39:19)
>     > Previously, if an exception was encountered anywhere, nir_algebraic would
>     > just die in a fire with no indication whatsoever as to where the actual
>     bug
>     > is.  This commit makes it print out the particular search-and-replace
>     > expression that is causing problems along with the exception.  Also, it
>     > will now report all of the errors it finds and then exit at the end like
>     a
>     > standard C compiler would do.
>     >
>     > Cc: Dylan Baker <baker.dylan.c at gmail.com>
>     > ---
>     >  src/compiler/nir/nir_algebraic.py | 17 ++++++++++++++++-
>     >  1 file changed, 16 insertions(+), 1 deletion(-)
>     >
>     > diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/
>     nir_algebraic.py
>     > index 7697171..3f770b6 100644
>     > --- a/src/compiler/nir/nir_algebraic.py
>     > +++ b/src/compiler/nir/nir_algebraic.py
>     > @@ -24,11 +24,13 @@
>     >  # Authors:
>     >  #    Jason Ekstrand (jason at jlekstrand.net)
>     >
>     > +from __future__ import print_function
>     >  import itertools
>     >  import struct
>     >  import sys
>     >  import mako.template
>     >  import re
>     > +import traceback
>     >
>     >  # Represents a set of variables, each with a unique id
>     >  class VarSet(object):
>     > @@ -311,15 +313,28 @@ class AlgebraicPass(object):
>     >        self.xform_dict = {}
>     >        self.pass_name = pass_name
>     >
>     > +      error = False
>     > +
>     >        for xform in transforms:
>     >           if not isinstance(xform, SearchAndReplace):
>     > -            xform = SearchAndReplace(xform)
>     > +            try:
>     > +               xform = SearchAndReplace(xform)
>     > +            except:
>     > +               print("Failed to parse transformation:", file=sys.stderr)
>     > +               print("  " + str(xform), file=sys.stderr)
>     > +               traceback.print_exc(file=sys.stderr)
>     > +               print('', file=sys.stderr)
>     > +               error = True
>     > +               continue
>     >
>     >           if xform.search.opcode not in self.xform_dict:
>     >              self.xform_dict[xform.search.opcode] = []
>     >
>     >           self.xform_dict[xform.search.opcode].append(xform)
>     >
>     > +      if error:
>     > +         raise RuntimeError("Error parsing transformations")
>     > +
> 
>     I'm going to admit that I have a bias against using RuntimeError, but I
>     think in the vein you're going for just calling "sys.exit(1)" here would
>     be better, since you won't get a meaningless stack trace.
> 
> 
> I'd rather use sys.exit(1) anyway.  I just thought that might be "improper" in
> python.  Changed locally.

Nah, in this case I think it's the right thing to do. It's an odd
handler, but it is an error handler, so I think just exiting is better.

>  
> 
>     >     def render(self):
>     >        return _algebraic_pass_template.render(pass_name=self.pass_name,
>     >                                               xform_dict=self.xform_dict,
>     > --
>     > 2.5.0.400.gff86faf
>     >
>     Even with the one nit, either way:
>     Reviewed-by: Dylan Baker <dylan at pnwbakers.com>
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160426/9290f992/attachment.sig>


More information about the mesa-dev mailing list