-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Oddities related to quoted imports #13878
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
Comments
For reference, the context for the change introducing |
We only emit import quoted if the quote is potentially capturing an import, which is effectively when we may have a dependency. Everything else gets resolved when the result of the quote is expanded instead. We will document it and I will double check if imported_quoted is required for /, but most likely yes, as the trace implies it may be used, not that it will. |
I did one more experiment. This time I compared events emitted by expanding a macro vs events emitted by the exact same code not quoted.
Grouped for readability and omitted not interesting bits Expanding
Directly calling the same code in
Notice no Additionally, I'd say that |
Exactly. The import is expanded on the module/function that does the quote, so where the quote is expanded, it can only be a remote call (or a local call if the function is locally overridden). 👍
Remember that Elixir AST is generic. |
Fixed in main.
We expand only imports and aliases inside
Per above, expected.
We store all arity-module pairs for a given name. In this case, both arities come from Kernel, but they could come from different functions. Thank you for the excellent questions and helping us document this more clearly. |
Thanks for the detailed answers @josevalim. Now I understand more on how macro hygiene works. |
@josevalim I revisited this and I'm convinced there is an issue with quoted import calls. Consider this simple example:
Yet when I expand this macro I don't get any trace events
Per your comment "so where the quote is expanded, it can only be a remote call" I'd expect to get I think the issue is somewhere in elixir/lib/elixir/src/elixir_dispatch.erl Line 204 in 18d367c
expand_require for remote_macro . For function {function, Receiver, Name} is returned and dispatch callback is executed without emitting anything.
|
Nice. I still have two questions:
|
|
The meaning of overridden was not clear. Do I get it right that this means the import is not resolved at quote time and resolved to a local on expand like in this example
|
Your example above is resolved locally. However, if |
Uh oh!
There was an error while loading. Please reload this page.
Elixir and Erlang/OTP versions
Erlang/OTP 26 [erts-14.2.5.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
Elixir 1.17.3 (compiled with Erlang/OTP 26)
Operating system
any
Current behavior
I noticed some strange behavior related to quoted imports. Given this compilation tracer
when I compile this code
The emitted traces are
:imported_quoted
&inspect/1
results in a trace event. No similar events for remote and local capturesNext, when I eval the macro, it outputs this AST
Kernel
added twice in metaimports: [{1, Kernel}, {2, Kernel}]
?Expected behavior
I'm not sure if emitting
{:imported_quoted, [line: 5, column: 15], Kernel, :/, [2]}
should happenAlternatively it's possible that events in quoted are not needed at all
:elixir_quote
so it may be correctThe text was updated successfully, but these errors were encountered: