On Tuesday, March 29, 2016 21:11:09 cy via dmd-internals wrote: > Well, Module in dmodule.d has a list called "members" returned > from parsing the code, each item a symbol that's supposedly a > member of that module. But, the list also includes template > specializations and package names, which are apparantly never > searched for? > > In dmd, I made a bool[const(char)*] searched array in the Module > class, and added to that a symbol's "toChars" representation > every time it was searched for in that module. Then, in the third > pass (was that a mistake?) I compared every item in > Module.members to see if its toChars representation was in that > array. If not, it warns about an unused identifier. > > So, it searched for like 5 symbols, and there were 2000 symbols > give or take in the members array, resulting in a wall of text of > unused identifiers, that are actually used I'm sure, but I have > no idea how to determine that, if they're never looked up.
I don't know all that much about the compiler internals, so I don't know quite what you're looking at, but I would point out that any attempt to warn about "unused identifiers" would have to be done very carefully. Aside from the normal issues with RAII and the like where something is declared and then not used but still does something, it's _very_ common in D code to declare stuff and then not actually use it when dealing with template constraints and the traits tested in them, because it's testing for compilation, not actually running the code. And even if all of that is handled correctly, if the compiler is very aggressive about warning about unused identifers, templates and string mixins could run into trouble depending on the exact arguments used with them and how complicated some of their static if-else logic is. So, any attempt to warn about unused identifiers is going to have to be _very_ careful, or it's going to cause problems for perfectly legitimate code - especially if you consider that if -w is used, then warnings are treated as errors. And the fact that that affects conditional compilation makes it even worse. The compiler can't ever warn about any unused identifiers which should actually stay in the code, or it's going to be a big problem. - Jonathan M Davis _______________________________________________ dmd-internals mailing list [email protected] http://lists.puremagic.com/mailman/listinfo/dmd-internals
