Discussion:
[Swig-devel] Warn about unused ignore/renames?
Vadim Zeitlin
2016-07-31 10:00:23 UTC
Permalink
Hi,

I have to admit that even after years of working with SWIG I still often
make mistakes when writing %rename or %ignore directives. Sometimes it's as
stupid as putting them after the declaration of the symbol being renamed,
and sometimes it's more subtle, see https://github.com/swig/swig/issues/757
but in any case it takes me longer than it should to find and fix the
problem and this is mostly due to the fact that it takes time to even
realize that the directive wasn't taken into account in the first place.

I really wish SWIG could help me here, so I wonder if it could be a good
idea to add a warning, which would be given at the end of processing, if a
rename/ignore has never been used? It seems to me that there is no real
reason to have such directives not matching anything, so I believe such
warning would be useful as it would point out unintentional behaviour.

And we would provide some "allow_unused" attribute which could be set to
indicate that some particular directive can really be unused, this would be
useful for at least the directives in the SWIG library files which define
%renames for all the operators in Python case, for example, even if,
clearly, not all operators are going to be used in all modules.

What do you think?
VZ
William S Fulton
2016-09-17 09:00:44 UTC
Permalink
Post by Vadim Zeitlin
Hi,
I have to admit that even after years of working with SWIG I still often
make mistakes when writing %rename or %ignore directives. Sometimes it's as
stupid as putting them after the declaration of the symbol being renamed,
and sometimes it's more subtle, see https://github.com/swig/swig/issues/757
but in any case it takes me longer than it should to find and fix the
problem and this is mostly due to the fact that it takes time to even
realize that the directive wasn't taken into account in the first place.
I really wish SWIG could help me here, so I wonder if it could be a good
idea to add a warning, which would be given at the end of processing, if a
rename/ignore has never been used? It seems to me that there is no real
reason to have such directives not matching anything, so I believe such
warning would be useful as it would point out unintentional behaviour.
And we would provide some "allow_unused" attribute which could be set to
indicate that some particular directive can really be unused, this would be
useful for at least the directives in the SWIG library files which define
%renames for all the operators in Python case, for example, even if,
clearly, not all operators are going to be used in all modules.
I think some analysis/report of the interface files with optional
warnings would be useful. I fear that the additional warnings will
produce more noise than useful information though. There are for
example loads of %renames in the SWIG library that will not always be
used, for example all the keyword renaming. There are also %renames
which use patterns, so the rename won't necessarily be used just once.
Given this I think the resulting report will be quite verbose and will
need a few options to control what should go into it, or it will be a
complex report requiring tools to analyse the output (like the typemap
debugging options require). It would be interesting to see what the
test-suite throws up if it gets implemented.

There are other areas though that would be nice to have as a
post-analysis, but equally complex to get right. Things like feature
usage and possibly improved typemap usage analysis (from the
-debug-tm* flags). The most important one I feel though is optionally
making SWIG act more like a C/C++ compiler with respect to type
declaration and usage. A lot incorrect interface file problems could
be solved more easily if SWIG had an option to error if it did not
have full type information in the same way that a C/C++ compiler does.
While one of SWIG's design goals is to work with missing type
information, this goal can sometimes slow down development on
interface files due to basic missing type information mistakes. For
well maintained/designed interface files, getting SWIG to warn about
missing type information will be very useful and then a user can turn
warnings into errors with -Werror if desired.

William

------------------------------------------------------------------------------
Loading...