-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Way to tell if a macro is in local or global scope #34168
Comments
I can understand why you'd like to do this; in specialized circumstances a macro wants to emit different code in different cases, (for example in #35833) The sticking point is that analysis of variable scope hasn't yet been done by the time macros are expanded — that's done later during lowering. Furthermore, if we did some analysis before macro expansion then that analysis might need to be redone based on whatever code the macro generates. And that might need to happen multiple times for nested macros. So in short, it's not trivial to implement this and seems to violate the "pipeline-like" layering of compiler analyses. Two very speculative alternatives to having a predicate available:
|
Being able to emit something like
In analogy to |
That seems like a promising and minimalistic minimal way to implement this, I like it! |
Also generally a duplicate feature request as #6733 |
There are local scopes which are not inside functions, like |
When writing macros, you often have to come up with very clever ways of writing code that works either in the global or local scope. It'd be nice if I could just query a variable analogous to
__module__
(maybe__isglobal__
?) to see if a macro is called from a local or global scope. The parser certainly know what code is in a local versus global scope so this shouldn't be too difficult.The text was updated successfully, but these errors were encountered: