Backport from paradise/macros

Applies improvements to the macro engine from paradise/macros
to provide robustness and uniformity to different entrances of macro
expansion + to prepare for the unavoidable typemacro merge!