I think what you want is a customised compiler, which is a use-case we want to support, but not with procedural macros. It seems you want two things which are outside the scope of procedural macros:
-
access to the whole program - macros are inherently local and context free. It is possible to imagine loosening this restriction, but IMO the costs (in complexity of the system) outweigh the benefits.
-
semantic information - i.e., the results of name resolution and type analysis. Macros are syntactic and happen before these phases of the compiler. We’ve thought about integrating name resolution and macro expansion to some extent, but doing all of name resolution would be complex. Likewise, I think it would be impossible to do type analysis at the same time as macro expansion.
So, on both counts it seems that procedural macros aren’t a good fit for what you want to do, and they probably won’t be in the future. However, we do support integration with the compiler at a deep level and this is probably what you want (i.e., to create a custom compiler). This tutorial explains how to do this - it is aimed at creating a tool, but creating a full compiler would use the same techniques. You get full (and easy) access to type and name info via the save-analysis API, see src/librustc_trans/save/mod.rs. This stuff is all work in progress and there are no concrete plans at the moment. But your use cases are exactly what these things should help with, so if it doesn’t fulfil your needs, then let me know and we’ll try to figure something out.