Hi Ludovic, This isn't a review really, because I changed the code in question... I hope you find the new analyze-lexicals procedure easier to understand. It's certainly better documented :)
On Thu 02 Jul 2009 19:35, l...@gnu.org (Ludovic Courtès) writes: > l...@gnu.org (Ludovic Courtès) writes: > >> The attached patch is an attempt to add unused variable reporting to the >> compiler, at the GLIL->assembly step. It was quite simple to implement >> here, and it should work with all front-ends (Scheme, ECMAScript, etc.), >> which is nice. > > Following Andy's suggestion on IRC, I tried to integrate this feature in > the `analyze-lexicals' procedure of Tree-IL, this time (and with an > imperative style not quite to my taste.) We could do this with multiple values, but we'd need decent functional map data structures. However the new algorithm is more functional than the last. > Unfortunately, source location information appears to be unavailable (or > just difficult to obtain?) at this level for code generated by macros > such as `record-case'. Well, I probably just need some guidance. ;-) You won't get source location information out of defmacros. OK, here's another idea. Why don't we keep this as a separate pass -- enabled if you pass a compilation option. That way it can be more functional, and you can keep approximate source information. At each node you have a set of identifiers that are bound but not referenced. If the node is a reference, you remove that identifier from the set. If it is a binding, you add the bindings, traverse subexpressions, then do a set difference between your bindings and the return value from subexpression traversal -- that's your unused bindings. What do you think? A -- http://wingolog.org/